Spaces:
Runtime error
Runtime error
ManMohanNayak
commited on
Commit
•
66fb69f
1
Parent(s):
eef888b
Create app.py
Browse files
app.py
ADDED
@@ -0,0 +1,42 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import gradio as gr
|
2 |
+
import os
|
3 |
+
|
4 |
+
UPLOAD_FOLDER = 'uploads'
|
5 |
+
if not os.path.exists(UPLOAD_FOLDER):
|
6 |
+
os.makedirs(UPLOAD_FOLDER)
|
7 |
+
|
8 |
+
def upload_file(file):
|
9 |
+
if file is None:
|
10 |
+
return "No file uploaded"
|
11 |
+
file_name = file.name
|
12 |
+
file_path = os.path.join(UPLOAD_FOLDER, file_name)
|
13 |
+
with open(file_path, "wb") as f:
|
14 |
+
f.write(file.read())
|
15 |
+
return f"File uploaded successfully: {file_name}"
|
16 |
+
|
17 |
+
def list_files():
|
18 |
+
files = os.listdir(UPLOAD_FOLDER)
|
19 |
+
return files
|
20 |
+
|
21 |
+
def delete_file(file_name):
|
22 |
+
file_path = os.path.join(UPLOAD_FOLDER, file_name)
|
23 |
+
if os.path.exists(file_path):
|
24 |
+
os.remove(file_path)
|
25 |
+
return f"File deleted successfully: {file_name}"
|
26 |
+
else:
|
27 |
+
return "File not found"
|
28 |
+
|
29 |
+
# Define Gradio interface
|
30 |
+
with gr.Blocks() as demo:
|
31 |
+
with gr.Row():
|
32 |
+
upload = gr.File(label="Upload File")
|
33 |
+
upload_btn = gr.Button("Upload")
|
34 |
+
upload_output = gr.Textbox(label="Upload Status")
|
35 |
+
upload_btn.click(upload_file, inputs=upload, outputs=upload_output)
|
36 |
+
|
37 |
+
with gr.Row():
|
38 |
+
list_btn = gr.Button("List Files")
|
39 |
+
list_output = gr.Textbox(label="Files List")
|
40 |
+
list_btn.click(list_files, outputs=list_output)
|
41 |
+
|
42 |
+
|