Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
|
@@ -34,7 +34,7 @@ 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
|
| 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:
|
| 40 |
# model_id='https://pflgm2locj2t89co.us-east-1.aws.endpoints.huggingface.cloud'
|
|
@@ -52,6 +52,33 @@ image_generation_tool = load_tool("agents-course/text-to-image", trust_remote_co
|
|
| 52 |
|
| 53 |
with open("prompts.yaml", 'r') as stream:
|
| 54 |
prompt_templates = yaml.safe_load(stream)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 55 |
|
| 56 |
agent = CodeAgent(
|
| 57 |
model=model,
|
|
|
|
| 34 |
return f"Error fetching time for timezone '{timezone}': {str(e)}"
|
| 35 |
|
| 36 |
|
| 37 |
+
tools=[final_answer, image_generation_tool, summarize_text, analyze_sentiment, get_current_time_in_timezone]
|
| 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:
|
| 40 |
# model_id='https://pflgm2locj2t89co.us-east-1.aws.endpoints.huggingface.cloud'
|
|
|
|
| 52 |
|
| 53 |
with open("prompts.yaml", 'r') as stream:
|
| 54 |
prompt_templates = yaml.safe_load(stream)
|
| 55 |
+
|
| 56 |
+
@tool
|
| 57 |
+
def summarize_text(content: str) -> str:
|
| 58 |
+
"""A tool to summarize long passages of text."""
|
| 59 |
+
try:
|
| 60 |
+
from transformers import pipeline
|
| 61 |
+
summarizer = pipeline("summarization")
|
| 62 |
+
summary = summarizer(content, max_length=100, min_length=30, do_sample=False)
|
| 63 |
+
return summary[0]['summary_text']
|
| 64 |
+
except Exception as e:
|
| 65 |
+
return f"Error processing summary: {str(e)}"
|
| 66 |
+
|
| 67 |
+
@tool
|
| 68 |
+
def analyze_sentiment(text: str) -> str:
|
| 69 |
+
"""A tool to perform basic sentiment analysis."""
|
| 70 |
+
from textblob import TextBlob
|
| 71 |
+
sentiment_score = TextBlob(text).sentiment.polarity
|
| 72 |
+
if sentiment_score > 0:
|
| 73 |
+
return "Positive sentiment detected!"
|
| 74 |
+
elif sentiment_score < 0:
|
| 75 |
+
return "Negative sentiment detected!"
|
| 76 |
+
else:
|
| 77 |
+
return "Neutral sentiment detected."
|
| 78 |
+
|
| 79 |
+
# Ensure image generation is included
|
| 80 |
+
tools_list = [final_answer, image_generation_tool, summarize_text, analyze_sentiment, get_current_time_in_timezone]
|
| 81 |
+
|
| 82 |
|
| 83 |
agent = CodeAgent(
|
| 84 |
model=model,
|