Spaces:
Sleeping
Sleeping
Commit
·
9ff6901
1
Parent(s):
31c8db9
Subindo arquivos53
Browse files
app.py
CHANGED
@@ -1,43 +1,37 @@
|
|
1 |
import gradio as gr
|
2 |
from PIL import Image
|
|
|
3 |
import numpy as np
|
4 |
import tempfile
|
5 |
-
import os
|
6 |
|
7 |
def muda_dpi(input_image, dpi):
|
8 |
-
if input_image is None:
|
9 |
-
return "No image provided"
|
10 |
-
|
11 |
dpi_tuple = (dpi, dpi)
|
12 |
|
13 |
-
# Converte a imagem de entrada em um formato compatível com PIL
|
14 |
image = Image.fromarray(input_image.astype('uint8'), 'RGB')
|
15 |
|
16 |
-
|
17 |
temp_file = tempfile.NamedTemporaryFile(delete=False, suffix='.png')
|
18 |
image.save(temp_file, format='PNG', dpi=dpi_tuple)
|
19 |
temp_file.close()
|
20 |
|
|
|
21 |
return temp_file.name
|
22 |
|
23 |
-
#
|
24 |
-
example_image_path = "example1.jpg"
|
25 |
-
|
26 |
-
# Verifica se a imagem de exemplo existe no caminho especificado
|
27 |
-
if not os.path.exists(example_image_path):
|
28 |
-
raise FileNotFoundError(f"O arquivo de exemplo {example_image_path} não foi encontrado.")
|
29 |
-
|
30 |
-
# Configurar a interface Gradio
|
31 |
iface = gr.Interface(
|
32 |
fn=muda_dpi,
|
33 |
inputs=[
|
34 |
gr.Image(label="Upload"),
|
35 |
gr.Number(label="Ajusta DPI", value=300)
|
36 |
],
|
37 |
-
outputs=gr.File(label="Download"),
|
38 |
title="Conversor DPI",
|
39 |
description="Faça o upload da imagem (.jpg, .png), ajuste o DPI e submeta",
|
40 |
-
examples=[
|
|
|
|
|
41 |
)
|
42 |
|
|
|
43 |
iface.launch(debug=True)
|
|
|
|
1 |
import gradio as gr
|
2 |
from PIL import Image
|
3 |
+
import io
|
4 |
import numpy as np
|
5 |
import tempfile
|
|
|
6 |
|
7 |
def muda_dpi(input_image, dpi):
|
|
|
|
|
|
|
8 |
dpi_tuple = (dpi, dpi)
|
9 |
|
|
|
10 |
image = Image.fromarray(input_image.astype('uint8'), 'RGB')
|
11 |
|
12 |
+
|
13 |
temp_file = tempfile.NamedTemporaryFile(delete=False, suffix='.png')
|
14 |
image.save(temp_file, format='PNG', dpi=dpi_tuple)
|
15 |
temp_file.close()
|
16 |
|
17 |
+
|
18 |
return temp_file.name
|
19 |
|
20 |
+
#teste
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
21 |
iface = gr.Interface(
|
22 |
fn=muda_dpi,
|
23 |
inputs=[
|
24 |
gr.Image(label="Upload"),
|
25 |
gr.Number(label="Ajusta DPI", value=300)
|
26 |
],
|
27 |
+
outputs=[gr.File(label="Download")],
|
28 |
title="Conversor DPI",
|
29 |
description="Faça o upload da imagem (.jpg, .png), ajuste o DPI e submeta",
|
30 |
+
examples=[
|
31 |
+
["example1.JPG"]
|
32 |
+
]
|
33 |
)
|
34 |
|
35 |
+
|
36 |
iface.launch(debug=True)
|
37 |
+
|