Spaces:
Sleeping
Sleeping
Update app.py
Browse files84 unmodified lines85868788899091929394959697989910010110210310410510610710810911011111210 unmodified lines12312412512612712812913084 unmodified linesfor i in I[0]:sol_id = document_ids[i]# Find the full content of the retrieved SOL# This relies on the 'documents' list being correctly loaded and matching by ID# --- CHANGE 1: Use 'text' key instead of 'content' here ---retrieved_content = next((doc["text"] for doc in documents if doc["id"] == sol_id), "Content not found.")retrieved_docs.append({"id": sol_id, "content": retrieved_content}) # Keep 'content' here for consistency in retrieved_docs structure if you like# --- CHANGE 2: Use 'text' key here for building the context ---context = "\n\n".join([f"SOL {doc['id']}: {doc['text']}" for doc in retrieved_docs])# --- CHANGE 3: Complete the prompt string ---prompt = f"""Given the following information about Virginia Standards of Learning (SOLs):{context}Based on this information, answer the following question:{query}If the question is about a specific SOL number, provide a direct explanation for that SOL.If asked for lesson plans, worksheets, or proofs, explain what the document generally entails and whether it provides such materials.Be concise and to the point."""# --- Start of the print statements for debugging (keep these for now!) ---print(f"\n--- PROMPT SENT TO LLM ---\n{prompt}\n--------------------------\n")response = llm_pipeline(prompt, max_new_tokens=500, num_return_sequences=1, do_sample=True, temperature=0.7)10 unmodified linesanswer = generated_textprint(f"\n--- FINAL ANSWER ---\n{answer}\n--------------------\n")# --- End of the print statements for debugging ---return answer# Create Gradio interface84 unmodified lines85868788899091929394959697989910010110210310410510610710810911010 unmodified lines12112212312412512684 unmodified linesfor i in I[0]:sol_id = document_ids[i]# Find the full content of the retrieved SOL# --- CHANGE THIS LINE ---# Original (incorrect): retrieved_content = next((doc["text"] for doc in documents if doc["id"] == sol_id), "Content not found.")retrieved_content = next((doc["content"] for doc in documents if doc["id"] == sol_id), "Content not found.")retrieved_docs.append({"id": sol_id, "content": retrieved_content})# 3. Context Construction# --- CHANGE THIS LINE ---# Original (incorrect): context = "\n\n".join([f"SOL {doc['id']}: {doc['text']}" for doc in retrieved_docs])context = "\n\n".join([f"SOL {doc['id']}: {doc['content']}" for doc in retrieved_docs])# 4. LLM Generationprompt = f"""Given the following information about Virginia Standards of Learning (SOLs):{context}Based on this information, answer the following question:{query}If the question is about a specific SOL number, provide a direct explanation for that SOL.If asked for lesson plans, worksheets, or proofs, explain what the document generally entails and whether it provides such materials.Be concise and to the point."""print(f"\n--- PROMPT SENT TO LLM ---\n{prompt}\n--------------------------\n")response = llm_pipeline(prompt, max_new_tokens=500, num_return_sequences=1, do_sample=True, temperature=0.7)10 unmodified linesanswer = generated_textprint(f"\n--- FINAL ANSWER ---\n{answer}\n--------------------\n")return answer# Create Gradio interface
app.py+9-13