Spaces:
Running
Running
File size: 1,566 Bytes
e33978f f6d49b6 e33978f f6d49b6 e33978f f6d49b6 e33978f f6d49b6 e33978f f6d49b6 e33978f f6d49b6 e33978f f6d49b6 e33978f |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 |
import gradio as gr
from diffusers import StableDiffusionPipeline
import torch
from PIL import Image
# Model nhỏ, chạy nhanh trên Hugging Face CPU
model_id = "segmind/tiny-sd"
pipe = StableDiffusionPipeline.from_pretrained(model_id, torch_dtype=torch.float32)
pipe = pipe.to("cpu")
# Hàm sinh ảnh
def generate_image(person_img, cloth_img, prompt):
# Nếu không có ảnh thì dùng prompt đơn thuần
full_prompt = "A person wearing fashionable clothes, high quality, realistic"
if prompt:
full_prompt += f", {prompt}"
# Nếu có ảnh nhân vật
if person_img:
full_prompt += ", base character reference provided"
# Nếu có ảnh quần áo
if cloth_img:
full_prompt += ", outfit reference provided"
# Sinh ảnh
image = pipe(full_prompt).images[0]
return image
# Giao diện
with gr.Blocks() as demo:
gr.Markdown("## 👗 AI Fashion Try-On (Tiny Model)")
gr.Markdown("Upload ảnh nhân vật + quần áo + nhập mô tả để thử phối đồ AI")
with gr.Row():
person = gr.Image(label="Ảnh nhân vật", type="pil")
cloth = gr.Image(label="Ảnh quần áo", type="pil")
prompt = gr.Textbox(label="Mô tả thêm (prompt)", placeholder="Ví dụ: phong cách streetwear, ảnh ngoài trời...")
output = gr.Image(label="Kết quả AI")
btn = gr.Button("✨ Tạo ảnh ngay")
btn.click(fn=generate_image, inputs=[person, cloth, prompt], outputs=output)
demo.launch()
|