Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -85,6 +85,29 @@ def get_current_time_in_timezone(timezone: str) -> str:
|
|
| 85 |
return f"Error fetching time for timezone '{timezone}': {str(e)}"
|
| 86 |
|
| 87 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 88 |
final_answer = FinalAnswerTool()
|
| 89 |
|
| 90 |
# 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:
|
|
@@ -105,7 +128,7 @@ with open("prompts.yaml", 'r') as stream:
|
|
| 105 |
|
| 106 |
agent = CodeAgent(
|
| 107 |
model=model,
|
| 108 |
-
tools=[final_answer,enhanced_translate,
|
| 109 |
max_steps=6,
|
| 110 |
verbosity_level=1,
|
| 111 |
grammar=None,
|
|
|
|
| 85 |
return f"Error fetching time for timezone '{timezone}': {str(e)}"
|
| 86 |
|
| 87 |
|
| 88 |
+
@tool
|
| 89 |
+
def generate_image(prompt: str) -> str:
|
| 90 |
+
"""
|
| 91 |
+
A tool that generates an image from a text prompt using Replicate's Stable Diffusion API.
|
| 92 |
+
|
| 93 |
+
Args:
|
| 94 |
+
prompt: A detailed text description of the image to generate.
|
| 95 |
+
|
| 96 |
+
Returns:
|
| 97 |
+
A URL of the generated image.
|
| 98 |
+
"""
|
| 99 |
+
try:
|
| 100 |
+
api_url = "https://replicate.com/api/models/stability-ai/stable-diffusion"
|
| 101 |
+
response = requests.post(api_url, json={"input": {"prompt": prompt}})
|
| 102 |
+
|
| 103 |
+
if response.status_code == 200:
|
| 104 |
+
return response.json().get("output", ["Image generation failed."])[0]
|
| 105 |
+
else:
|
| 106 |
+
return f"Error: {response.status_code} - {response.text}"
|
| 107 |
+
|
| 108 |
+
except Exception as e:
|
| 109 |
+
return f"Failed to generate image: {str(e)}"
|
| 110 |
+
|
| 111 |
final_answer = FinalAnswerTool()
|
| 112 |
|
| 113 |
# 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:
|
|
|
|
| 128 |
|
| 129 |
agent = CodeAgent(
|
| 130 |
model=model,
|
| 131 |
+
tools=[final_answer,enhanced_translate,generate_image,search_tool ], ## add your tools here (don't remove final answer)
|
| 132 |
max_steps=6,
|
| 133 |
verbosity_level=1,
|
| 134 |
grammar=None,
|