Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -256,75 +256,38 @@ agent = CodeAgent(
|
|
| 256 |
|
| 257 |
|
| 258 |
|
| 259 |
-
#
|
| 260 |
-
# def search_papers(user_input):
|
| 261 |
-
# keywords = [kw.strip() for kw in user_input.split(",") if kw.strip()] # Ensure valid keywords
|
| 262 |
-
# print(f"DEBUG: Received input keywords - {keywords}") # Debug user input
|
| 263 |
-
|
| 264 |
-
# if not keywords:
|
| 265 |
-
# print("DEBUG: No valid keywords provided.")
|
| 266 |
-
# return "Error: Please enter at least one valid keyword."
|
| 267 |
-
|
| 268 |
-
# results = fetch_latest_arxiv_papers(keywords, num_results=3) # Fetch 3 results
|
| 269 |
-
# print(f"DEBUG: Results received - {results}") # Debug function output
|
| 270 |
-
|
| 271 |
-
# # Check if the API returned an error
|
| 272 |
-
# if isinstance(results, list) and len(results) > 0 and "error" in results[0]:
|
| 273 |
-
# return results[0]["error"] # Return the error message directly
|
| 274 |
-
|
| 275 |
-
# # Format results only if valid papers exist
|
| 276 |
-
# if isinstance(results, list) and results and isinstance(results[0], dict):
|
| 277 |
-
# formatted_results = "\n\n".join([
|
| 278 |
-
# f"---\n\n"
|
| 279 |
-
# f"📌 **Title:** {paper['title']}\n\n"
|
| 280 |
-
# f"👨🔬 **Authors:** {paper['authors']}\n\n"
|
| 281 |
-
# f"📅 **Year:** {paper['year']}\n\n"
|
| 282 |
-
# f"📖 **Abstract:** {paper['abstract'][:500]}... *(truncated for readability)*\n\n"
|
| 283 |
-
# f"[🔗 Read Full Paper]({paper['link']})\n\n"
|
| 284 |
-
# for paper in results
|
| 285 |
-
# ])
|
| 286 |
-
# return formatted_results
|
| 287 |
-
|
| 288 |
-
# print("DEBUG: No results found.")
|
| 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
|
| 327 |
-
# GradioUI(agent).launch()
|
| 328 |
|
| 329 |
|
| 330 |
# Create Gradio UI
|
|
|
|
| 256 |
|
| 257 |
|
| 258 |
|
| 259 |
+
#Search Papers
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 260 |
def search_papers(user_input):
|
| 261 |
+
keywords = [kw.strip() for kw in user_input.split(",") if kw.strip()] # Ensure valid keywords
|
| 262 |
+
print(f"DEBUG: Received input keywords - {keywords}") # Debug user input
|
| 263 |
+
|
| 264 |
if not keywords:
|
| 265 |
+
print("DEBUG: No valid keywords provided.")
|
| 266 |
return "Error: Please enter at least one valid keyword."
|
| 267 |
+
|
| 268 |
+
results = fetch_latest_arxiv_papers(keywords, num_results=3) # Fetch 3 results
|
| 269 |
+
print(f"DEBUG: Results received - {results}") # Debug function output
|
| 270 |
+
|
| 271 |
+
# Check if the API returned an error
|
| 272 |
+
if isinstance(results, list) and len(results) > 0 and "error" in results[0]:
|
| 273 |
+
return results[0]["error"] # Return the error message directly
|
| 274 |
+
|
| 275 |
+
# Format results only if valid papers exist
|
| 276 |
+
if isinstance(results, list) and results and isinstance(results[0], dict):
|
| 277 |
+
formatted_results = "\n\n".join([
|
| 278 |
+
f"---\n\n"
|
| 279 |
+
f"📌 **Title:** {paper['title']}\n\n"
|
| 280 |
+
f"👨🔬 **Authors:** {paper['authors']}\n\n"
|
| 281 |
+
f"📅 **Year:** {paper['year']}\n\n"
|
| 282 |
+
f"📖 **Abstract:** {paper['abstract'][:500]}... *(truncated for readability)*\n\n"
|
| 283 |
+
f"[🔗 Read Full Paper]({paper['link']})\n\n"
|
| 284 |
+
for paper in results
|
| 285 |
+
])
|
| 286 |
+
return formatted_results
|
| 287 |
+
|
| 288 |
+
print("DEBUG: No results found.")
|
| 289 |
+
return "No results found. Try different keywords."
|
| 290 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 291 |
|
| 292 |
|
| 293 |
# Create Gradio UI
|