rahgadda commited on
Commit
84ac28f
·
verified ·
1 Parent(s): bf6a716

Initial Draft

Browse files
Files changed (1) hide show
  1. lib/ui/sidebar.py +110 -0
lib/ui/sidebar.py ADDED
@@ -0,0 +1,110 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import subprocess
2
+ import time
3
+ import streamlit as st
4
+ import pandas as pd
5
+
6
+
7
+ def fn_process_excel(lv_file_name,ui_status_message,sm):
8
+ try:
9
+ # Read the Excel file
10
+ excel_data = pd.read_excel(lv_file_name,sheet_name=None)
11
+
12
+ # Iterate over each sheet in the Excel file
13
+ for sheet_name, sheet_data in excel_data.items():
14
+ # Process the data in each sheet
15
+ print(f"Sheet Name: {sheet_name}")
16
+ print(sheet_data.head())
17
+
18
+ # Display a success message
19
+ sm.fn_display_status_messages("Excel data processed successfully!", "Success", ui_status_message)
20
+
21
+ except Exception as e:
22
+ # Display an error message if there is an exception
23
+ sm.fn_display_status_messages(f"Error: {e}", "Error", ui_status_message)
24
+
25
+ # Function to start the Flask server
26
+ def start_flask_server():
27
+ """
28
+ Function to start the Flask server.
29
+
30
+ Returns:
31
+ None
32
+ """
33
+ lv_proc = subprocess.Popen(["python", "flask_app.py"])
34
+ st.session_state.sv_flask_server_proc = lv_proc
35
+
36
+ # Function to stop the Flask server
37
+ def stop_flask_server():
38
+ """
39
+ Function to stop the Flask server.
40
+
41
+ Returns:
42
+ None
43
+ """
44
+
45
+ lv_proc = st.session_state.sv_flask_server_proc
46
+ if lv_proc is not None:
47
+ lv_proc.terminate()
48
+ lv_proc.wait(timeout=5)
49
+ if lv_proc.poll() is None:
50
+ lv_proc.kill()
51
+ st.session_state.sv_flask_server_proc = None
52
+
53
+ # Function to configure the sidebar UI elements.
54
+ def fn_sidebar_configuration(ui_status_message,sm):
55
+ """
56
+ Function to configure the sidebar UI elements.
57
+
58
+ Parameters:
59
+ - ui_status_message (str): The status message to be display in UI.
60
+
61
+ Returns:
62
+ None
63
+ """
64
+
65
+ try:
66
+ if not(st.session_state.sv_flask_server_proc):
67
+ # Start Flask Server
68
+ start_flask_server()
69
+
70
+ # Toggle button to enable/disable training mode
71
+ ui_training_indicator = st.toggle("Training", value=False)
72
+
73
+ # Container to hold the UI elements
74
+ ui_container = st.container(border=True)
75
+
76
+ with ui_container:
77
+
78
+ # Training new domain
79
+ if ui_training_indicator:
80
+ # File uploader for training file
81
+ ui_training_file = st.file_uploader("Training File", type=["xlsx"], accept_multiple_files=False, key="training_file")
82
+
83
+ # Text input for domain name
84
+ ui_domain_name = st.text_input("Domain Name")
85
+
86
+ # Button to submit the form
87
+ if st.button("Submit"):
88
+
89
+ # Check if the training file is uploaded
90
+ if ui_training_file is not None and ui_domain_name != "":
91
+ lv_file_name = "storage/"+ui_domain_name+".xlsx"
92
+
93
+ # Saving File
94
+ with open(lv_file_name, "wb") as f:
95
+ f.write(ui_training_file.getvalue())
96
+
97
+ # Process the Excel file
98
+ fn_process_excel(lv_file_name, ui_status_message,sm)
99
+ else:
100
+ # Display an error message if the training file is not uploaded
101
+ sm.fn_display_status_messages("Please upload the training file.", "Error", ui_status_message)
102
+
103
+ # Mapping data to trained domain
104
+ else:
105
+ # Selectbox for domain selection
106
+ ui_training_vector_db = st.selectbox("Domain", ["OFSLL", "OBRL"])
107
+
108
+ except Exception as e:
109
+ # Display an error message if there is an exception
110
+ sm.fn_display_status_messages(f"Error: {e}", "Error", ui_status_message)