Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,24 +1,23 @@
|
|
| 1 |
import gradio as gr
|
| 2 |
-
import shutil
|
| 3 |
import os
|
| 4 |
|
| 5 |
-
|
| 6 |
-
|
| 7 |
-
|
| 8 |
-
# Garantir que o diret贸rio de uploads exista
|
| 9 |
-
os.makedirs("uploads", exist_ok=True)
|
| 10 |
-
# Salvar o arquivo
|
| 11 |
-
with open(save_path, "wb") as f:
|
| 12 |
-
shutil.copyfileobj(file.file, f)
|
| 13 |
-
# Retornar a URL do arquivo
|
| 14 |
-
return f"files/{file.name}"
|
| 15 |
|
| 16 |
-
|
| 17 |
-
|
| 18 |
-
|
| 19 |
-
|
| 20 |
-
|
| 21 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 22 |
)
|
| 23 |
|
| 24 |
-
|
|
|
|
|
|
| 1 |
import gradio as gr
|
|
|
|
| 2 |
import os
|
| 3 |
|
| 4 |
+
# Cria a pasta 'imagens' se n茫o existir
|
| 5 |
+
if not os.path.exists('imagens'):
|
| 6 |
+
os.makedirs('imagens')
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 7 |
|
| 8 |
+
def save_image(image):
|
| 9 |
+
image_path = os.path.join('imagens', image.name)
|
| 10 |
+
image.save(image_path)
|
| 11 |
+
return f"Imagem salva em: {os.path.abspath(image_path)}"
|
| 12 |
+
|
| 13 |
+
# Interface do Gradio
|
| 14 |
+
iface = gr.Interface(
|
| 15 |
+
fn=save_image,
|
| 16 |
+
inputs=gr.inputs.Image(type="file", label="Selecione uma imagem"),
|
| 17 |
+
outputs="text",
|
| 18 |
+
title="Upload de Imagem",
|
| 19 |
+
description="Selecione uma imagem para enviar e obter a URL completa do arquivo salvo."
|
| 20 |
)
|
| 21 |
|
| 22 |
+
if __name__ == "__main__":
|
| 23 |
+
iface.launch()
|