| import os |
| import gradio as gr |
|
|
| def list_files(): |
| result = {} |
|
|
| |
| try: |
| result["/data"] = os.listdir("/data") |
| except Exception as e: |
| result["/data"] = str(e) |
|
|
| |
| 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) |
|
|
| |
| 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: |
| os.makedirs("/1", exist_ok=True) |
| 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() |