Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,19 +1,22 @@
|
|
| 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(
|
| 9 |
-
|
| 10 |
-
|
| 11 |
-
|
|
|
|
|
|
|
| 12 |
|
| 13 |
# Interface do Gradio
|
| 14 |
iface = gr.Interface(
|
| 15 |
fn=save_image,
|
| 16 |
-
inputs=gr.Image(type="
|
| 17 |
outputs="text",
|
| 18 |
title="Upload de Imagem",
|
| 19 |
description="Selecione uma imagem para enviar e obter a URL completa do arquivo salvo."
|
|
|
|
| 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(image_path):
|
| 10 |
+
image = Image.open(image_path)
|
| 11 |
+
image_name = os.path.basename(image_path)
|
| 12 |
+
saved_path = os.path.join('imagens', image_name)
|
| 13 |
+
image.save(saved_path)
|
| 14 |
+
return f"Imagem salva em: {os.path.abspath(saved_path)}"
|
| 15 |
|
| 16 |
# Interface do Gradio
|
| 17 |
iface = gr.Interface(
|
| 18 |
fn=save_image,
|
| 19 |
+
inputs=gr.Image(type="filepath", 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."
|