Imaan Soltanalipour commited on
Commit
4837cbe
·
verified ·
1 Parent(s): 451ca4e

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +14 -5
app.py CHANGED
@@ -10,16 +10,25 @@ import io
10
  from Gradio_UI import GradioUI
11
 
12
  @tool
13
- def generate_image(prompt: str) -> Image.Image:
14
  """
15
- Generates an image based on a provided text prompt using an open-source model.
 
16
 
17
  Args:
18
  prompt: A detailed text description of the image to create.
19
  """
 
20
  client = InferenceClient("black-forest-labs/FLUX.1-schnell")
21
  image_bytes = client.text_to_image(prompt)
22
- return Image.open(io.BytesIO(image_bytes))
 
 
 
 
 
 
 
23
 
24
  # Below is an example of a tool that does nothing. Amaze us with your creativity !
25
  @tool
@@ -31,9 +40,9 @@ def cast_spell(mana:int)-> str: #it's import to specify the return type
31
  """
32
  if mana > 0:
33
 
34
- if 10 > mana > 5:
35
  return "FIREBALL"
36
- elif 15 > mana > 10:
37
  return "THUNDERBALL"
38
 
39
  return "AIRBALL"
 
10
  from Gradio_UI import GradioUI
11
 
12
  @tool
13
+ def generate_image(prompt: str) -> str:
14
  """
15
+ Generates an image based on a provided text prompt using an open-source model,
16
+ saves it locally, and returns the path to render it in the chat interface.
17
 
18
  Args:
19
  prompt: A detailed text description of the image to create.
20
  """
21
+ # 1. Fetch image from Hugging Face Inference API
22
  client = InferenceClient("black-forest-labs/FLUX.1-schnell")
23
  image_bytes = client.text_to_image(prompt)
24
+ image = Image.open(io.BytesIO(image_bytes))
25
+
26
+ # 2. Save it locally inside your execution workspace
27
+ output_path = "generated_output.png"
28
+ image.save(output_path)
29
+
30
+ # 3. Return the string file path. Gradio will intercept this path and display the actual image!
31
+ return output_path
32
 
33
  # Below is an example of a tool that does nothing. Amaze us with your creativity !
34
  @tool
 
40
  """
41
  if mana > 0:
42
 
43
+ if 10 > mana >= 5:
44
  return "FIREBALL"
45
+ elif 15 > mana >= 10:
46
  return "THUNDERBALL"
47
 
48
  return "AIRBALL"