Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
@@ -1,16 +1,17 @@
|
|
1 |
-
from smolagents import CodeAgent, HfApiModel, load_tool, tool
|
2 |
-
import yaml
|
3 |
import feedparser
|
|
|
|
|
4 |
import gradio as gr
|
|
|
5 |
|
6 |
-
import urllib.parse # Import URL encoder
|
7 |
|
8 |
-
|
|
|
9 |
"""Fetches the latest research papers from arXiv based on provided keywords."""
|
10 |
try:
|
11 |
print(f"DEBUG: Searching arXiv papers with keywords: {keywords}") # Debug input
|
12 |
|
13 |
-
# Properly format query with +AND+ for multiple keywords
|
14 |
query = "+AND+".join([f"all:{kw}" for kw in keywords])
|
15 |
query_encoded = urllib.parse.quote(query) # Encode spaces and special characters
|
16 |
|
@@ -36,8 +37,6 @@ def fetch_latest_arxiv_papers(keywords: list, num_results: int = 1) -> list:
|
|
36 |
print(f"ERROR: {str(e)}") # Debug errors
|
37 |
return [f"Error fetching research papers: {str(e)}"]
|
38 |
|
39 |
-
|
40 |
-
|
41 |
model = HfApiModel(
|
42 |
max_tokens=2096,
|
43 |
temperature=0.5,
|
@@ -45,12 +44,14 @@ model = HfApiModel(
|
|
45 |
custom_role_conversions=None,
|
46 |
)
|
47 |
|
|
|
48 |
with open("prompts.yaml", 'r') as stream:
|
49 |
prompt_templates = yaml.safe_load(stream)
|
50 |
|
|
|
51 |
agent = CodeAgent(
|
52 |
model=model,
|
53 |
-
tools=[fetch_latest_arxiv_papers],
|
54 |
max_steps=6,
|
55 |
verbosity_level=1,
|
56 |
grammar=None,
|
@@ -60,6 +61,7 @@ agent = CodeAgent(
|
|
60 |
prompt_templates=prompt_templates
|
61 |
)
|
62 |
|
|
|
63 |
def search_papers(user_input):
|
64 |
keywords = [kw.strip() for kw in user_input.split(",") if kw.strip()] # Ensure valid keywords
|
65 |
print(f"DEBUG: Received input keywords - {keywords}") # Debug user input
|
@@ -80,8 +82,7 @@ def search_papers(user_input):
|
|
80 |
print("DEBUG: No results found.")
|
81 |
return "No results found. Try different keywords."
|
82 |
|
83 |
-
|
84 |
-
# Create a simple Gradio interface
|
85 |
with gr.Blocks() as demo:
|
86 |
gr.Markdown("# arXiv Research Paper Fetcher")
|
87 |
keyword_input = gr.Textbox(label="Enter keywords (comma-separated)", placeholder="e.g., deep learning, reinforcement learning")
|
@@ -92,4 +93,5 @@ with gr.Blocks() as demo:
|
|
92 |
|
93 |
print("DEBUG: Gradio UI is running. Waiting for user input...")
|
94 |
|
|
|
95 |
demo.launch()
|
|
|
|
|
|
|
1 |
import feedparser
|
2 |
+
import urllib.parse
|
3 |
+
import yaml
|
4 |
import gradio as gr
|
5 |
+
from smolagents import CodeAgent, HfApiModel, tool
|
6 |
|
|
|
7 |
|
8 |
+
@tool
|
9 |
+
def fetch_latest_arxiv_papers(keywords: list, num_results: int = 3) -> list:
|
10 |
"""Fetches the latest research papers from arXiv based on provided keywords."""
|
11 |
try:
|
12 |
print(f"DEBUG: Searching arXiv papers with keywords: {keywords}") # Debug input
|
13 |
|
14 |
+
# ✅ Properly format query with +AND+ for multiple keywords
|
15 |
query = "+AND+".join([f"all:{kw}" for kw in keywords])
|
16 |
query_encoded = urllib.parse.quote(query) # Encode spaces and special characters
|
17 |
|
|
|
37 |
print(f"ERROR: {str(e)}") # Debug errors
|
38 |
return [f"Error fetching research papers: {str(e)}"]
|
39 |
|
|
|
|
|
40 |
model = HfApiModel(
|
41 |
max_tokens=2096,
|
42 |
temperature=0.5,
|
|
|
44 |
custom_role_conversions=None,
|
45 |
)
|
46 |
|
47 |
+
# Load prompt templates
|
48 |
with open("prompts.yaml", 'r') as stream:
|
49 |
prompt_templates = yaml.safe_load(stream)
|
50 |
|
51 |
+
# Create the AI Agent
|
52 |
agent = CodeAgent(
|
53 |
model=model,
|
54 |
+
tools=[fetch_latest_arxiv_papers], # Properly registered tool
|
55 |
max_steps=6,
|
56 |
verbosity_level=1,
|
57 |
grammar=None,
|
|
|
61 |
prompt_templates=prompt_templates
|
62 |
)
|
63 |
|
64 |
+
# Define Gradio Search Function
|
65 |
def search_papers(user_input):
|
66 |
keywords = [kw.strip() for kw in user_input.split(",") if kw.strip()] # Ensure valid keywords
|
67 |
print(f"DEBUG: Received input keywords - {keywords}") # Debug user input
|
|
|
82 |
print("DEBUG: No results found.")
|
83 |
return "No results found. Try different keywords."
|
84 |
|
85 |
+
# Create Gradio UI
|
|
|
86 |
with gr.Blocks() as demo:
|
87 |
gr.Markdown("# arXiv Research Paper Fetcher")
|
88 |
keyword_input = gr.Textbox(label="Enter keywords (comma-separated)", placeholder="e.g., deep learning, reinforcement learning")
|
|
|
93 |
|
94 |
print("DEBUG: Gradio UI is running. Waiting for user input...")
|
95 |
|
96 |
+
# Launch Gradio App
|
97 |
demo.launch()
|