File size: 1,623 Bytes
1c3157b 86cc22a 71724d5 86cc22a 71724d5 86cc22a 71724d5 19ec90f 71724d5 19ec90f 71724d5 19ec90f 71724d5 19ec90f 71724d5 86cc22a 71724d5 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 | import os
import gradio as gr
def list_files():
result = {}
# Check /data
try:
result["/data"] = os.listdir("/data")
except Exception as e:
result["/data"] = str(e)
# Check /1
try:
result["/1"] = os.listdir("/1")
except Exception as e:
result["/1"] = str(e)
return result
def upload_file(file):
import os
responses = {}
filename = os.path.basename(file.name) # ✅ FIX
# Try writing to /data
try:
path_data = f"/data/{filename}"
with open(file.name, "rb") as src:
with open(path_data, "wb") as dst:
dst.write(src.read())
responses["/data"] = f"Uploaded to {path_data}"
except Exception as e:
responses["/data"] = f"Failed: {str(e)}"
# Try writing to /1
try:
os.makedirs("/1", exist_ok=True) # ensure folder exists
path_1 = f"/1/{filename}"
with open(file.name, "rb") as src:
with open(path_1, "wb") as dst:
dst.write(src.read())
responses["/1"] = f"Uploaded to {path_1}"
except Exception as e:
responses["/1"] = f"Failed: {str(e)}"
return responses
with gr.Blocks() as app:
gr.Markdown("## 📂 Storage Debugger")
list_btn = gr.Button("List Files")
output_list = gr.JSON()
list_btn.click(fn=list_files, outputs=output_list)
gr.Markdown("## ⬆️ Upload Test")
file_input = gr.File()
upload_btn = gr.Button("Upload File")
upload_output = gr.JSON()
upload_btn.click(fn=upload_file, inputs=file_input, outputs=upload_output)
app.launch() |