pdx97 commited on
Commit
bb8d29a
·
verified ·
1 Parent(s): 82728a0

Updated app.py added debugging

Browse files
Files changed (1) hide show
  1. app.py +23 -6
app.py CHANGED
@@ -9,18 +9,17 @@ import gradio as gr
9
 
10
  @tool
11
  def fetch_latest_research_papers(keywords: list, num_results: int = 1) -> list:
12
- """Fetches the latest research papers from Google Scholar based on provided keywords.
13
- Args:
14
- keywords: A list of keywords to search for relevant papers.
15
- num_results: The number of papers to fetch (default is 5).
16
- """
17
  try:
 
18
  query = " ".join(keywords)
19
  search_results = scholarly.search_pubs(query)
 
20
  papers = []
21
  for i in range(num_results):
22
  paper = next(search_results, None)
23
  if paper:
 
24
  papers.append({
25
  "title": paper['bib'].get('title', 'No Title'),
26
  "authors": paper['bib'].get('author', 'Unknown Authors'),
@@ -28,10 +27,14 @@ def fetch_latest_research_papers(keywords: list, num_results: int = 1) -> list:
28
  "abstract": paper['bib'].get('abstract', 'No Abstract Available'),
29
  "link": paper.get('pub_url', 'No Link Available')
30
  })
 
 
31
  return papers
32
  except Exception as e:
 
33
  return [f"Error fetching research papers: {str(e)}"]
34
 
 
35
  final_answer = FinalAnswerTool()
36
 
37
  model = HfApiModel(
@@ -58,8 +61,17 @@ agent = CodeAgent(
58
 
59
  def search_papers(user_input):
60
  keywords = user_input.split(",") # Split input by commas for multiple keywords
 
 
61
  results = fetch_latest_research_papers(keywords, num_results=1)
62
- return "\n\n".join([f"**Title:** {paper['title']}\n**Authors:** {paper['authors']}\n**Year:** {paper['year']}\n**Abstract:** {paper['abstract']}\n[Read More]({paper['link']})" for paper in results])
 
 
 
 
 
 
 
63
 
64
  # Create a simple Gradio interface
65
  with gr.Blocks() as demo:
@@ -70,4 +82,9 @@ with gr.Blocks() as demo:
70
 
71
  search_button.click(search_papers, inputs=[keyword_input], outputs=[output_display])
72
 
 
 
 
 
 
73
  demo.launch()
 
9
 
10
  @tool
11
  def fetch_latest_research_papers(keywords: list, num_results: int = 1) -> list:
12
+ """Fetches the latest research papers from Google Scholar based on provided keywords."""
 
 
 
 
13
  try:
14
+ print(f"DEBUG: Searching papers with keywords: {keywords}") # Debug input
15
  query = " ".join(keywords)
16
  search_results = scholarly.search_pubs(query)
17
+
18
  papers = []
19
  for i in range(num_results):
20
  paper = next(search_results, None)
21
  if paper:
22
+ print(f"DEBUG: Found paper - {paper['bib'].get('title', 'No Title')}") # Debug result
23
  papers.append({
24
  "title": paper['bib'].get('title', 'No Title'),
25
  "authors": paper['bib'].get('author', 'Unknown Authors'),
 
27
  "abstract": paper['bib'].get('abstract', 'No Abstract Available'),
28
  "link": paper.get('pub_url', 'No Link Available')
29
  })
30
+ if not papers:
31
+ print("DEBUG: No papers found.")
32
  return papers
33
  except Exception as e:
34
+ print(f"ERROR: {str(e)}") # Debug errors
35
  return [f"Error fetching research papers: {str(e)}"]
36
 
37
+
38
  final_answer = FinalAnswerTool()
39
 
40
  model = HfApiModel(
 
61
 
62
  def search_papers(user_input):
63
  keywords = user_input.split(",") # Split input by commas for multiple keywords
64
+ print(f"DEBUG: Received input keywords - {keywords}") # Debug user input
65
+
66
  results = fetch_latest_research_papers(keywords, num_results=1)
67
+ print(f"DEBUG: Results received - {results}") # Debug function output
68
+
69
+ if isinstance(results, list) and results:
70
+ return "\n\n".join([f"**Title:** {paper['title']}\n**Authors:** {paper['authors']}\n**Year:** {paper['year']}\n**Abstract:** {paper['abstract']}\n[Read More]({paper['link']})" for paper in results])
71
+
72
+ print("DEBUG: No results found.")
73
+ return "No results found. Try different keywords."
74
+
75
 
76
  # Create a simple Gradio interface
77
  with gr.Blocks() as demo:
 
82
 
83
  search_button.click(search_papers, inputs=[keyword_input], outputs=[output_display])
84
 
85
+
86
+
87
+ print("DEBUG: Gradio UI is running. Waiting for user input...")
88
+
89
+
90
  demo.launch()