Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,26 +1,26 @@
|
|
| 1 |
import gradio as gr
|
| 2 |
import os
|
| 3 |
-
from PIL import Image
|
| 4 |
|
| 5 |
# Cria a pasta 'imagens' se não existir
|
| 6 |
if not os.path.exists('imagens'):
|
| 7 |
os.makedirs('imagens')
|
| 8 |
|
| 9 |
-
def save_image(
|
| 10 |
-
|
| 11 |
-
|
| 12 |
-
|
| 13 |
-
|
| 14 |
-
|
|
|
|
| 15 |
|
| 16 |
# Interface do Gradio
|
| 17 |
iface = gr.Interface(
|
| 18 |
fn=save_image,
|
| 19 |
-
inputs=gr.
|
| 20 |
outputs="text",
|
| 21 |
title="Upload de Imagem",
|
| 22 |
description="Selecione uma imagem para enviar e obter a URL completa do arquivo salvo."
|
| 23 |
)
|
| 24 |
|
| 25 |
if __name__ == "__main__":
|
| 26 |
-
iface.launch()
|
|
|
|
| 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_name = image.name
|
| 10 |
+
image_path = os.path.join('imagens', image_name)
|
| 11 |
+
with open(image_path, 'wb') as f:
|
| 12 |
+
f.write(image.read())
|
| 13 |
+
full_url = f"{os.getcwd()}/imagens/{image_name}"
|
| 14 |
+
return f"Imagem salva em: {full_url}"
|
| 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="Selecione uma imagem para enviar e obter a URL completa do arquivo salvo."
|
| 23 |
)
|
| 24 |
|
| 25 |
if __name__ == "__main__":
|
| 26 |
+
iface.launch(server_name="0.0.0.0")
|