Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,26 +1,32 @@
|
|
| 1 |
import gradio as gr
|
| 2 |
import os
|
| 3 |
|
| 4 |
-
#
|
| 5 |
-
|
| 6 |
-
|
|
|
|
|
|
|
|
|
|
| 7 |
|
| 8 |
def save_image(image):
|
| 9 |
-
|
| 10 |
-
|
| 11 |
-
|
| 12 |
-
|
| 13 |
-
|
| 14 |
-
|
|
|
|
|
|
|
|
|
|
| 15 |
|
| 16 |
# Interface do Gradio
|
| 17 |
iface = gr.Interface(
|
| 18 |
-
fn=save_image,
|
| 19 |
-
inputs=gr.File(label="Selecione uma imagem"),
|
| 20 |
outputs="text",
|
| 21 |
title="Upload de Imagem",
|
| 22 |
-
description="
|
| 23 |
)
|
| 24 |
|
| 25 |
if __name__ == "__main__":
|
| 26 |
-
iface.launch(
|
|
|
|
| 1 |
import gradio as gr
|
| 2 |
import os
|
| 3 |
|
| 4 |
+
# Diret贸rio onde as imagens ser茫o salvas
|
| 5 |
+
IMAGE_DIR = "imagens"
|
| 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 |
+
if image:
|
| 13 |
+
# Define o caminho completo para salvar a imagem
|
| 14 |
+
image_path = os.path.join(IMAGE_DIR, image.name)
|
| 15 |
+
# Salva a imagem no diret贸rio especificado
|
| 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 do Gradio
|
| 23 |
iface = gr.Interface(
|
| 24 |
+
fn=save_image,
|
| 25 |
+
inputs=gr.inputs.File(label="Selecione uma imagem"),
|
| 26 |
outputs="text",
|
| 27 |
title="Upload de Imagem",
|
| 28 |
+
description="Envie uma imagem e ela ser谩 salva na pasta 'imagens'."
|
| 29 |
)
|
| 30 |
|
| 31 |
if __name__ == "__main__":
|
| 32 |
+
iface.launch()
|