Spaces:
Sleeping
Sleeping
Update Gradio_UI.py
Browse files- Gradio_UI.py +12 -11
Gradio_UI.py
CHANGED
|
@@ -17,41 +17,42 @@ class GradioUI:
|
|
| 17 |
try:
|
| 18 |
print("Detected PDF upload and query. Calling document_qna_tool...")
|
| 19 |
|
| 20 |
-
# Dynamically find the tool by name
|
| 21 |
-
tool_name = "document_qna_tool"
|
| 22 |
tool_func = None
|
| 23 |
for t in self.agent.tools:
|
| 24 |
-
|
|
|
|
|
|
|
| 25 |
tool_func = t
|
| 26 |
break
|
| 27 |
|
| 28 |
if tool_func is None:
|
| 29 |
-
return f"Error: Could not find tool named '
|
| 30 |
|
| 31 |
# Call the tool with the uploaded PDF path and the user's question
|
| 32 |
response = tool_func(pdf_file.name, query)
|
| 33 |
-
print("Document Q&A tool finished.")
|
| 34 |
return response
|
| 35 |
|
| 36 |
except Exception as e:
|
| 37 |
-
print(f"Error during Document Q&A tool execution: {e}")
|
| 38 |
return f"An error occurred during Document Q&A: {str(e)}"
|
| 39 |
|
| 40 |
elif query and query.strip():
|
| 41 |
print(f"No PDF file or query is for general task. Processing with agent.run(): {query}")
|
| 42 |
try:
|
| 43 |
response = self.agent.run(query)
|
| 44 |
-
print("
|
| 45 |
return response
|
| 46 |
except Exception as e:
|
| 47 |
-
print(f"Error during agent.run: {e}")
|
| 48 |
return f"An error occurred while processing your request: {str(e)}"
|
| 49 |
|
| 50 |
elif pdf_file is not None:
|
| 51 |
-
return "Please enter a question in the textbox to ask about the uploaded PDF."
|
| 52 |
|
| 53 |
else:
|
| 54 |
-
return "Please enter a request or upload a document for analysis."
|
| 55 |
|
| 56 |
def launch(self):
|
| 57 |
"""
|
|
@@ -93,4 +94,4 @@ class GradioUI:
|
|
| 93 |
outputs=agent_output
|
| 94 |
)
|
| 95 |
|
| 96 |
-
demo.launch(share=False, inline=False)
|
|
|
|
| 17 |
try:
|
| 18 |
print("Detected PDF upload and query. Calling document_qna_tool...")
|
| 19 |
|
| 20 |
+
# Dynamically find the tool function by actual function name
|
|
|
|
| 21 |
tool_func = None
|
| 22 |
for t in self.agent.tools:
|
| 23 |
+
# Some tools may not have the 'name' attribute; fall back to function __name__
|
| 24 |
+
tool_name = getattr(t, "name", None) or getattr(t, "__name__", "")
|
| 25 |
+
if tool_name == "document_qna_tool":
|
| 26 |
tool_func = t
|
| 27 |
break
|
| 28 |
|
| 29 |
if tool_func is None:
|
| 30 |
+
return f"❌ Error: Could not find tool named 'document_qna_tool'. Please check your app.py tool registration."
|
| 31 |
|
| 32 |
# Call the tool with the uploaded PDF path and the user's question
|
| 33 |
response = tool_func(pdf_file.name, query)
|
| 34 |
+
print("✅ Document Q&A tool finished.")
|
| 35 |
return response
|
| 36 |
|
| 37 |
except Exception as e:
|
| 38 |
+
print(f"❌ Error during Document Q&A tool execution: {e}")
|
| 39 |
return f"An error occurred during Document Q&A: {str(e)}"
|
| 40 |
|
| 41 |
elif query and query.strip():
|
| 42 |
print(f"No PDF file or query is for general task. Processing with agent.run(): {query}")
|
| 43 |
try:
|
| 44 |
response = self.agent.run(query)
|
| 45 |
+
print("✅ agent.run finished for general query.")
|
| 46 |
return response
|
| 47 |
except Exception as e:
|
| 48 |
+
print(f"❌ Error during agent.run: {e}")
|
| 49 |
return f"An error occurred while processing your request: {str(e)}"
|
| 50 |
|
| 51 |
elif pdf_file is not None:
|
| 52 |
+
return "⚠️ Please enter a question in the textbox to ask about the uploaded PDF."
|
| 53 |
|
| 54 |
else:
|
| 55 |
+
return "⚠️ Please enter a request or upload a document for analysis."
|
| 56 |
|
| 57 |
def launch(self):
|
| 58 |
"""
|
|
|
|
| 94 |
outputs=agent_output
|
| 95 |
)
|
| 96 |
|
| 97 |
+
demo.launch(share=False, inline=False)
|