Spaces:
Sleeping
Sleeping
Canstralian
commited on
Commit
β’
8e0edfc
1
Parent(s):
d0f3816
Update app.py
Browse files
app.py
CHANGED
@@ -1,26 +1,46 @@
|
|
|
|
1 |
import gradio as gr
|
2 |
-
from utils.search_utils import find_relevant_bounty
|
3 |
|
4 |
-
|
5 |
-
|
6 |
-
bounty = find_relevant_bounty(user_query)
|
7 |
-
if bounty:
|
8 |
-
return (
|
9 |
-
f"Title: {bounty['title']}\n"
|
10 |
-
f"Description: {bounty['description']}\n"
|
11 |
-
f"Answer: {bounty['answer']}\n"
|
12 |
-
f"Score: {bounty['score']}\n"
|
13 |
-
)
|
14 |
-
else:
|
15 |
-
return "No relevant bounties found."
|
16 |
|
17 |
-
#
|
18 |
-
|
19 |
-
|
20 |
-
|
21 |
-
|
22 |
-
|
23 |
-
)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
24 |
|
25 |
-
|
26 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
from pathlib import Path
|
2 |
import gradio as gr
|
|
|
3 |
|
4 |
+
# Define the directory to scan
|
5 |
+
DATA_PATH = Path("/data")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
6 |
|
7 |
+
# Function to get file details and total storage usage
|
8 |
+
def get_storage():
|
9 |
+
# Gather file details
|
10 |
+
files = [
|
11 |
+
{
|
12 |
+
"orig_name": file.name,
|
13 |
+
"name": str(file.resolve()),
|
14 |
+
"size": f"{file.stat().st_size / (1024.0 ** 2):.2f} MB", # Size in MB
|
15 |
+
}
|
16 |
+
for file in DATA_PATH.glob("**/*") if file.is_file()
|
17 |
+
]
|
18 |
+
# Calculate total storage usage
|
19 |
+
total_size = sum(file.stat().st_size for file in DATA_PATH.glob("**/*") if file.is_file())
|
20 |
+
usage = f"{total_size / (1024.0 ** 3):.3f} GB" # Convert to GB
|
21 |
+
return files, usage
|
22 |
|
23 |
+
# Define the Gradio interface
|
24 |
+
with gr.Blocks() as app:
|
25 |
+
# Title and description
|
26 |
+
gr.Markdown("# π File Storage Viewer\nView files and calculate storage usage in the `/data` directory.")
|
27 |
+
|
28 |
+
with gr.Row():
|
29 |
+
with gr.Column():
|
30 |
+
# Button to trigger file listing
|
31 |
+
btn = gr.Button("Fetch Files")
|
32 |
+
|
33 |
+
with gr.Column():
|
34 |
+
# Outputs: File list and total storage usage
|
35 |
+
files = gr.Dataframe(
|
36 |
+
headers=["Original Name", "Path", "Size"],
|
37 |
+
interactive=False,
|
38 |
+
label="Files",
|
39 |
+
)
|
40 |
+
storage = gr.Textbox(label="Total Storage Usage", interactive=False)
|
41 |
+
|
42 |
+
# Click action to trigger the `get_storage` function
|
43 |
+
btn.click(get_storage, inputs=None, outputs=[files, storage])
|
44 |
+
|
45 |
+
# Launch the Gradio app with access to the `/data` directory
|
46 |
+
app.launch(allowed_paths=["/data"])
|