vladd19 commited on
Commit
75bdc27
·
verified ·
1 Parent(s): 8c5c24b

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +25 -7
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
@@ -9,14 +9,32 @@ 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 my_custom_tool(arg1:str, arg2:int)-> str: #it's import to specify the return type
13
- #Keep this format for the description / args / args description but feel free to modify the tool
14
- """A tool that does nothing yet
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:
 
1
+ from smolagents import CodeAgent, DuckDuckGoSearchTool, HfApiModel,load_tool,tool
2
  import datetime
3
  import requests
4
  import pytz
 
9
 
10
  # Below is an example of a tool that does nothing. Amaze us with your creativity !
11
  @tool
12
+ def generate_image(prompt: str, negative_prompt: str = "blurry, text, watermark, low quality", width: int = 1024, height: int = 1024) -> Image.Image:
13
+ """
14
+ Генерирует изображение по текстовому описанию с использованием диффузионной модели.
15
  Args:
16
+ prompt: Подробное описание того, что должно быть на изображении.
17
+ negative_prompt: Что следует избегать в результате.
18
+ width: Ширина изображения в пикселях (кратно 8, макс 1024 на бесплатном тарифе).
19
+ height: Высота изображения в пикселях (кратно 8, макс 1024).
20
+ Returns:
21
+ PIL.Image.Image: Сгенерированное изображение.
22
  """
23
+ try:
24
+ # Вызов Inference API (FLUX.1-schnell быстрый и хорошо работает на free tier)
25
+ image = hf_client.text_to_image(
26
+ prompt=prompt,
27
+ negative_prompt=negative_prompt,
28
+ model="black-forest-labs/FLUX.1-schnell",
29
+ width=width,
30
+ height=height,
31
+ num_inference_steps=4, # Для скорости. Поднимите до 20-30 для качества
32
+ guidance_scale=3.5
33
+ )
34
+ return image
35
+ except Exception as e:
36
+ # Возвращаем строку с ошибкой, чтобы агент не "упал", а мог объяснить пользователю
37
+ return f"❌ Ошибка генерации: {str(e)}"
38
 
39
  @tool
40
  def get_current_time_in_timezone(timezone: str) -> str: