abdullahfurquan commited on
Commit
fef29d4
·
verified ·
1 Parent(s): 6b98fd7

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +23 -12
app.py CHANGED
@@ -15,24 +15,35 @@ from Gradio_UI import GradioUI
15
  image_generation_tool = load_tool("agents-course/text-to-image", trust_remote_code=True,hf_token=os.getenv("HF_TOKEN"))
16
 
17
 
18
- # Below is an example of a tool that does nothing. Amaze us with your creativity !
19
 
20
- @tool
21
- def generate_image_tool(prompt: str) -> Image:
22
- """Generates an image from text using the image generation tool.
23
-
24
- Args:
25
- prompt: A description of the image to generate.
26
-
27
- Returns:
28
- The generated image.
29
- """
30
  try:
31
- return image_generation_tool(prompt)
 
 
 
32
  except Exception as e:
33
  return f"Error generating image: {str(e)}"
34
 
35
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
36
 
37
 
38
  # Below is an example of a tool that does nothing. Amaze us with your creativity !
 
15
  image_generation_tool = load_tool("agents-course/text-to-image", trust_remote_code=True,hf_token=os.getenv("HF_TOKEN"))
16
 
17
 
18
+ # Image generation !
19
 
20
+ def generate_image_tool(prompt: str) -> str:
21
+ """Generates an image from text and returns the file path."""
 
 
 
 
 
 
 
 
22
  try:
23
+ image = image_generation_tool(prompt) # Get PIL Image
24
+ file_path = "generated_image.jpg"
25
+ image.save(file_path) # Save it
26
+ return file_path # Return the file path
27
  except Exception as e:
28
  return f"Error generating image: {str(e)}"
29
 
30
 
31
+ # @tool
32
+ # def generate_image_tool(prompt: str) -> Image:
33
+ # """Generates an image from text using the image generation tool.
34
+
35
+ # Args:
36
+ # prompt: A description of the image to generate.
37
+
38
+ # Returns:
39
+ # The generated image.
40
+ # """
41
+ # try:
42
+ # return image_generation_tool(prompt)
43
+ # except Exception as e:
44
+ # return f"Error generating image: {str(e)}"
45
+
46
+
47
 
48
 
49
  # Below is an example of a tool that does nothing. Amaze us with your creativity !