Files changed (1) hide show
  1. app.py +33 -37
app.py CHANGED
@@ -6,63 +6,59 @@ import yaml
6
  from tools.final_answer import FinalAnswerTool
7
  from Gradio_UI import GradioUI
8
 
9
- # Below is an example of a tool that does nothing. Amaze us with your creativity !
10
- @tool
11
- def my_custom_tool(userprompt: str) -> str: #it's import to specify the return type
12
- """A tool that does helps to generate the image for the given text prompt
13
- Args:
14
- userprompt: A string prompt that helps the image to generate
15
- Returns:
16
- str: A generated image.
17
- """
18
- # Import tool from Hub
19
- image_generation_tool = load_tool("agents-course/text-to-image", trust_remote_code=True)
20
- return image_generation_tool(userprompt)
 
 
21
 
22
  @tool
23
- def get_current_time_in_timezone(timezone: str) -> str:
24
- """A tool that fetches the current local time in a specified timezone.
25
- Args:
26
- timezone: A string representing a valid timezone (e.g., 'America/New_York').
27
- """
28
  try:
29
- # Create timezone object
30
- tz = pytz.timezone(timezone)
31
- # Get current time in that timezone
32
- local_time = datetime.datetime.now(tz).strftime("%Y-%m-%d %H:%M:%S")
33
- return f"The current local time in {timezone} is: {local_time}"
 
 
 
34
  except Exception as e:
35
- return f"Error fetching time for timezone '{timezone}': {str(e)}"
36
 
37
 
38
- final_answer = FinalAnswerTool()
39
 
40
- # 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:
41
- # model_id='https://pflgm2locj2t89co.us-east-1.aws.endpoints.huggingface.cloud'
42
 
43
- # Define the AI model
44
- model = HfApiModel(
45
- max_tokens=2096,
46
- temperature=0.5,
47
- model_id='Qwen/Qwen2.5-Coder-32B-Instruct', # it is possible that this model may be overloaded
48
- custom_role_conversions=None,
49
- )
50
 
51
  # Load prompt templates
52
  with open("prompts.yaml", 'r') as stream:
53
  prompt_templates = yaml.safe_load(stream)
54
 
55
- # Create the AI agent with tools
56
  agent = CodeAgent(
57
- model=model,
58
- tools=[final_answer,my_custom_tool,get_current_time_in_timezone], ## add your tools here (don't remove final answer)
59
  max_steps=6,
60
  verbosity_level=1,
61
  grammar=None,
62
  planning_interval=None,
63
  name=None,
64
  description=None,
65
- prompt_templates=prompt_templates
66
  )
67
 
68
  # Launch the AI agent with Gradio
 
6
  from tools.final_answer import FinalAnswerTool
7
  from Gradio_UI import GradioUI
8
 
9
+ # Подключаем модели
10
+ text_model = HfApiModel(
11
+ max_tokens=2096,
12
+ temperature=0.5,
13
+ model_id='Qwen/Qwen2.5-Coder-32B-Instruct', # Модель для обработки текста
14
+ custom_role_conversions=None,
15
+ )
16
+
17
+ image_model = HfApiModel(
18
+ max_tokens=2096,
19
+ temperature=0.5,
20
+ model_id="black-forest-labs/FLUX.1-dev", # Модель для генерации изображений
21
+ custom_role_conversions=None,
22
+ )
23
 
24
  @tool
25
+ def generate_image_from_text(prompt: str) -> str:
26
+ """Инструмент для генерации изображения на основе текстового описания."""
 
 
 
27
  try:
28
+ # Загружаем инструмент для генерации изображений с Hugging Face
29
+ image_generation_tool = load_tool("multimodalart/flux.1-dev", trust_remote_code=True)
30
+
31
+ # Генерация изображения
32
+ generated_image = image_generation_tool(prompt=prompt)
33
+
34
+ # Возвращаем путь или URL изображения
35
+ return generated_image
36
  except Exception as e:
37
+ return f"Error generating image: {str(e)}"
38
 
39
 
40
+
41
 
 
 
42
 
43
+ final_answer = FinalAnswerTool()
44
+
45
+
 
 
 
 
46
 
47
  # Load prompt templates
48
  with open("prompts.yaml", 'r') as stream:
49
  prompt_templates = yaml.safe_load(stream)
50
 
51
+ # Инициализируем агента, передавая обе модели
52
  agent = CodeAgent(
53
+ model=text_model, # Здесь указываем модель для обработки текста
54
+ tools=[FinalAnswerTool(), generate_image_from_text], # Добавляем инструменты
55
  max_steps=6,
56
  verbosity_level=1,
57
  grammar=None,
58
  planning_interval=None,
59
  name=None,
60
  description=None,
61
+ prompt_templates=None, # Указывайте шаблоны при необходимости
62
  )
63
 
64
  # Launch the AI agent with Gradio