Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
|
@@ -4,19 +4,28 @@ import requests
|
|
| 4 |
import pytz
|
| 5 |
import yaml
|
| 6 |
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
|
| 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:
|
|
@@ -34,6 +43,14 @@ def get_current_time_in_timezone(timezone: str) -> str:
|
|
| 34 |
return f"Error fetching time for timezone '{timezone}': {str(e)}"
|
| 35 |
|
| 36 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 37 |
final_answer = FinalAnswerTool()
|
| 38 |
|
| 39 |
# If the agent does not answer, the model is overloaded, please use another model or the following Hugging Face Endpoint that also contains qwen2.5 coder:
|
|
@@ -47,15 +64,12 @@ custom_role_conversions=None,
|
|
| 47 |
)
|
| 48 |
|
| 49 |
|
| 50 |
-
# Import tool from Hub
|
| 51 |
-
image_generation_tool = load_tool("agents-course/text-to-image", trust_remote_code=True)
|
| 52 |
-
|
| 53 |
with open("prompts.yaml", 'r') as stream:
|
| 54 |
prompt_templates = yaml.safe_load(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,
|
|
|
|
| 4 |
import pytz
|
| 5 |
import yaml
|
| 6 |
from tools.final_answer import FinalAnswerTool
|
| 7 |
+
from tools.visit_webpage import VisitWebpageTool
|
| 8 |
+
!pip install gliner
|
| 9 |
+
from gliner import GLiNER
|
| 10 |
from Gradio_UI import GradioUI
|
| 11 |
|
|
|
|
| 12 |
@tool
|
| 13 |
+
def ner_tool(text:str, labels:list)-> str:
|
| 14 |
+
"""A tool that calls the GLiNER model to perform a name entity recognition task on a piece of text.
|
|
|
|
| 15 |
Args:
|
| 16 |
+
text: the text on which to perform the name entity recognition task
|
| 17 |
+
labels: a list of the types of entities to extract from the text
|
| 18 |
"""
|
| 19 |
+
try:
|
| 20 |
+
model = GLiNER.from_pretrained("urchade/gliner_large-v2.1")
|
| 21 |
+
entities_list = []
|
| 22 |
+
results = model.predict_entities(text, labels)
|
| 23 |
+
for entity in results:
|
| 24 |
+
entities_list.append(entity["text"])
|
| 25 |
+
entities = ", ".join(entities_list)
|
| 26 |
+
return entities
|
| 27 |
+
except Exception as e:
|
| 28 |
+
return "Error fetching entities."
|
| 29 |
|
| 30 |
@tool
|
| 31 |
def get_current_time_in_timezone(timezone: str) -> str:
|
|
|
|
| 43 |
return f"Error fetching time for timezone '{timezone}': {str(e)}"
|
| 44 |
|
| 45 |
|
| 46 |
+
# Import tool from Hub
|
| 47 |
+
image_generation_tool = load_tool("agents-course/text-to-image", trust_remote_code=True)
|
| 48 |
+
|
| 49 |
+
# The rest of the tools
|
| 50 |
+
search_web = DuckDuckGoSearchTool()
|
| 51 |
+
visit_page = VisitWebpageTool()
|
| 52 |
+
ner = ner_tool()
|
| 53 |
+
timezone = get_current_time_in_timezone()
|
| 54 |
final_answer = FinalAnswerTool()
|
| 55 |
|
| 56 |
# If the agent does not answer, the model is overloaded, please use another model or the following Hugging Face Endpoint that also contains qwen2.5 coder:
|
|
|
|
| 64 |
)
|
| 65 |
|
| 66 |
|
|
|
|
|
|
|
|
|
|
| 67 |
with open("prompts.yaml", 'r') as stream:
|
| 68 |
prompt_templates = yaml.safe_load(stream)
|
| 69 |
|
| 70 |
agent = CodeAgent(
|
| 71 |
model=model,
|
| 72 |
+
tools=[image_generation_tool, search_web, visit_page, ner, timezone, final_answer], ## add your tools here (don't remove final answer)
|
| 73 |
max_steps=6,
|
| 74 |
verbosity_level=1,
|
| 75 |
grammar=None,
|