Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,23 +1,35 @@
|
|
| 1 |
import gradio as gr
|
| 2 |
-
from
|
| 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 |
-
#
|
| 9 |
-
|
| 10 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 11 |
|
| 12 |
-
# Create
|
| 13 |
interface = gr.Interface(
|
| 14 |
fn=generate_image,
|
| 15 |
inputs="text",
|
| 16 |
outputs="image",
|
| 17 |
-
title="Image Generator
|
| 18 |
-
description="Enter a
|
| 19 |
)
|
| 20 |
|
| 21 |
-
# Launch the Gradio
|
| 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()
|