veasnakao commited on
Commit
be9d420
·
verified ·
1 Parent(s): 8c86f75

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +6 -5
app.py CHANGED
@@ -2,24 +2,25 @@ import gradio as gr
2
  from PIL import Image, ImageDraw
3
  import io
4
 
5
- # Define a function to generate an image from a prompt
6
  def generate_image(prompt):
7
  try:
8
- # Create a simple image for testing
9
  img = Image.new('RGB', (256, 256), color='blue')
10
  draw = ImageDraw.Draw(img)
11
  draw.text((10, 10), prompt, fill='white')
12
 
13
- # Convert image to bytes and then return
14
  buffered = io.BytesIO()
15
  img.save(buffered, format="PNG")
16
  img_bytes = buffered.getvalue()
17
 
18
- return Image.open(io.BytesIO(img_bytes)) # Ensure image is in PIL format
 
19
  except Exception as e:
20
  return f"Error: {e}"
21
 
22
- # Create Gradio interface
23
  iface = gr.Interface(fn=generate_image, inputs="text", outputs="image")
24
 
25
  # Launch the Gradio interface
 
2
  from PIL import Image, ImageDraw
3
  import io
4
 
5
+ # Function to generate an image from a prompt
6
  def generate_image(prompt):
7
  try:
8
+ # Create a simple image with a blue background and text
9
  img = Image.new('RGB', (256, 256), color='blue')
10
  draw = ImageDraw.Draw(img)
11
  draw.text((10, 10), prompt, fill='white')
12
 
13
+ # Convert the PIL image to a format Gradio can use
14
  buffered = io.BytesIO()
15
  img.save(buffered, format="PNG")
16
  img_bytes = buffered.getvalue()
17
 
18
+ # Return the image as a PIL Image object for Gradio
19
+ return Image.open(io.BytesIO(img_bytes))
20
  except Exception as e:
21
  return f"Error: {e}"
22
 
23
+ # Create and launch the Gradio interface
24
  iface = gr.Interface(fn=generate_image, inputs="text", outputs="image")
25
 
26
  # Launch the Gradio interface