Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
|
@@ -289,36 +289,38 @@ agent = CodeAgent(
|
|
| 289 |
# return "No results found. Try different keywords."
|
| 290 |
|
| 291 |
def search_papers(user_input):
|
| 292 |
-
keywords = [kw.strip() for kw in user_input.split(",") if kw.strip()]
|
| 293 |
-
print(f"DEBUG: Received input keywords - {keywords}")
|
| 294 |
-
|
| 295 |
if not keywords:
|
| 296 |
-
print("DEBUG: No valid keywords provided.")
|
| 297 |
return "Error: Please enter at least one valid keyword."
|
| 298 |
-
|
| 299 |
-
#
|
| 300 |
-
|
| 301 |
-
|
| 302 |
-
|
| 303 |
-
|
| 304 |
-
|
| 305 |
-
|
| 306 |
-
|
| 307 |
-
|
| 308 |
-
|
| 309 |
-
|
| 310 |
-
|
| 311 |
-
|
| 312 |
-
|
| 313 |
-
|
| 314 |
-
|
| 315 |
-
|
| 316 |
-
|
| 317 |
-
|
| 318 |
-
|
| 319 |
-
|
| 320 |
-
|
| 321 |
-
|
|
|
|
|
|
|
|
|
|
| 322 |
|
| 323 |
|
| 324 |
# # Launch Gradio UI with CodeAgent
|
|
|
|
| 289 |
# return "No results found. Try different keywords."
|
| 290 |
|
| 291 |
def search_papers(user_input):
|
| 292 |
+
keywords = [kw.strip() for kw in user_input.split(",") if kw.strip()]
|
| 293 |
+
print(f"DEBUG: Received input keywords - {keywords}")
|
| 294 |
+
|
| 295 |
if not keywords:
|
|
|
|
| 296 |
return "Error: Please enter at least one valid keyword."
|
| 297 |
+
|
| 298 |
+
# Check if 'final_answer' exists in prompt_templates
|
| 299 |
+
if "final_answer" not in agent.prompt_templates:
|
| 300 |
+
agent.prompt_templates["final_answer"] = {
|
| 301 |
+
"pre_messages": "Here is the final answer based on the research:",
|
| 302 |
+
"post_messages": "End of response."
|
| 303 |
+
}
|
| 304 |
+
|
| 305 |
+
try:
|
| 306 |
+
response = agent.run(user_input) # Now it actually uses CodeAgent
|
| 307 |
+
print(f"DEBUG: Agent Response - {response}")
|
| 308 |
+
|
| 309 |
+
if isinstance(response, list) and response and isinstance(response[0], dict):
|
| 310 |
+
formatted_results = "\n\n".join([
|
| 311 |
+
f"📌 **Title:** {paper['title']}\n\n"
|
| 312 |
+
f"👨🔬 **Authors:** {paper['authors']}\n\n"
|
| 313 |
+
f"📅 **Year:** {paper['year']}\n\n"
|
| 314 |
+
f"📖 **Abstract:** {paper['abstract'][:500]}... *(truncated for readability)*\n\n"
|
| 315 |
+
f"[🔗 Read Full Paper]({paper['link']})\n\n"
|
| 316 |
+
for paper in response
|
| 317 |
+
])
|
| 318 |
+
return formatted_results
|
| 319 |
+
|
| 320 |
+
return "No results found. Try different keywords."
|
| 321 |
+
except Exception as e:
|
| 322 |
+
print(f"ERROR: {e}")
|
| 323 |
+
return f"An error occurred: {str(e)}"
|
| 324 |
|
| 325 |
|
| 326 |
# # Launch Gradio UI with CodeAgent
|