Create app.py
Browse files
app.py
ADDED
|
@@ -0,0 +1,34 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import gradio as gr
|
| 2 |
+
import os
|
| 3 |
+
|
| 4 |
+
# Função para lidar com o upload de arquivos
|
| 5 |
+
def upload_files(files):
|
| 6 |
+
file_paths = []
|
| 7 |
+
for file in files:
|
| 8 |
+
file_paths.append(file.name) # Salva o caminho do arquivo
|
| 9 |
+
return file_paths
|
| 10 |
+
|
| 11 |
+
# Função para exibir os arquivos
|
| 12 |
+
def display_files(file_paths):
|
| 13 |
+
if not file_paths:
|
| 14 |
+
return "Nenhum arquivo enviado ainda."
|
| 15 |
+
file_list = "<ul>"
|
| 16 |
+
for path in file_paths:
|
| 17 |
+
file_name = os.path.basename(path)
|
| 18 |
+
file_list += f'<li><a href="{path}" download="{file_name}">{file_name}</a></li>'
|
| 19 |
+
file_list += "</ul>"
|
| 20 |
+
return file_list
|
| 21 |
+
|
| 22 |
+
# Interface Gradio
|
| 23 |
+
with gr.Blocks() as demo:
|
| 24 |
+
with gr.Row():
|
| 25 |
+
with gr.Column():
|
| 26 |
+
file_input = gr.File(label="Envie seus arquivos", file_count="multiple")
|
| 27 |
+
upload_button = gr.Button("Enviar")
|
| 28 |
+
with gr.Column():
|
| 29 |
+
file_output = gr.HTML(label="Arquivos Disponíveis para Download")
|
| 30 |
+
|
| 31 |
+
upload_button.click(fn=upload_files, inputs=file_input, outputs=file_output)
|
| 32 |
+
file_input.change(fn=display_files, inputs=file_input, outputs=file_output)
|
| 33 |
+
|
| 34 |
+
demo.launch()
|