Upload 2 files (#4)
Browse files- Upload 2 files (798994f18e1941834003c5264df5d941aa84907d)
- data_sources/upload_file.py +14 -2
- functions/chat_functions.py +2 -2
data_sources/upload_file.py
CHANGED
@@ -8,9 +8,21 @@ def get_delimiter(file_path, bytes = 4096):
|
|
8 |
delimiter = sniffer.sniff(data).delimiter
|
9 |
return delimiter
|
10 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
11 |
def process_data_upload(data_file, session_hash):
|
12 |
-
|
13 |
-
df = pd.read_csv(data_file, sep=delimiter)
|
14 |
|
15 |
# Read each sheet and store data in a DataFrame
|
16 |
#data = df.parse(sheet_name)
|
|
|
8 |
delimiter = sniffer.sniff(data).delimiter
|
9 |
return delimiter
|
10 |
|
11 |
+
def read_file(file):
|
12 |
+
if file.endswith(('.csv', '.tsv', '.txt')) :
|
13 |
+
df = pd.read_csv(file, sep=get_delimiter(file))
|
14 |
+
elif file.endswith('.json'):
|
15 |
+
df = pd.read_json(file)
|
16 |
+
elif file.endswith('.xml'):
|
17 |
+
df = pd.read_xml(file)
|
18 |
+
elif file.endswith(('.xls','xlsx')):
|
19 |
+
df = pd.read_excel(file)
|
20 |
+
else:
|
21 |
+
raise ValueError(f'Unsupported filetype: {file}')
|
22 |
+
return df
|
23 |
+
|
24 |
def process_data_upload(data_file, session_hash):
|
25 |
+
df = read_file(data_file)
|
|
|
26 |
|
27 |
# Read each sheet and store data in a DataFrame
|
28 |
#data = df.parse(sheet_name)
|
functions/chat_functions.py
CHANGED
@@ -73,14 +73,14 @@ css= ".file_marker .large{min-height:50px !important;} .example_btn{max-width:30
|
|
73 |
|
74 |
with gr.Blocks(css=css) as demo:
|
75 |
title = gr.HTML("<h1 style='text-align:center;'>Virtual Data Analyst</h1>")
|
76 |
-
description = gr.HTML("<p style='text-align:center;'>Upload a
|
77 |
example_file_1 = gr.File(visible=False, value="samples/bank_marketing_campaign.csv")
|
78 |
example_file_2 = gr.File(visible=False, value="samples/online_retail_data.csv")
|
79 |
with gr.Row():
|
80 |
example_btn_1 = gr.Button(value="Try Me: bank_marketing_campaign.csv", elem_classes="example_btn", size="md", variant="primary")
|
81 |
example_btn_2 = gr.Button(value="Try Me: online_retail_data.csv", elem_classes="example_btn", size="md", variant="primary")
|
82 |
|
83 |
-
file_output = gr.File(label="CSV
|
84 |
example_btn_1.click(fn=run_example, inputs=example_file_1, outputs=file_output)
|
85 |
example_btn_2.click(fn=run_example, inputs=example_file_2, outputs=file_output)
|
86 |
file_output.change(fn=example_display, inputs=file_output, outputs=[example_btn_1, example_btn_2])
|
|
|
73 |
|
74 |
with gr.Blocks(css=css) as demo:
|
75 |
title = gr.HTML("<h1 style='text-align:center;'>Virtual Data Analyst</h1>")
|
76 |
+
description = gr.HTML("<p style='text-align:center;'>Upload a data file and chat with our virtual data analyst to get insights on your data set. Currently accepts CSV, TSV, TXT, XLS, XLSX, XML, and JSON files. Try a sample file to get started!</p>")
|
77 |
example_file_1 = gr.File(visible=False, value="samples/bank_marketing_campaign.csv")
|
78 |
example_file_2 = gr.File(visible=False, value="samples/online_retail_data.csv")
|
79 |
with gr.Row():
|
80 |
example_btn_1 = gr.Button(value="Try Me: bank_marketing_campaign.csv", elem_classes="example_btn", size="md", variant="primary")
|
81 |
example_btn_2 = gr.Button(value="Try Me: online_retail_data.csv", elem_classes="example_btn", size="md", variant="primary")
|
82 |
|
83 |
+
file_output = gr.File(label="Data File (CSV, TSV, TXT, XLS, XLSX, XML, JSON)", show_label=True, elem_classes="file_marker", file_types=['.csv','.xlsx','.txt','.json','.xml','.xls','.tsv'])
|
84 |
example_btn_1.click(fn=run_example, inputs=example_file_1, outputs=file_output)
|
85 |
example_btn_2.click(fn=run_example, inputs=example_file_2, outputs=file_output)
|
86 |
file_output.change(fn=example_display, inputs=file_output, outputs=[example_btn_1, example_btn_2])
|