Spaces:
Sleeping
Sleeping
Test UploadButton
Browse files
app.py
CHANGED
@@ -1,5 +1,7 @@
|
|
1 |
from typing import Dict
|
2 |
from pathlib import Path
|
|
|
|
|
3 |
|
4 |
import gradio as gr
|
5 |
|
@@ -15,21 +17,20 @@ title = "This is title."
|
|
15 |
description = "This is description."
|
16 |
article = "This is article."
|
17 |
|
18 |
-
|
19 |
-
name = Path(filepath).name
|
20 |
-
return [gr.UploadButton(visible=False), gr.DownloadButton(label=f"Download {name}", value=filepath, visible=True)]
|
21 |
|
22 |
-
def
|
23 |
-
|
|
|
|
|
|
|
|
|
|
|
24 |
|
25 |
with gr.Blocks() as demo:
|
26 |
-
gr.
|
27 |
-
|
28 |
-
|
29 |
-
|
30 |
|
31 |
-
|
32 |
-
d.click(download_file, None, [u, d])
|
33 |
-
|
34 |
-
demo.launch(debug=False,
|
35 |
-
share=True)
|
|
|
1 |
from typing import Dict
|
2 |
from pathlib import Path
|
3 |
+
import pandas as pd
|
4 |
+
from io import StringIO
|
5 |
|
6 |
import gradio as gr
|
7 |
|
|
|
17 |
description = "This is description."
|
18 |
article = "This is article."
|
19 |
|
20 |
+
default_csv = "Phase,Activity,Start date,End date\n\"Mapping the Field\",\"Literature review\",2024-01-01,2024-01-31"
|
|
|
|
|
21 |
|
22 |
+
def process_csv_text(temp_file):
|
23 |
+
if isinstance(temp_file, str):
|
24 |
+
df = pd.read_csv(StringIO(temp_file), parse_dates=["Start date", "End date"])
|
25 |
+
else:
|
26 |
+
df = pd.read_csv(temp_file.name, parse_dates=["Start date", "End date"])
|
27 |
+
print(df)
|
28 |
+
return df
|
29 |
|
30 |
with gr.Blocks() as demo:
|
31 |
+
upload_button = gr.UploadButton(label="Upload Timetable", file_types = ['.csv'], live=True, file_count = "single")
|
32 |
+
table = gr.Dataframe(headers=["Phase", "Activity", "Start date", "End date"], type="pandas", col_count=4, value=process_csv_text(default_csv))
|
33 |
+
image = gr.Plot()
|
34 |
+
upload_button.upload(fn=process_csv_text, inputs=upload_button, outputs=table, api_name="upload_csv")
|
35 |
|
36 |
+
demo.launch(debug=True)
|
|
|
|
|
|
|
|