onnew commited on
Commit
d953bca
·
verified ·
1 Parent(s): b5ee36a

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +33 -44
app.py CHANGED
@@ -1,44 +1,33 @@
1
- import gradio as gr
2
- import requests
3
- from PIL import Image
4
- from io import BytesIO
5
-
6
- # Substitua 'YOUR_HUGGINGFACE_API_KEY' pela sua chave de API real
7
- API_KEY = "YOUR_HUGGINGFACE_API_KEY"
8
-
9
- # Função para gerar imagem usando a API do Hugging Face
10
- def generate_image(prompt: str):
11
- API_URL = "https://api-inference.huggingface.co/models/CompVis/stable-diffusion-v1-4"
12
- headers = {"Authorization": f"Bearer {API_KEY}"}
13
-
14
- response = requests.post(API_URL, headers=headers, json={"inputs": prompt})
15
-
16
- if response.status_code == 200:
17
- image_data = response.content
18
- image = Image.open(BytesIO(image_data))
19
- return image
20
- else:
21
- raise gr.Error(f"Erro ao gerar imagem: {response.status_code} - {response.text}")
22
-
23
- # Função para criar a interface do Gradio
24
- def gradio_interface():
25
- with gr.Blocks() as demo:
26
- gr.Markdown("## Gere imagens usando Stable Diffusion")
27
- with gr.Row():
28
- with gr.Column():
29
- prompt = gr.Textbox(label="Prompt", placeholder="Digite o prompt aqui...")
30
- run_button = gr.Button("Gerar Imagem")
31
- with gr.Column():
32
- result = gr.Image(label="Imagem Gerada")
33
-
34
- run_button.click(
35
- fn=generate_image,
36
- inputs=prompt,
37
- outputs=result,
38
- )
39
-
40
- return demo
41
-
42
- if __name__ == "__main__":
43
- demo = gradio_interface()
44
- demo.launch()
 
1
+ from PIL import Image, ImageDraw, ImageFont
2
+
3
+ # Dimensões da imagem
4
+ width, height = 576, 1024
5
+
6
+ # Criar uma imagem branca
7
+ image = Image.new('RGB', (width, height), color='white')
8
+
9
+ # Criar um objeto de desenho
10
+ draw = ImageDraw.Draw(image)
11
+
12
+ # Carregar uma fonte (certifique-se de que a fonte está disponível no seu sistema)
13
+ try:
14
+ font = ImageFont.truetype("arial.ttf", 40)
15
+ except IOError:
16
+ font = ImageFont.load_default()
17
+
18
+ # Texto a ser adicionado à imagem
19
+ text = "Este é um exemplo de texto em uma imagem."
20
+
21
+ # Calcular a posição do texto para centralizá-lo
22
+ text_width, text_height = draw.textsize(text, font=font)
23
+ text_x = (width - text_width) / 2
24
+ text_y = (height - text_height) / 2
25
+
26
+ # Adicionar texto à imagem
27
+ draw.text((text_x, text_y), text, font=font, fill='black')
28
+
29
+ # Salvar a imagem
30
+ image.save('text_image.png')
31
+
32
+ # Exibir a imagem
33
+ image.show()