Spaces:
Sleeping
Sleeping
Create app.py
Browse files
app.py
ADDED
|
@@ -0,0 +1,56 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import gradio as gr
|
| 2 |
+
import torch
|
| 3 |
+
from diffusers import StableDiffusionPipeline
|
| 4 |
+
|
| 5 |
+
# Load model
|
| 6 |
+
print("Loading model...")
|
| 7 |
+
pipe = StableDiffusionPipeline.from_pretrained(
|
| 8 |
+
"runwayml/stable-diffusion-v1-5",
|
| 9 |
+
torch_dtype=torch.float16 if torch.cuda.is_available() else torch.float32,
|
| 10 |
+
safety_checker=None
|
| 11 |
+
)
|
| 12 |
+
|
| 13 |
+
# Load YOUR LoRA weights
|
| 14 |
+
pipe.load_lora_weights("ozzyzoz123/indian-clothing-lora")
|
| 15 |
+
|
| 16 |
+
# Move to GPU if available
|
| 17 |
+
device = "cuda" if torch.cuda.is_available() else "cpu"
|
| 18 |
+
pipe = pipe.to(device)
|
| 19 |
+
print(f"Model loaded on {device}")
|
| 20 |
+
|
| 21 |
+
# Generation function
|
| 22 |
+
def generate(prompt, negative_prompt, steps, guidance_scale):
|
| 23 |
+
image = pipe(
|
| 24 |
+
prompt=prompt,
|
| 25 |
+
negative_prompt=negative_prompt,
|
| 26 |
+
num_inference_steps=int(steps),
|
| 27 |
+
guidance_scale=guidance_scale
|
| 28 |
+
).images[0]
|
| 29 |
+
return image
|
| 30 |
+
|
| 31 |
+
# Gradio Interface
|
| 32 |
+
demo = gr.Interface(
|
| 33 |
+
fn=generate,
|
| 34 |
+
inputs=[
|
| 35 |
+
gr.Textbox(
|
| 36 |
+
label="Prompt",
|
| 37 |
+
value="product photo of Indian Saree, black background, no person, studio shot"
|
| 38 |
+
),
|
| 39 |
+
gr.Textbox(
|
| 40 |
+
label="Negative Prompt",
|
| 41 |
+
value="human face, person, human body, skin texture, portrait"
|
| 42 |
+
),
|
| 43 |
+
gr.Slider(10, 50, value=30, step=1, label="Steps"),
|
| 44 |
+
gr.Slider(1, 15, value=7.5, step=0.5, label="Guidance Scale"),
|
| 45 |
+
],
|
| 46 |
+
outputs=gr.Image(label="Generated Image"),
|
| 47 |
+
title="🇮🇳 Indian Clothing Generator",
|
| 48 |
+
description="Generate product photos of Indian clothing (Saree, Kurta, Shirt, Jacket, T-shirt)",
|
| 49 |
+
examples=[
|
| 50 |
+
["product photo of Indian Saree, black background, no person", "human face, person", 30, 7.5],
|
| 51 |
+
["product photo of Indian Kurta, black background, no person", "human face, person", 30, 7.5],
|
| 52 |
+
["product photo of Indian Jacket, black background, no person", "human face, person", 30, 7.5],
|
| 53 |
+
]
|
| 54 |
+
)
|
| 55 |
+
|
| 56 |
+
demo.launch()
|