dschandra commited on
Commit
6b2bc5d
·
verified ·
1 Parent(s): 67d4737

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +23 -11
app.py CHANGED
@@ -1,23 +1,35 @@
1
  import gradio as gr
2
- from transformers import pipeline
3
-
4
- # Load the text-to-image pipeline from Hugging Face
5
- generator = pipeline('text-to-image', model="CompVis/stable-diffusion-v1-4")
6
 
 
7
  def generate_image(description):
8
- # Generate the image based on the description
9
- image = generator(description)
10
- return image[0]['image']
 
 
 
 
 
 
 
 
 
 
 
 
 
 
11
 
12
- # Create the Gradio interface
13
  interface = gr.Interface(
14
  fn=generate_image,
15
  inputs="text",
16
  outputs="image",
17
- title="Image Generator from Description",
18
- description="Enter a text description and generate an image based on it."
19
  )
20
 
21
- # Launch the Gradio interface
22
  if __name__ == "__main__":
23
  interface.launch()
 
1
  import gradio as gr
2
+ from PIL import Image, ImageDraw, ImageFont
 
 
 
3
 
4
+ # Function to generate a simple image based on description
5
  def generate_image(description):
6
+ # Create a blank white canvas of 300x300 pixels
7
+ img = Image.new('RGB', (300, 300), color=(255, 255, 255))
8
+
9
+ # Create an ImageDraw object to add shapes and text
10
+ draw = ImageDraw.Draw(img)
11
+
12
+ # Check for specific keywords in the description
13
+ if "circle" in description.lower():
14
+ # Draw a blue circle
15
+ draw.ellipse([(50, 50), (250, 250)], fill="blue", outline="black")
16
+
17
+ # Add the description text on the image
18
+ font = ImageFont.load_default()
19
+ draw.text((60, 260), description, fill="black", font=font)
20
+
21
+ # Return the generated image
22
+ return img
23
 
24
+ # Create a Gradio interface
25
  interface = gr.Interface(
26
  fn=generate_image,
27
  inputs="text",
28
  outputs="image",
29
+ title="Simple Text-to-Image Generator",
30
+ description="Enter a description, and the app will generate an image based on it. For example, try 'circle'."
31
  )
32
 
33
+ # Launch the Gradio app
34
  if __name__ == "__main__":
35
  interface.launch()