Spaces:
Running
Running
Suman Das
commited on
Commit
·
f76a072
1
Parent(s):
ae7a494
updated smol agents app
Browse files- Gradio_UI.py +1 -1
- README.md +4 -4
- app.py +25 -17
Gradio_UI.py
CHANGED
|
@@ -265,7 +265,7 @@ class GradioUI:
|
|
| 265 |
stored_messages = gr.State([])
|
| 266 |
file_uploads_log = gr.State([])
|
| 267 |
chatbot = gr.Chatbot(
|
| 268 |
-
label="Agent",
|
| 269 |
type="messages",
|
| 270 |
avatar_images=(
|
| 271 |
None,
|
|
|
|
| 265 |
stored_messages = gr.State([])
|
| 266 |
file_uploads_log = gr.State([])
|
| 267 |
chatbot = gr.Chatbot(
|
| 268 |
+
label="Post Card Generator Agent",
|
| 269 |
type="messages",
|
| 270 |
avatar_images=(
|
| 271 |
None,
|
README.md
CHANGED
|
@@ -1,8 +1,8 @@
|
|
| 1 |
---
|
| 2 |
-
title:
|
| 3 |
-
emoji:
|
| 4 |
-
colorFrom:
|
| 5 |
-
colorTo:
|
| 6 |
sdk: gradio
|
| 7 |
sdk_version: 5.15.0
|
| 8 |
app_file: app.py
|
|
|
|
| 1 |
---
|
| 2 |
+
title: Post Card Generator
|
| 3 |
+
emoji: ✉️
|
| 4 |
+
colorFrom: orange
|
| 5 |
+
colorTo: green
|
| 6 |
sdk: gradio
|
| 7 |
sdk_version: 5.15.0
|
| 8 |
app_file: app.py
|
app.py
CHANGED
|
@@ -1,22 +1,30 @@
|
|
| 1 |
-
from smolagents import CodeAgent,DuckDuckGoSearchTool, HfApiModel,load_tool,tool
|
| 2 |
import datetime
|
| 3 |
-
|
| 4 |
import pytz
|
| 5 |
import yaml
|
| 6 |
-
from
|
|
|
|
| 7 |
|
| 8 |
from Gradio_UI import GradioUI
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 9 |
|
| 10 |
-
|
| 11 |
-
|
| 12 |
-
|
| 13 |
-
|
| 14 |
-
|
| 15 |
-
Args:
|
| 16 |
-
arg1: the first argument
|
| 17 |
-
arg2: the second argument
|
| 18 |
-
"""
|
| 19 |
-
return "What magic will you build ?"
|
| 20 |
|
| 21 |
@tool
|
| 22 |
def get_current_time_in_timezone(timezone: str) -> str:
|
|
@@ -41,21 +49,21 @@ final_answer = FinalAnswerTool()
|
|
| 41 |
|
| 42 |
model = HfApiModel(
|
| 43 |
max_tokens=2096,
|
| 44 |
-
temperature=0.
|
| 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 |
|
| 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,
|
|
|
|
|
|
|
| 1 |
import datetime
|
| 2 |
+
|
| 3 |
import pytz
|
| 4 |
import yaml
|
| 5 |
+
from huggingface_hub import InferenceClient
|
| 6 |
+
from smolagents import CodeAgent, HfApiModel, tool, Tool
|
| 7 |
|
| 8 |
from Gradio_UI import GradioUI
|
| 9 |
+
from tools.final_answer import FinalAnswerTool
|
| 10 |
+
|
| 11 |
+
|
| 12 |
+
class TextToImageTool(Tool):
|
| 13 |
+
description = "This tool creates an image according to a prompt, which is a text description."
|
| 14 |
+
name = "image_generator"
|
| 15 |
+
inputs = {"prompt":
|
| 16 |
+
{"type": "string",
|
| 17 |
+
"description": "The image generator prompt. Don't hesitate to add details in the prompt to make the image look better, like 'high-res, photorealistic', etc."}
|
| 18 |
+
}
|
| 19 |
+
output_type = "image"
|
| 20 |
+
model_sdxl = "black-forest-labs/FLUX.1-schnell"
|
| 21 |
+
client = InferenceClient(model_sdxl)
|
| 22 |
|
| 23 |
+
|
| 24 |
+
def forward(self, prompt):
|
| 25 |
+
updated_prompt = prompt + ". Don't use duplicate or overlapping texts. Make sure words used in the image are correctly spelled."
|
| 26 |
+
print(updated_prompt)
|
| 27 |
+
return self.client.text_to_image(updated_prompt)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 28 |
|
| 29 |
@tool
|
| 30 |
def get_current_time_in_timezone(timezone: str) -> str:
|
|
|
|
| 49 |
|
| 50 |
model = HfApiModel(
|
| 51 |
max_tokens=2096,
|
| 52 |
+
temperature=0.1,
|
| 53 |
model_id='Qwen/Qwen2.5-Coder-32B-Instruct',# it is possible that this model may be overloaded
|
| 54 |
custom_role_conversions=None,
|
| 55 |
)
|
| 56 |
|
| 57 |
|
| 58 |
# Import tool from Hub
|
| 59 |
+
# image_generation_tool = load_tool("agents-course/text-to-image", trust_remote_code=True)
|
| 60 |
+
image_generation_tool = TextToImageTool()
|
| 61 |
with open("prompts.yaml", 'r') as stream:
|
| 62 |
prompt_templates = yaml.safe_load(stream)
|
| 63 |
|
| 64 |
agent = CodeAgent(
|
| 65 |
model=model,
|
| 66 |
+
tools=[image_generation_tool,final_answer], ## add your tools here (don't remove final answer)
|
| 67 |
max_steps=6,
|
| 68 |
verbosity_level=1,
|
| 69 |
grammar=None,
|