Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,4 +1,4 @@
|
|
| 1 |
-
from smolagents import CodeAgent,DuckDuckGoSearchTool, HfApiModel,load_tool,tool
|
| 2 |
import datetime
|
| 3 |
import requests
|
| 4 |
import pytz
|
|
@@ -33,6 +33,18 @@ def get_current_time_in_timezone(timezone: str) -> str:
|
|
| 33 |
except Exception as e:
|
| 34 |
return f"Error fetching time for timezone '{timezone}': {str(e)}"
|
| 35 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 36 |
|
| 37 |
final_answer = FinalAnswerTool()
|
| 38 |
|
|
@@ -40,21 +52,18 @@ final_answer = FinalAnswerTool()
|
|
| 40 |
# model_id='https://pflgm2locj2t89co.us-east-1.aws.endpoints.huggingface.cloud'
|
| 41 |
|
| 42 |
model = HfApiModel(
|
| 43 |
-
max_tokens=2096,
|
| 44 |
-
temperature=0.5,
|
| 45 |
-
model_id='Qwen/Qwen2.5-Coder-32B-Instruct',# it is possible that this model may be overloaded
|
| 46 |
-
custom_role_conversions=None,
|
| 47 |
)
|
| 48 |
|
| 49 |
-
# Import tool from Hub
|
| 50 |
-
image_generation_tool = load_tool("agents-course/text-to-image", trust_remote_code=True)
|
| 51 |
-
|
| 52 |
with open("prompts.yaml", 'r') as stream:
|
| 53 |
prompt_templates = yaml.safe_load(stream)
|
| 54 |
|
| 55 |
agent = CodeAgent(
|
| 56 |
model=model,
|
| 57 |
-
tools=[final_answer,
|
| 58 |
max_steps=6,
|
| 59 |
verbosity_level=1,
|
| 60 |
grammar=None,
|
|
@@ -64,16 +73,4 @@ agent = CodeAgent(
|
|
| 64 |
prompt_templates=prompt_templates
|
| 65 |
)
|
| 66 |
|
| 67 |
-
img = image_generation_tool(prompt="A cute cat with prominent moustaches, photorealistic, high-resolution")
|
| 68 |
-
|
| 69 |
-
print("Returned type:", type(img))
|
| 70 |
-
print("Returned value:", img)
|
| 71 |
-
|
| 72 |
-
# If it's a PIL image, this will work:
|
| 73 |
-
try:
|
| 74 |
-
img.save("/tmp/test.png")
|
| 75 |
-
print("Saved to /tmp/test.png")
|
| 76 |
-
except Exception as e:
|
| 77 |
-
print("Could not save as PIL:", e)
|
| 78 |
-
|
| 79 |
GradioUI(agent).launch()
|
|
|
|
| 1 |
+
from smolagents import CodeAgent, DuckDuckGoSearchTool, HfApiModel, load_tool, tool
|
| 2 |
import datetime
|
| 3 |
import requests
|
| 4 |
import pytz
|
|
|
|
| 33 |
except Exception as e:
|
| 34 |
return f"Error fetching time for timezone '{timezone}': {str(e)}"
|
| 35 |
|
| 36 |
+
# Import tool from Hub
|
| 37 |
+
image_generation_tool = load_tool("agents-course/text-to-image", trust_remote_code=True)
|
| 38 |
+
|
| 39 |
+
@tool
|
| 40 |
+
def generate_image_file(prompt: str) -> str:
|
| 41 |
+
"""Generate an image from a text prompt and return a filepath to the PNG."""
|
| 42 |
+
img = image_generation_tool(prompt=prompt)
|
| 43 |
+
out_path = "/tmp/generated.png"
|
| 44 |
+
img.save(out_path)
|
| 45 |
+
return out_path
|
| 46 |
+
|
| 47 |
+
|
| 48 |
|
| 49 |
final_answer = FinalAnswerTool()
|
| 50 |
|
|
|
|
| 52 |
# model_id='https://pflgm2locj2t89co.us-east-1.aws.endpoints.huggingface.cloud'
|
| 53 |
|
| 54 |
model = HfApiModel(
|
| 55 |
+
max_tokens=2096,
|
| 56 |
+
temperature=0.5,
|
| 57 |
+
model_id='Qwen/Qwen2.5-Coder-32B-Instruct',# it is possible that this model may be overloaded
|
| 58 |
+
custom_role_conversions=None,
|
| 59 |
)
|
| 60 |
|
|
|
|
|
|
|
|
|
|
| 61 |
with open("prompts.yaml", 'r') as stream:
|
| 62 |
prompt_templates = yaml.safe_load(stream)
|
| 63 |
|
| 64 |
agent = CodeAgent(
|
| 65 |
model=model,
|
| 66 |
+
tools=[final_answer, generate_image_file], ## add your tools here (don't remove final answer)
|
| 67 |
max_steps=6,
|
| 68 |
verbosity_level=1,
|
| 69 |
grammar=None,
|
|
|
|
| 73 |
prompt_templates=prompt_templates
|
| 74 |
)
|
| 75 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 76 |
GradioUI(agent).launch()
|