Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -1,18 +1,21 @@
|
|
1 |
import gradio as gr
|
2 |
import requests
|
|
|
|
|
3 |
|
4 |
# Função para gerar imagem usando a API do Hugging Face
|
5 |
def generate_image(prompt: str):
|
6 |
API_URL = "https://api-inference.huggingface.co/models/CompVis/stable-diffusion-v1-4"
|
7 |
-
headers = {"Authorization": "Bearer YOUR_HUGGINGFACE_API_KEY"}
|
8 |
|
9 |
response = requests.post(API_URL, headers=headers, json={"inputs": prompt})
|
10 |
|
11 |
if response.status_code == 200:
|
12 |
-
|
13 |
-
|
|
|
14 |
else:
|
15 |
-
|
16 |
|
17 |
# Função para criar a interface do Gradio
|
18 |
def gradio_interface():
|
|
|
1 |
import gradio as gr
|
2 |
import requests
|
3 |
+
from PIL import Image
|
4 |
+
from io import BytesIO
|
5 |
|
6 |
# Função para gerar imagem usando a API do Hugging Face
|
7 |
def generate_image(prompt: str):
|
8 |
API_URL = "https://api-inference.huggingface.co/models/CompVis/stable-diffusion-v1-4"
|
9 |
+
headers = {"Authorization": f"Bearer YOUR_HUGGINGFACE_API_KEY"}
|
10 |
|
11 |
response = requests.post(API_URL, headers=headers, json={"inputs": prompt})
|
12 |
|
13 |
if response.status_code == 200:
|
14 |
+
image_data = response.content
|
15 |
+
image = Image.open(BytesIO(image_data))
|
16 |
+
return image
|
17 |
else:
|
18 |
+
raise gr.Error(f"Erro ao gerar imagem: {response.status_code} - {response.text}")
|
19 |
|
20 |
# Função para criar a interface do Gradio
|
21 |
def gradio_interface():
|