Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,7 +1,27 @@
|
|
| 1 |
import gradio as gr
|
|
|
|
|
|
|
| 2 |
|
| 3 |
-
|
| 4 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 5 |
|
| 6 |
-
|
| 7 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
import gradio as gr
|
| 2 |
+
import torch
|
| 3 |
+
from diffusers import StableDiffusionPipeline
|
| 4 |
|
| 5 |
+
# Tải model SD 1.5 từ HuggingFace (chỉ cần tải lần đầu)
|
| 6 |
+
pipe = StableDiffusionPipeline.from_pretrained(
|
| 7 |
+
"runwayml/stable-diffusion-v1-5",
|
| 8 |
+
torch_dtype=torch.float16 if torch.cuda.is_available() else torch.float32,
|
| 9 |
+
)
|
| 10 |
+
pipe = pipe.to("cuda" if torch.cuda.is_available() else "cpu")
|
| 11 |
|
| 12 |
+
def generate_image(prompt, negative_prompt):
|
| 13 |
+
image = pipe(prompt=prompt, negative_prompt=negative_prompt, guidance_scale=7.5).images[0]
|
| 14 |
+
return image
|
| 15 |
+
|
| 16 |
+
demo = gr.Interface(
|
| 17 |
+
fn=generate_image,
|
| 18 |
+
inputs=[
|
| 19 |
+
gr.Textbox(label="Prompt", placeholder="Nhập mô tả cảnh bạn muốn tạo..."),
|
| 20 |
+
gr.Textbox(label="Negative Prompt", placeholder="Không muốn có gì trong ảnh? (optional)"),
|
| 21 |
+
],
|
| 22 |
+
outputs=gr.Image(type="pil"),
|
| 23 |
+
title="🖼️ Prompt-to-Image Generator",
|
| 24 |
+
description="Nhập prompt → gen ảnh từ AI (dùng SD1.5 - chạy được cả trên iPhone/laptop)."
|
| 25 |
+
)
|
| 26 |
+
|
| 27 |
+
demo.launch()
|