pdx97 commited on
Commit
7233de1
·
verified ·
1 Parent(s): 0bb6d8b

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +15 -14
app.py CHANGED
@@ -2,24 +2,25 @@ import feedparser
2
  import urllib.parse
3
  import yaml
4
  import gradio as gr
 
5
  from smolagents import CodeAgent, HfApiModel, tool
6
 
7
  @tool
8
- def fetch_latest_arxiv_papers(keywords: list, num_results: int = 3) -> list:
9
  """
10
- Fetch the latest research papers from arXiv.
11
 
12
- Parameters:
13
- keywords (list of str): A list of search keywords. Each keyword is used to filter relevant papers.
14
  num_results (int): The maximum number of research papers to fetch. Default is 3.
15
 
16
  Returns:
17
- list of dict: A list of dictionaries, where each dictionary contains:
18
- - title (str): The title of the research paper.
19
- - authors (str): The authors of the paper.
20
- - year (str): The publication year.
21
- - abstract (str): A summary of the research paper.
22
- - link (str): A direct link to the paper on arXiv.
23
  """
24
  try:
25
  print(f"DEBUG: Searching arXiv papers with keywords: {keywords}") # Debug input
@@ -62,7 +63,7 @@ model = HfApiModel(
62
  with open("prompts.yaml", 'r') as stream:
63
  prompt_templates = yaml.safe_load(stream)
64
 
65
- # Create the AI Agent
66
  agent = CodeAgent(
67
  model=model,
68
  tools=[fetch_latest_arxiv_papers], # Properly registered tool
@@ -75,7 +76,7 @@ agent = CodeAgent(
75
  prompt_templates=prompt_templates
76
  )
77
 
78
- #Define Gradio Search Function
79
  def search_papers(user_input):
80
  keywords = [kw.strip() for kw in user_input.split(",") if kw.strip()] # Ensure valid keywords
81
  print(f"DEBUG: Received input keywords - {keywords}") # Debug user input
@@ -96,7 +97,7 @@ def search_papers(user_input):
96
  print("DEBUG: No results found.")
97
  return "No results found. Try different keywords."
98
 
99
-
100
  with gr.Blocks() as demo:
101
  gr.Markdown("# arXiv Research Paper Fetcher")
102
  keyword_input = gr.Textbox(label="Enter keywords (comma-separated)", placeholder="e.g., deep learning, reinforcement learning")
@@ -107,5 +108,5 @@ with gr.Blocks() as demo:
107
 
108
  print("DEBUG: Gradio UI is running. Waiting for user input...")
109
 
110
-
111
  demo.launch()
 
2
  import urllib.parse
3
  import yaml
4
  import gradio as gr
5
+ from typing import List, Dict
6
  from smolagents import CodeAgent, HfApiModel, tool
7
 
8
  @tool
9
+ def fetch_latest_arxiv_papers(keywords: List[str], num_results: int = 3) -> List[Dict[str, str]]:
10
  """
11
+ Fetches the latest research papers from arXiv.
12
 
13
+ Args:
14
+ keywords (List[str]): A list of search keywords to filter relevant papers.
15
  num_results (int): The maximum number of research papers to fetch. Default is 3.
16
 
17
  Returns:
18
+ List[Dict[str, str]]: A list of dictionaries where each dictionary contains:
19
+ - "title" (str): The title of the research paper.
20
+ - "authors" (str): The authors of the paper.
21
+ - "year" (str): The publication year.
22
+ - "abstract" (str): A summary of the research paper.
23
+ - "link" (str): A direct link to the paper on arXiv.
24
  """
25
  try:
26
  print(f"DEBUG: Searching arXiv papers with keywords: {keywords}") # Debug input
 
63
  with open("prompts.yaml", 'r') as stream:
64
  prompt_templates = yaml.safe_load(stream)
65
 
66
+ # Create the AI Agent
67
  agent = CodeAgent(
68
  model=model,
69
  tools=[fetch_latest_arxiv_papers], # Properly registered tool
 
76
  prompt_templates=prompt_templates
77
  )
78
 
79
+ #Define Gradio Search Function
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
 
97
  print("DEBUG: No results found.")
98
  return "No results found. Try different keywords."
99
 
100
+ # ✅ Create Gradio UI
101
  with gr.Blocks() as demo:
102
  gr.Markdown("# arXiv Research Paper Fetcher")
103
  keyword_input = gr.Textbox(label="Enter keywords (comma-separated)", placeholder="e.g., deep learning, reinforcement learning")
 
108
 
109
  print("DEBUG: Gradio UI is running. Waiting for user input...")
110
 
111
+ # ✅ Launch Gradio App
112
  demo.launch()