jskinner215 commited on
Commit
d934c26
·
1 Parent(s): 0e0ce94

Create ui_utils.py

Browse files
Files changed (1) hide show
  1. ui_utils.py +68 -0
ui_utils.py ADDED
@@ -0,0 +1,68 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import streamlit as st
2
+
3
+ def display_initial_buttons():
4
+ if st.button("Upload new CSV"):
5
+ st.session_state.upload_flow = True
6
+ st.session_state.query_flow = False
7
+
8
+ if st.button("Query existing data"):
9
+ st.session_state.query_flow = True
10
+ st.session_state.upload_flow = False
11
+
12
+
13
+ def display_class_dropdown(client):
14
+ if st.session_state.upload_flow:
15
+ existing_classes = [cls["class"] for cls in client.schema.get()["classes"]]
16
+ class_options = existing_classes + ["New Class"]
17
+ selected_class = st.selectbox("Select a class or create a new one:", class_options)
18
+ if st.session_state.query_flow:
19
+ existing_classes = [cls["class"] for cls in client.schema.get()["classes"]]
20
+ class_options = existing_classes + ["Query all data"]
21
+ selected_class = st.selectbox("Select a class or query all data:", class_options)
22
+
23
+
24
+ def handle_new_class_selection():
25
+ if selected_class == "New Class":
26
+ class_name = st.text_input("Enter the new class name:")
27
+ class_description = st.text_input("Enter a description for the class:")
28
+ if class_name and class_description:
29
+ if st.button("Create Vector DB Class"):
30
+ # Call function to create new class schema in Weaviate
31
+ create_new_class_schema(class_name, class_description)
32
+
33
+ if selected_class != "Query all data":
34
+ # Display data preview for selected class
35
+ display_data_preview(selected_class)
36
+ if st.button("Confirm Data Selection"):
37
+ # Set the selected class as the data source for TAPAS queries
38
+ st.session_state.data_source = selected_class
39
+
40
+ else:
41
+ # Display all class schemas
42
+ display_all_class_schemas()
43
+ if st.button("Confirm Data Selection"):
44
+ # Set all data as the source for TAPAS queries
45
+ st.session_state.data_source = "all_data"
46
+
47
+
48
+ def csv_upload_and_ingestion():
49
+ csv_file = st.file_uploader("Upload a CSV file", type=["csv"])
50
+ if csv_file:
51
+ if st.button("Confirm CSV upload"):
52
+ # Call function to ingest CSV data into Weaviate
53
+ ingest_csv_to_weaviate(csv_file, selected_class)
54
+
55
+
56
+ def display_query_input():
57
+ question = st.text_input("Enter your question:")
58
+ if question:
59
+ if st.button("Submit Query"):
60
+ # Call function to query TAPAS with selected data and entered question
61
+ query_tapas_with_weaviate_data(selected_class, question)
62
+
63
+ question = st.text_input("Enter your question:")
64
+ if question:
65
+ if st.button("Submit Query"):
66
+ # Call function to query TAPAS with selected data source and entered question
67
+ query_tapas_with_weaviate_data(st.session_state.data_source, question)
68
+