mohan260851 commited on
Commit
7f61980
·
verified ·
1 Parent(s): ae7a494

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +22 -2
app.py CHANGED
@@ -4,7 +4,7 @@ import requests
4
  import pytz
5
  import yaml
6
  from tools.final_answer import FinalAnswerTool
7
-
8
  from Gradio_UI import GradioUI
9
 
10
  # Below is an example of a tool that does nothing. Amaze us with your creativity !
@@ -33,6 +33,26 @@ 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
 
@@ -55,7 +75,7 @@ with open("prompts.yaml", 'r') as 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,
 
4
  import pytz
5
  import yaml
6
  from tools.final_answer import FinalAnswerTool
7
+ from huggingface_hub import InferenceClient
8
  from Gradio_UI import GradioUI
9
 
10
  # Below is an example of a tool that does nothing. Amaze us with your creativity !
 
33
  except Exception as e:
34
  return f"Error fetching time for timezone '{timezone}': {str(e)}"
35
 
36
+ @tool
37
+ def image_generator(description: str):
38
+ """A tool that generates an image from a description.
39
+ Args:
40
+ deescription: A string representing the description of the image.
41
+ """
42
+ try:
43
+ client = InferenceClient(
44
+ # provider="hf-inference",
45
+ api_key=os.getenv('HF_TOKEN')
46
+ )
47
+
48
+ # output is a PIL.Image object
49
+ image = client.text_to_image(
50
+ prompt=description,
51
+ model="dreamlike-art/dreamlike-photoreal-2.0"
52
+ )
53
+ return image
54
+ except Exception as e:
55
+ return f"Error generating image: {str(e)}"
56
 
57
  final_answer = FinalAnswerTool()
58
 
 
75
 
76
  agent = CodeAgent(
77
  model=model,
78
+ tools=[final_answer,get_current_time_in_timezone, image_generator], ## add your tools here (don't remove final answer)
79
  max_steps=6,
80
  verbosity_level=1,
81
  grammar=None,