pdx97 commited on
Commit
041eef2
·
verified ·
1 Parent(s): dea9d55

Updated new app.py

Browse files
Files changed (1) hide show
  1. app.py +1 -57
app.py CHANGED
@@ -1,63 +1,7 @@
1
- from smolagents import CodeAgent, HfApiModel, load_tool, tool
2
- import datetime
3
- import requests
4
- import pytz
5
- import yaml
6
- from tools.final_answer import FinalAnswerTool
7
- from scholarly import scholarly
8
  import gradio as gr
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
- 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'),
27
- "year": paper['bib'].get('pub_year', 'Unknown Year'),
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(
38
- max_tokens=2096,
39
- temperature=0.5,
40
- model_id='Qwen/Qwen2.5-Coder-32B-Instruct',
41
- custom_role_conversions=None,
42
- )
43
-
44
- with open("prompts.yaml", 'r') as stream:
45
- prompt_templates = yaml.safe_load(stream)
46
-
47
- agent = CodeAgent(
48
- model=model,
49
- tools=[final_answer, fetch_latest_research_papers],
50
- max_steps=6,
51
- verbosity_level=1,
52
- grammar=None,
53
- planning_interval=None,
54
- name="ScholarAgent",
55
- description="An AI agent that fetches the latest research papers from Google Scholar based on user-defined keywords and filters.",
56
- prompt_templates=prompt_templates
57
- )
58
-
59
  def search_papers(user_input):
60
- keywords = user_input.split("math reasoning,deep learning") # Split input by commas for multiple keywords
61
  results = fetch_latest_research_papers(keywords, num_results=5)
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
 
 
 
 
 
 
 
 
 
1
  import gradio as gr
2
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
3
  def search_papers(user_input):
4
+ keywords = user_input.split(",") # Split input by commas for multiple keywords
5
  results = fetch_latest_research_papers(keywords, num_results=5)
6
  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])
7