Spaces:
Sleeping
Sleeping
Delete app.py
Browse files
app.py
DELETED
@@ -1,48 +0,0 @@
|
|
1 |
-
import os
|
2 |
-
import uuid
|
3 |
-
import gradio as gr
|
4 |
-
import torch
|
5 |
-
from PIL import Image
|
6 |
-
from diffusers import StableDiffusionXLPipeline, EulerAncestralDiscreteScheduler
|
7 |
-
|
8 |
-
# Configuração do modelo e pipeline
|
9 |
-
model_id = "stabilityai/stable-diffusion-xl-base-1.0"
|
10 |
-
|
11 |
-
# Carrega o pipeline do modelo
|
12 |
-
scheduler = EulerAncestralDiscreteScheduler.from_pretrained(model_id, subfolder="scheduler")
|
13 |
-
pipe = StableDiffusionXLPipeline.from_pretrained(model_id, scheduler=scheduler, torch_dtype=torch.float16)
|
14 |
-
pipe.to("cuda") # Usa GPU para acelerar o processamento
|
15 |
-
|
16 |
-
# Função para geração de imagens
|
17 |
-
def generate_image(prompt: str, height: int = 576, width: int = 1024, seed: int = None) -> Image.Image:
|
18 |
-
if not seed:
|
19 |
-
seed = random.randint(0, 99999)
|
20 |
-
|
21 |
-
# Configurar seed para reprodutibilidade
|
22 |
-
generator = torch.manual_seed(seed)
|
23 |
-
|
24 |
-
# Gerar a imagem
|
25 |
-
image = pipe(prompt, height=height, width=width, num_inference_steps=50, guidance_scale=7.5, generator=generator).images[0]
|
26 |
-
|
27 |
-
# Retorna a imagem gerada
|
28 |
-
return image
|
29 |
-
|
30 |
-
# Interface Gradio
|
31 |
-
with gr.Blocks() as demo:
|
32 |
-
gr.Markdown("## Gerador de Imagens com Stable Diffusion XL")
|
33 |
-
|
34 |
-
with gr.Row():
|
35 |
-
with gr.Column():
|
36 |
-
prompt = gr.Textbox(label="Texto (Prompt)", placeholder="Descreva a imagem que deseja gerar...")
|
37 |
-
seed = gr.Number(label="Seed (opcional)", value=None)
|
38 |
-
generate_button = gr.Button("Gerar Imagem")
|
39 |
-
|
40 |
-
with gr.Column():
|
41 |
-
output_image = gr.Image(label="Imagem Gerada", type="pil")
|
42 |
-
|
43 |
-
# Conectar botão à função
|
44 |
-
generate_button.click(fn=generate_image, inputs=[prompt, gr.Number(value=576), gr.Number(value=1024), seed], outputs=output_image)
|
45 |
-
|
46 |
-
# Executar o app
|
47 |
-
if __name__ == "__main__":
|
48 |
-
demo.launch(server_name="0.0.0.0", server_port=7860)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|