mayzinoo commited on
Commit
54cc619
·
verified ·
1 Parent(s): be905b7

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +38 -4
app.py CHANGED
@@ -86,12 +86,46 @@ def retrieve_and_generate_app(query, top_k=3):
86
  sol_id = document_ids[i]
87
  # Find the full content of the retrieved SOL
88
  # This relies on the 'documents' list being correctly loaded and matching by ID
89
- retrieved_content = next((doc["content"] for doc in documents if doc["id"] == sol_id), "Content not found.")
90
- retrieved_docs.append({"id": sol_id, "content": retrieved_content})
 
91
 
92
- context = "\n\n".join([f"SOL {doc['id']}: {doc['content']}" for doc in retrieved_docs])
 
93
 
94
- prompt = f""""""
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
95
 
96
  # Create Gradio interface
97
  demo = gr.Interface(
 
86
  sol_id = document_ids[i]
87
  # Find the full content of the retrieved SOL
88
  # This relies on the 'documents' list being correctly loaded and matching by ID
89
+ # --- CHANGE 1: Use 'text' key instead of 'content' here ---
90
+ retrieved_content = next((doc["text"] for doc in documents if doc["id"] == sol_id), "Content not found.")
91
+ retrieved_docs.append({"id": sol_id, "content": retrieved_content}) # Keep 'content' here for consistency in retrieved_docs structure if you like
92
 
93
+ # --- CHANGE 2: Use 'text' key here for building the context ---
94
+ context = "\n\n".join([f"SOL {doc['id']}: {doc['text']}" for doc in retrieved_docs])
95
 
96
+ # --- CHANGE 3: Complete the prompt string ---
97
+ prompt = f"""
98
+ Given the following information about Virginia Standards of Learning (SOLs):
99
+
100
+ {context}
101
+
102
+ Based on this information, answer the following question:
103
+ {query}
104
+
105
+ If the question is about a specific SOL number, provide a direct explanation for that SOL.
106
+ If asked for lesson plans, worksheets, or proofs, explain what the document generally entails and whether it provides such materials.
107
+ Be concise and to the point.
108
+ """
109
+ # --- Start of the print statements for debugging (keep these for now!) ---
110
+ print(f"\n--- PROMPT SENT TO LLM ---\n{prompt}\n--------------------------\n")
111
+
112
+ response = llm_pipeline(prompt, max_new_tokens=500, num_return_sequences=1, do_sample=True, temperature=0.7)
113
+
114
+ generated_text = response[0]['generated_text']
115
+
116
+ print(f"\n--- RAW GENERATED TEXT ---\n{generated_text}\n--------------------------\n")
117
+
118
+ answer_start_marker = f"Based on this information, answer the following question:\n{query}"
119
+ if answer_start_marker in generated_text:
120
+ answer = generated_text.split(answer_start_marker, 1)[1].strip()
121
+ answer = re.sub(r'If the question is about a specific SOL number,.*?$', '', answer, flags=re.DOTALL).strip()
122
+ else:
123
+ answer = generated_text
124
+
125
+ print(f"\n--- FINAL ANSWER ---\n{answer}\n--------------------\n")
126
+ # --- End of the print statements for debugging ---
127
+
128
+ return answer
129
 
130
  # Create Gradio interface
131
  demo = gr.Interface(