Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,32 +1,22 @@
|
|
| 1 |
import gradio as gr
|
| 2 |
import os
|
| 3 |
|
| 4 |
-
#
|
| 5 |
-
|
| 6 |
-
|
| 7 |
-
# Cria o diret贸rio se n茫o existir
|
| 8 |
-
if not os.path.exists(IMAGE_DIR):
|
| 9 |
-
os.makedirs(IMAGE_DIR)
|
| 10 |
|
| 11 |
def save_image(image):
|
| 12 |
-
|
| 13 |
-
|
| 14 |
-
|
| 15 |
-
|
| 16 |
-
with open(image_path, "wb") as f:
|
| 17 |
-
f.write(image.read())
|
| 18 |
-
return f"Imagem salva em: {image_path}"
|
| 19 |
-
else:
|
| 20 |
-
return "Nenhuma imagem enviada."
|
| 21 |
|
| 22 |
-
# Interface
|
| 23 |
-
|
| 24 |
-
|
| 25 |
-
|
| 26 |
-
|
| 27 |
-
|
| 28 |
-
|
| 29 |
-
)
|
| 30 |
|
| 31 |
-
|
| 32 |
-
iface.launch()
|
|
|
|
| 1 |
import gradio as gr
|
| 2 |
import os
|
| 3 |
|
| 4 |
+
# Crie a pasta 'imagens' se ela n茫o existir
|
| 5 |
+
if not os.path.exists('imagens'):
|
| 6 |
+
os.makedirs('imagens')
|
|
|
|
|
|
|
|
|
|
| 7 |
|
| 8 |
def save_image(image):
|
| 9 |
+
image_name = image.name.split('/')[-1]
|
| 10 |
+
image_path = os.path.join('imagens', image_name)
|
| 11 |
+
image.save(image_path)
|
| 12 |
+
return f"Imagem salva em: {image_path}"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 13 |
|
| 14 |
+
# Interface Gradio
|
| 15 |
+
with gr.Blocks() as demo:
|
| 16 |
+
gr.Markdown("# Envie uma imagem")
|
| 17 |
+
file_input = gr.File(label="Selecione uma imagem", type="file")
|
| 18 |
+
output = gr.Textbox()
|
| 19 |
+
submit_btn = gr.Button("Enviar")
|
| 20 |
+
submit_btn.click(save_image, inputs=file_input, outputs=output)
|
|
|
|
| 21 |
|
| 22 |
+
demo.launch()
|
|
|