Spaces:
Running
Running
Update app.py
Browse filessummary of a paper
app.py
CHANGED
@@ -9,14 +9,35 @@ from Gradio_UI import GradioUI
|
|
9 |
|
10 |
# Below is an example of a tool that does nothing. Amaze us with your creativity !
|
11 |
@tool
|
12 |
-
def
|
13 |
-
|
14 |
-
"""A tool that does nothing yet
|
15 |
Args:
|
16 |
-
|
17 |
-
|
18 |
"""
|
19 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
20 |
|
21 |
@tool
|
22 |
def get_current_time_in_timezone(timezone: str) -> str:
|
@@ -51,7 +72,7 @@ with open("prompts.yaml", 'r') as stream:
|
|
51 |
|
52 |
agent = CodeAgent(
|
53 |
model=model,
|
54 |
-
tools=[
|
55 |
max_steps=6,
|
56 |
verbosity_level=1,
|
57 |
grammar=None,
|
|
|
9 |
|
10 |
# Below is an example of a tool that does nothing. Amaze us with your creativity !
|
11 |
@tool
|
12 |
+
def summary_of_paper(query: str, max_results: int = 1) -> str:
|
13 |
+
"""A tool that searches for a paper on arXiv and summarizes it using a language model.
|
|
|
14 |
Args:
|
15 |
+
query: The search query for the paper.
|
16 |
+
max_results: The maximum number of search results to return.
|
17 |
"""
|
18 |
+
try:
|
19 |
+
# Search for the paper on arXiv
|
20 |
+
search_url = f"http://export.arxiv.org/api/query?search_query={query}&max_results={max_results}"
|
21 |
+
response = requests.get(search_url)
|
22 |
+
if response.status_code != 200:
|
23 |
+
return f"Error fetching paper from arXiv: {response.status_code}"
|
24 |
+
|
25 |
+
# Parse the response
|
26 |
+
papers = response.text
|
27 |
+
# For simplicity, let's assume we extract the first paper's summary
|
28 |
+
# In a real implementation, you would parse the XML response properly
|
29 |
+
start_idx = papers.find('<summary>') + len('<summary>')
|
30 |
+
end_idx = papers.find('</summary>', start_idx)
|
31 |
+
paper_summary = papers[start_idx:end_idx].strip()
|
32 |
+
|
33 |
+
# Summarize the paper using a language model
|
34 |
+
summary_prompt = f"Summarize the following paper: {paper_summary}"
|
35 |
+
summary_response = model.generate(summary_prompt)
|
36 |
+
|
37 |
+
return f"the summary of the paper is: {summary_response}"
|
38 |
+
except Exception as e:
|
39 |
+
return f"Error summarizing paper: {str(e)}"
|
40 |
+
|
41 |
|
42 |
@tool
|
43 |
def get_current_time_in_timezone(timezone: str) -> str:
|
|
|
72 |
|
73 |
agent = CodeAgent(
|
74 |
model=model,
|
75 |
+
tools=[summary_of_paper, final_answer], ## add your tools here (don't remove final answer)
|
76 |
max_steps=6,
|
77 |
verbosity_level=1,
|
78 |
grammar=None,
|