kainngo commited on
Commit
a9da66b
·
verified ·
1 Parent(s): 0ded2d3

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +24 -4
app.py CHANGED
@@ -1,7 +1,27 @@
1
  import gradio as gr
 
 
2
 
3
- def greet(name):
4
- return "Hello " + name + "!!"
 
 
 
 
5
 
6
- demo = gr.Interface(fn=greet, inputs="text", outputs="text")
7
- demo.launch()
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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()