Spaces:
Build error
Build error
Update app.py
Browse files
app.py
CHANGED
|
@@ -7,6 +7,39 @@ from tools.final_answer import FinalAnswerTool
|
|
| 7 |
|
| 8 |
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 my_custom_tool(arg1:str, arg2:int)-> str: #it's import to specify the return type
|
|
@@ -55,7 +88,7 @@ with open("prompts.yaml", 'r') as stream:
|
|
| 55 |
|
| 56 |
agent = CodeAgent(
|
| 57 |
model=model,
|
| 58 |
-
tools=[final_answer], ## add your tools here (don't remove final answer)
|
| 59 |
max_steps=6,
|
| 60 |
verbosity_level=1,
|
| 61 |
grammar=None,
|
|
|
|
| 7 |
|
| 8 |
from Gradio_UI import GradioUI
|
| 9 |
|
| 10 |
+
# List of Norwegian news websites to scrape
|
| 11 |
+
NEWS_SITES = {
|
| 12 |
+
"Aftenposten": "https://www.aftenposten.no",
|
| 13 |
+
"VG": "https://www.vg.no",
|
| 14 |
+
"Dagbladet": "https://www.dagbladet.no",
|
| 15 |
+
"Nettavisen": "https://www.nettavisen.no",
|
| 16 |
+
"Dagens Næringsliv": "https://www.dn.no"
|
| 17 |
+
}
|
| 18 |
+
|
| 19 |
+
@tool
|
| 20 |
+
def news_summary_tool() -> str:
|
| 21 |
+
"""Fetches and summarizes today's top headlines from major Norwegian newspapers."""
|
| 22 |
+
headlines = {}
|
| 23 |
+
summary = "Today's top news in Norway:\n"
|
| 24 |
+
|
| 25 |
+
for site, url in NEWS_SITES.items():
|
| 26 |
+
try:
|
| 27 |
+
response = requests.get(url, timeout=10)
|
| 28 |
+
response.raise_for_status()
|
| 29 |
+
soup = BeautifulSoup(response.text, 'html.parser')
|
| 30 |
+
|
| 31 |
+
# Attempt to find headlines based on common tag patterns
|
| 32 |
+
headlines[site] = [h.get_text().strip() for h in soup.find_all(['h1', 'h2'], limit=10)]
|
| 33 |
+
|
| 34 |
+
if headlines[site]:
|
| 35 |
+
summary += f"\n{site}:\n" + "\n".join(f"- {h}" for h in headlines[site]) + "\n"
|
| 36 |
+
else:
|
| 37 |
+
summary += f"\n{site}: No headlines found.\n"
|
| 38 |
+
except Exception as e:
|
| 39 |
+
summary += f"\n{site}: Error fetching news - {str(e)}\n"
|
| 40 |
+
|
| 41 |
+
return summary
|
| 42 |
+
|
| 43 |
# Below is an example of a tool that does nothing. Amaze us with your creativity !
|
| 44 |
@tool
|
| 45 |
def my_custom_tool(arg1:str, arg2:int)-> str: #it's import to specify the return type
|
|
|
|
| 88 |
|
| 89 |
agent = CodeAgent(
|
| 90 |
model=model,
|
| 91 |
+
tools=[news_summary_tool, final_answer], ## add your tools here (don't remove final answer)
|
| 92 |
max_steps=6,
|
| 93 |
verbosity_level=1,
|
| 94 |
grammar=None,
|