Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -1,29 +1,30 @@
|
|
1 |
-
import os
|
2 |
import gradio as gr
|
|
|
3 |
|
4 |
-
|
5 |
-
|
6 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
7 |
|
8 |
-
|
9 |
-
|
10 |
-
|
11 |
-
|
12 |
-
|
13 |
-
|
14 |
-
|
15 |
-
|
16 |
-
return num1 / num2
|
17 |
|
18 |
-
|
19 |
-
|
20 |
-
calculator,
|
21 |
-
["number", gr.Radio(["add", "subtract", "multiply", "divide"]), "number"],
|
22 |
-
"number",
|
23 |
-
#description="Check out the crowd-sourced dataset at: [https://huggingface.co/datasets/aliabd/crowdsourced-calculator-demo](https://huggingface.co/datasets/aliabd/crowdsourced-calculator-demo)",
|
24 |
-
allow_flagging="manual",
|
25 |
-
flagging_options=["wrong sign", "off by one", "other"],
|
26 |
-
flagging_callback=hf_writer
|
27 |
-
)
|
28 |
-
|
29 |
-
iface.launch()
|
|
|
|
|
1 |
import gradio as gr
|
2 |
+
from pathlib import Path
|
3 |
|
4 |
+
DATA_PATH = Path("./") # Path("/data")
|
5 |
+
def get_storage():
|
6 |
+
files = [
|
7 |
+
{
|
8 |
+
"orig_name": file.name,
|
9 |
+
"name": file.resolve(),
|
10 |
+
"size": file.stat().st_size,
|
11 |
+
"data": None,
|
12 |
+
"is_file": True,
|
13 |
+
}
|
14 |
+
for file in DATA_PATH.glob("**/*")
|
15 |
+
if file.is_file()
|
16 |
+
]
|
17 |
+
usage = sum([f['size'] for f in files])
|
18 |
+
return files, f"{usage/(1024.0 ** 3):.3f}GB"
|
19 |
|
20 |
+
with gr.Blocks() as app:
|
21 |
+
with gr.Row():
|
22 |
+
with gr.Column():
|
23 |
+
btn = gr.Button("Run")
|
24 |
+
with gr.Column():
|
25 |
+
files = gr.Files(label="Files")
|
26 |
+
storage = gr.Text(label="Total Usage")
|
27 |
+
btn.click(get_storage, inputs=None, outputs=[files, storage], postprocess=False)
|
|
|
28 |
|
29 |
+
# Files that you explicitly allow on allowed_paths
|
30 |
+
app.launch(allowed_paths=[str(DATA_PATH)])
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|