pdx97 commited on
Commit
58b3bc8
·
verified ·
1 Parent(s): 41b209f

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +30 -28
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()] # Ensure valid keywords
293
- print(f"DEBUG: Received input keywords - {keywords}") # Debug user input
294
-
295
  if not keywords:
296
- print("DEBUG: No valid keywords provided.")
297
  return "Error: Please enter at least one valid keyword."
298
-
299
- # Use CodeAgent to process the request
300
- response = agent.run(user_input) # Now it actually uses CodeAgent
301
- print(f"DEBUG: Agent Response - {response}") # Debug response from the agent
302
-
303
- # Check if response is valid
304
- if isinstance(response, list) and len(response) > 0 and "error" in response[0]:
305
- return response[0]["error"] # Return the error message directly
306
-
307
- # Format results only if valid papers exist
308
- if isinstance(response, list) and response and isinstance(response[0], dict):
309
- formatted_results = "\n\n".join([
310
- f"---\n\n"
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
- print("DEBUG: No results found.")
321
- return "No results found. Try different keywords."
 
 
 
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