Spaces:
Sleeping
Sleeping
Create app.py
Browse files
app.py
ADDED
|
@@ -0,0 +1,25 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import torch
|
| 2 |
+
import gradio as gr
|
| 3 |
+
from diffusers import StableDiffusionPipeline
|
| 4 |
+
|
| 5 |
+
# Load the Stable Diffusion model
|
| 6 |
+
model_id = "stabilityai/stable-diffusion-3-medium-diffusers"
|
| 7 |
+
pipeline = StableDiffusionPipeline.from_pretrained(model_id, torch_dtype=torch.float16)
|
| 8 |
+
pipeline.to("cuda") # Use GPU if available
|
| 9 |
+
|
| 10 |
+
def generate_image(prompt):
|
| 11 |
+
"""Generates an image based on user input text."""
|
| 12 |
+
image = pipeline(prompt).images[0]
|
| 13 |
+
return image
|
| 14 |
+
|
| 15 |
+
# Create a Gradio interface
|
| 16 |
+
demo = gr.Interface(
|
| 17 |
+
fn=generate_image,
|
| 18 |
+
inputs=gr.Textbox(placeholder="Enter a prompt for image generation..."),
|
| 19 |
+
outputs=gr.Image(type="pil"),
|
| 20 |
+
title="AI Image Chatbot",
|
| 21 |
+
description="Enter a text prompt, and the AI will generate an image based on it."
|
| 22 |
+
)
|
| 23 |
+
|
| 24 |
+
# Launch the application
|
| 25 |
+
demo.launch()
|