Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -5,6 +5,14 @@ import shutil
|
|
| 5 |
# Defina o nome do seu Hugging Face Space
|
| 6 |
SPACE_NAME = "seu-nome-de-usuario/seu-nome-do-space"
|
| 7 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 8 |
# Crie a pasta 'imagens' se ela não existir
|
| 9 |
if not os.path.exists('imagens'):
|
| 10 |
os.makedirs('imagens')
|
|
@@ -13,6 +21,27 @@ def save_image(image_path):
|
|
| 13 |
image_name = os.path.basename(image_path)
|
| 14 |
target_path = os.path.join('imagens', image_name)
|
| 15 |
shutil.move(image_path, target_path)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 16 |
|
| 17 |
# Gera a URL completa
|
| 18 |
url = f"https://{SPACE_NAME}.hf.space/imagens/{image_name}"
|
|
|
|
| 5 |
# Defina o nome do seu Hugging Face Space
|
| 6 |
SPACE_NAME = "seu-nome-de-usuario/seu-nome-do-space"
|
| 7 |
|
| 8 |
+
# Crie a pasta 'imagens' se ela não existir
|
| 9 |
+
if not os.path.exists('imagens'):
|
| 10 |
+
os.makedirs('imagens')
|
| 11 |
+
|
| 12 |
+
def save_image(image_path):import gradio as gr
|
| 13 |
+
import os
|
| 14 |
+
import shutil
|
| 15 |
+
|
| 16 |
# Crie a pasta 'imagens' se ela não existir
|
| 17 |
if not os.path.exists('imagens'):
|
| 18 |
os.makedirs('imagens')
|
|
|
|
| 21 |
image_name = os.path.basename(image_path)
|
| 22 |
target_path = os.path.join('imagens', image_name)
|
| 23 |
shutil.move(image_path, target_path)
|
| 24 |
+
url = f"https://13ze-cs.hf.space/file/13ze-cs/imagens/{image_name}"
|
| 25 |
+
return target_path, url
|
| 26 |
+
|
| 27 |
+
def display_image(image_path):
|
| 28 |
+
return image_path
|
| 29 |
+
|
| 30 |
+
# Interface Gradio
|
| 31 |
+
with gr.Blocks() as demo:
|
| 32 |
+
gr.Markdown("# Envie uma imagem")
|
| 33 |
+
file_input = gr.File(label="Selecione uma imagem", type="filepath")
|
| 34 |
+
image_output = gr.Image()
|
| 35 |
+
url_output = gr.Textbox()
|
| 36 |
+
submit_btn = gr.Button("Enviar")
|
| 37 |
+
|
| 38 |
+
submit_btn.click(save_image, inputs=file_input, outputs=[image_output, url_output])
|
| 39 |
+
|
| 40 |
+
demo.launch()
|
| 41 |
+
|
| 42 |
+
image_name = os.path.basename(image_path)
|
| 43 |
+
target_path = os.path.join('imagens', image_name)
|
| 44 |
+
shutil.move(image_path, target_path)
|
| 45 |
|
| 46 |
# Gera a URL completa
|
| 47 |
url = f"https://{SPACE_NAME}.hf.space/imagens/{image_name}"
|