jeffvedd commited on
Commit
4179614
·
verified ·
1 Parent(s): 51cb041

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +56 -0
app.py ADDED
@@ -0,0 +1,56 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import spaces
2
+ import torch
3
+ import gradio as gr
4
+ from diffusers import StableDiffusionXLPipeline
5
+
6
+ MODEL_REPO = "BinaryLight1011/Imageflow"
7
+
8
+ pipe = StableDiffusionXLPipeline.from_pretrained(
9
+ MODEL_REPO,
10
+ torch_dtype=torch.float16,
11
+ variant="fp16",
12
+ use_safetensors=True,
13
+ )
14
+ pipe.to("cuda")
15
+
16
+
17
+ @spaces.GPU(duration=60)
18
+ def generate(prompt, negative_prompt, width, height, guidance_scale, steps, seed):
19
+ generator = torch.Generator(device="cuda").manual_seed(int(seed))
20
+ image = pipe(
21
+ prompt=prompt,
22
+ negative_prompt=negative_prompt or None,
23
+ width=int(width),
24
+ height=int(height),
25
+ guidance_scale=float(guidance_scale),
26
+ num_inference_steps=int(steps),
27
+ generator=generator,
28
+ ).images[0]
29
+ return image
30
+
31
+
32
+ with gr.Blocks(title="Imageflow") as demo:
33
+ gr.Markdown("# 🖼️ Imageflow — Text-to-Image (SDXL)")
34
+
35
+ with gr.Row():
36
+ with gr.Column():
37
+ prompt = gr.Textbox(label="Prompt", lines=4, placeholder="Descreva a imagem...")
38
+ negative_prompt = gr.Textbox(label="Negative prompt (opcional)", lines=2)
39
+ with gr.Row():
40
+ width = gr.Slider(512, 1536, value=1024, step=64, label="Largura")
41
+ height = gr.Slider(512, 1536, value=1024, step=64, label="Altura")
42
+ guidance_scale = gr.Slider(1.0, 15.0, value=7.0, step=0.5, label="Guidance scale")
43
+ steps = gr.Slider(10, 100, value=30, step=5, label="Inference steps")
44
+ seed = gr.Number(value=42, label="Seed")
45
+ btn = gr.Button("Gerar imagem", variant="primary")
46
+
47
+ with gr.Column():
48
+ output_image = gr.Image(label="Resultado")
49
+
50
+ btn.click(
51
+ fn=generate,
52
+ inputs=[prompt, negative_prompt, width, height, guidance_scale, steps, seed],
53
+ outputs=output_image,
54
+ )
55
+
56
+ demo.launch()