Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -4,19 +4,36 @@ import requests
|
|
| 4 |
import pytz
|
| 5 |
import yaml
|
| 6 |
from tools.final_answer import FinalAnswerTool
|
|
|
|
| 7 |
|
| 8 |
from Gradio_UI import GradioUI
|
| 9 |
|
| 10 |
-
|
| 11 |
@tool
|
| 12 |
-
def my_custom_tool(
|
| 13 |
#Keep this format for the description / args / args description but feel free to modify the tool
|
| 14 |
"""A tool that does nothing yet
|
| 15 |
Args:
|
| 16 |
arg1: the first argument
|
| 17 |
arg2: the second argument
|
| 18 |
"""
|
| 19 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 20 |
|
| 21 |
@tool
|
| 22 |
def get_current_time_in_timezone(timezone: str) -> str:
|
|
@@ -55,7 +72,7 @@ with open("prompts.yaml", 'r') as stream:
|
|
| 55 |
|
| 56 |
agent = CodeAgent(
|
| 57 |
model=model,
|
| 58 |
-
tools=[final_answer],
|
| 59 |
max_steps=6,
|
| 60 |
verbosity_level=1,
|
| 61 |
grammar=None,
|
|
|
|
| 4 |
import pytz
|
| 5 |
import yaml
|
| 6 |
from tools.final_answer import FinalAnswerTool
|
| 7 |
+
from bertopic import BERTopic
|
| 8 |
|
| 9 |
from Gradio_UI import GradioUI
|
| 10 |
|
| 11 |
+
|
| 12 |
@tool
|
| 13 |
+
def my_custom_tool(text:str, arg2:int)-> str: #it's import to specify the return type
|
| 14 |
#Keep this format for the description / args / args description but feel free to modify the tool
|
| 15 |
"""A tool that does nothing yet
|
| 16 |
Args:
|
| 17 |
arg1: the first argument
|
| 18 |
arg2: the second argument
|
| 19 |
"""
|
| 20 |
+
try:
|
| 21 |
+
# Load the pre-trained BERTopic model
|
| 22 |
+
topic_model = BERTopic.load("MaartenGr/BERTopic_ArXiv")
|
| 23 |
+
|
| 24 |
+
# Generate topics and their probabilities
|
| 25 |
+
topics, _ = topic_model.transform(text)
|
| 26 |
+
|
| 27 |
+
topic_words = topic_model.get_topic(topics[0])
|
| 28 |
+
|
| 29 |
+
# Retrieve the actual topic words
|
| 30 |
+
topic_words = [word[0] for word in topic_words ]
|
| 31 |
+
topic_words = ' '.join(topic_words)
|
| 32 |
+
|
| 33 |
+
except Exception as e:
|
| 34 |
+
return f"Error fetching time for timezone '{timezone}': {str(e)}"
|
| 35 |
+
|
| 36 |
+
return "Here is the topic of the text: ", topic_words
|
| 37 |
|
| 38 |
@tool
|
| 39 |
def get_current_time_in_timezone(timezone: str) -> str:
|
|
|
|
| 72 |
|
| 73 |
agent = CodeAgent(
|
| 74 |
model=model,
|
| 75 |
+
tools=[final_answer, my_custom_tool],
|
| 76 |
max_steps=6,
|
| 77 |
verbosity_level=1,
|
| 78 |
grammar=None,
|