Spaces:
Sleeping
Sleeping
Upload app.py
Browse files
app.py
CHANGED
|
@@ -242,11 +242,11 @@ def initialize_system():
|
|
| 242 |
def ask_question(question: str, assistant: CurriculumAssistant):
|
| 243 |
"""Ask a question and get answer with relevant pages"""
|
| 244 |
if not assistant or not assistant.qa_chain:
|
| 245 |
-
return "Please initialize the system first."
|
| 246 |
|
| 247 |
try:
|
| 248 |
-
# Get answer from QA chain
|
| 249 |
-
answer = assistant.qa_chain.
|
| 250 |
|
| 251 |
# Find relevant pages
|
| 252 |
relevant_pages = assistant.find_relevant_pages(question)
|
|
@@ -262,13 +262,13 @@ def ask_question(question: str, assistant: CurriculumAssistant):
|
|
| 262 |
page_info = "No specific pages found for this question."
|
| 263 |
|
| 264 |
# Format the complete response
|
| 265 |
-
full_response = f"## Answer\n\n{answer}\n\n---\n\n{page_info}"
|
| 266 |
|
| 267 |
-
return full_response
|
| 268 |
|
| 269 |
except Exception as e:
|
| 270 |
error_msg = f"Error processing question: {str(e)}"
|
| 271 |
-
return error_msg
|
| 272 |
|
| 273 |
# Initialize the system
|
| 274 |
status, assistant, curriculum_docs = initialize_system()
|
|
@@ -332,4 +332,4 @@ with gr.Blocks(title="Inclusive World Curriculum Assistant", theme=gr.themes.Sof
|
|
| 332 |
|
| 333 |
# Launch the app
|
| 334 |
if __name__ == "__main__":
|
| 335 |
-
demo.launch(
|
|
|
|
| 242 |
def ask_question(question: str, assistant: CurriculumAssistant):
|
| 243 |
"""Ask a question and get answer with relevant pages"""
|
| 244 |
if not assistant or not assistant.qa_chain:
|
| 245 |
+
return "Please initialize the system first."
|
| 246 |
|
| 247 |
try:
|
| 248 |
+
# Get answer from QA chain using invoke instead of run
|
| 249 |
+
answer = assistant.qa_chain.invoke({"query": question})
|
| 250 |
|
| 251 |
# Find relevant pages
|
| 252 |
relevant_pages = assistant.find_relevant_pages(question)
|
|
|
|
| 262 |
page_info = "No specific pages found for this question."
|
| 263 |
|
| 264 |
# Format the complete response
|
| 265 |
+
full_response = f"## Answer\n\n{answer['result']}\n\n---\n\n{page_info}"
|
| 266 |
|
| 267 |
+
return full_response
|
| 268 |
|
| 269 |
except Exception as e:
|
| 270 |
error_msg = f"Error processing question: {str(e)}"
|
| 271 |
+
return error_msg
|
| 272 |
|
| 273 |
# Initialize the system
|
| 274 |
status, assistant, curriculum_docs = initialize_system()
|
|
|
|
| 332 |
|
| 333 |
# Launch the app
|
| 334 |
if __name__ == "__main__":
|
| 335 |
+
demo.launch()
|