13ze commited on
Commit
52b8a33
verified
1 Parent(s): e0b5df0

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +17 -18
app.py CHANGED
@@ -1,24 +1,23 @@
1
  import gradio as gr
2
- import shutil
3
  import os
4
 
5
- def upload_file(file):
6
- # Definir o caminho para salvar o arquivo
7
- save_path = os.path.join("uploads", file.name)
8
- # Garantir que o diret贸rio de uploads exista
9
- os.makedirs("uploads", exist_ok=True)
10
- # Salvar o arquivo
11
- with open(save_path, "wb") as f:
12
- shutil.copyfileobj(file.file, f)
13
- # Retornar a URL do arquivo
14
- return f"files/{file.name}"
15
 
16
- interface = gr.Interface(
17
- fn=upload_file,
18
- inputs=gr.File(label="Upload a file"),
19
- outputs=gr.Textbox(label="File URL"),
20
- title="File Upload and URL Generator",
21
- description="Upload a file and get a URL to access it."
 
 
 
 
 
 
22
  )
23
 
24
- interface.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_path = os.path.join('imagens', image.name)
10
+ image.save(image_path)
11
+ return f"Imagem salva em: {os.path.abspath(image_path)}"
12
+
13
+ # Interface do Gradio
14
+ iface = gr.Interface(
15
+ fn=save_image,
16
+ inputs=gr.inputs.Image(type="file", label="Selecione uma imagem"),
17
+ outputs="text",
18
+ title="Upload de Imagem",
19
+ description="Selecione uma imagem para enviar e obter a URL completa do arquivo salvo."
20
  )
21
 
22
+ if __name__ == "__main__":
23
+ iface.launch()