Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
@@ -9,21 +9,15 @@ import gradio as gr
|
|
9 |
|
10 |
@tool
|
11 |
def fetch_latest_research_papers(keywords: list, num_results: int = 5) -> list:
|
12 |
-
"""
|
13 |
-
Fetches the latest research papers from Google Scholar based on provided keywords.
|
14 |
-
|
15 |
Args:
|
16 |
-
keywords
|
17 |
-
num_results
|
18 |
-
|
19 |
-
Returns:
|
20 |
-
list: A list of dictionaries containing paper details.
|
21 |
"""
|
22 |
try:
|
23 |
print(f"DEBUG: Searching papers with keywords: {keywords}") # Debug input
|
24 |
-
query = " ".join(keywords)
|
25 |
search_results = scholarly.search_pubs(query)
|
26 |
-
|
27 |
papers = []
|
28 |
for _ in range(num_results * 2): # Fetch extra papers to ensure we get recent ones
|
29 |
paper = next(search_results, None)
|
@@ -59,8 +53,6 @@ def fetch_latest_research_papers(keywords: list, num_results: int = 5) -> list:
|
|
59 |
return [f"Error fetching research papers: {str(e)}"]
|
60 |
|
61 |
|
62 |
-
|
63 |
-
|
64 |
final_answer = FinalAnswerTool()
|
65 |
|
66 |
model = HfApiModel(
|
@@ -86,13 +78,17 @@ agent = CodeAgent(
|
|
86 |
)
|
87 |
|
88 |
def search_papers(user_input):
|
89 |
-
keywords = user_input.split(",") #
|
90 |
print(f"DEBUG: Received input keywords - {keywords}") # Debug user input
|
91 |
|
|
|
|
|
|
|
|
|
92 |
results = fetch_latest_research_papers(keywords, num_results=1)
|
93 |
print(f"DEBUG: Results received - {results}") # Debug function output
|
94 |
|
95 |
-
if isinstance(results, list) and results:
|
96 |
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])
|
97 |
|
98 |
print("DEBUG: No results found.")
|
@@ -109,8 +105,6 @@ with gr.Blocks() as demo:
|
|
109 |
search_button.click(search_papers, inputs=[keyword_input], outputs=[output_display])
|
110 |
|
111 |
|
112 |
-
|
113 |
print("DEBUG: Gradio UI is running. Waiting for user input...")
|
114 |
|
115 |
-
|
116 |
demo.launch()
|
|
|
9 |
|
10 |
@tool
|
11 |
def fetch_latest_research_papers(keywords: list, num_results: int = 5) -> 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 |
print(f"DEBUG: Searching papers with keywords: {keywords}") # Debug input
|
19 |
+
query = " ".join([kw.strip() for kw in keywords if kw.strip()]) # Ensure clean query
|
20 |
search_results = scholarly.search_pubs(query)
|
|
|
21 |
papers = []
|
22 |
for _ in range(num_results * 2): # Fetch extra papers to ensure we get recent ones
|
23 |
paper = next(search_results, None)
|
|
|
53 |
return [f"Error fetching research papers: {str(e)}"]
|
54 |
|
55 |
|
|
|
|
|
56 |
final_answer = FinalAnswerTool()
|
57 |
|
58 |
model = HfApiModel(
|
|
|
78 |
)
|
79 |
|
80 |
def search_papers(user_input):
|
81 |
+
keywords = [kw.strip() for kw in user_input.split(",") if kw.strip()] # Ensure valid keywords
|
82 |
print(f"DEBUG: Received input keywords - {keywords}") # Debug user input
|
83 |
|
84 |
+
if not keywords:
|
85 |
+
print("DEBUG: No valid keywords provided.")
|
86 |
+
return "Error: Please enter at least one valid keyword."
|
87 |
+
|
88 |
results = fetch_latest_research_papers(keywords, num_results=1)
|
89 |
print(f"DEBUG: Results received - {results}") # Debug function output
|
90 |
|
91 |
+
if isinstance(results, list) and results and isinstance(results[0], dict):
|
92 |
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])
|
93 |
|
94 |
print("DEBUG: No results found.")
|
|
|
105 |
search_button.click(search_papers, inputs=[keyword_input], outputs=[output_display])
|
106 |
|
107 |
|
|
|
108 |
print("DEBUG: Gradio UI is running. Waiting for user input...")
|
109 |
|
|
|
110 |
demo.launch()
|