Spaces:
Sleeping
Sleeping
Create app.py
Browse files
app.py
ADDED
|
@@ -0,0 +1,24 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import gradio as gr
|
| 2 |
+
import shutil
|
| 3 |
+
import os
|
| 4 |
+
|
| 5 |
+
# Define onde salvar (pasta temporária)
|
| 6 |
+
def upload_file(file):
|
| 7 |
+
if not file:
|
| 8 |
+
return None
|
| 9 |
+
|
| 10 |
+
# O Gradio recebe o arquivo num caminho temporário
|
| 11 |
+
# Vamos mover para uma pasta pública estática se necessário,
|
| 12 |
+
# mas o próprio Gradio já gera um link acessível via /file/
|
| 13 |
+
return file.name # Retorna o caminho absoluto do arquivo no servidor
|
| 14 |
+
|
| 15 |
+
# Cria uma interface API (sem interface visual pesada)
|
| 16 |
+
with gr.Blocks() as demo:
|
| 17 |
+
# Um componente invisível apenas para receber o arquivo
|
| 18 |
+
file_input = gr.File()
|
| 19 |
+
output_text = gr.Textbox()
|
| 20 |
+
|
| 21 |
+
# Quando o arquivo sobe, retorna o caminho
|
| 22 |
+
file_input.upload(upload_file, file_input, output_text)
|
| 23 |
+
|
| 24 |
+
demo.launch()
|