File size: 1,157 Bytes
58126da
b8ec2f8
58126da
b8ec2f8
 
 
 
58126da
b8ec2f8
bfd543d
b8ec2f8
 
 
 
 
bfd543d
b8ec2f8
bfd543d
b8ec2f8
 
bfd543d
 
 
 
 
 
 
 
b8ec2f8
 
bfd543d
 
 
 
d8e57d4
 
bfd543d
 
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
import gradio as gr
import requests

# Função para gerar imagem usando a API do Hugging Face
def generate_image(prompt: str):
    API_URL = "https://api-inference.huggingface.co/models/CompVis/stable-diffusion-v1-4"
    headers = {"Authorization": "Bearer YOUR_HUGGINGFACE_API_KEY"}

    response = requests.post(API_URL, headers=headers, json={"inputs": prompt})

    if response.status_code == 200:
        image_url = response.json()
        return image_url
    else:
        return None

# Função para criar a interface do Gradio
def gradio_interface():
    with gr.Blocks() as demo:
        gr.Markdown("## Gere imagens usando Stable Diffusion")
        with gr.Row():
            with gr.Column():
                prompt = gr.Textbox(label="Prompt", placeholder="Digite o prompt aqui...")
                run_button = gr.Button("Gerar Imagem")
            with gr.Column():
                result = gr.Image(label="Imagem Gerada")

        run_button.click(
            fn=generate_image,
            inputs=prompt,
            outputs=result,
        )

    return demo

if __name__ == "__main__":
    demo = gradio_interface()
    demo.launch()