Spaces:
Sleeping
Sleeping
Create app.py
Browse files
app.py
ADDED
|
@@ -0,0 +1,23 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import gradio as gr
|
| 2 |
+
from diffusers import StableDiffusionPipeline
|
| 3 |
+
import torch
|
| 4 |
+
|
| 5 |
+
# Load your fine-tuned model from Hugging Face
|
| 6 |
+
model_id = "your-username/stable-diffusion-finetuned" # Replace with your model ID on HF
|
| 7 |
+
pipe = StableDiffusionPipeline.from_pretrained(model_id, torch_dtype=torch.float16)
|
| 8 |
+
pipe.to("cuda")
|
| 9 |
+
|
| 10 |
+
# Define the function for text-to-image generation
|
| 11 |
+
def generate_image(prompt):
|
| 12 |
+
image = pipe(prompt).images[0]
|
| 13 |
+
return image
|
| 14 |
+
|
| 15 |
+
# Create a Gradio interface
|
| 16 |
+
interface = gr.Interface(
|
| 17 |
+
fn=generate_image,
|
| 18 |
+
inputs=gr.Textbox(label="Enter your prompt"),
|
| 19 |
+
outputs=gr.Image(label="Generated Image"),
|
| 20 |
+
)
|
| 21 |
+
|
| 22 |
+
# Launch the interface
|
| 23 |
+
interface.launch()
|