jskinner215 commited on
Commit
7ba8571
·
1 Parent(s): d934c26

Update ui_utils.py

Browse files
Files changed (1) hide show
  1. ui_utils.py +10 -30
ui_utils.py CHANGED
@@ -1,6 +1,11 @@
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
@@ -9,19 +14,17 @@ def display_initial_buttons():
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:")
@@ -30,39 +33,16 @@ def handle_new_class_selection():
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
-
 
1
  import streamlit as st
2
 
3
  def display_initial_buttons():
4
+ if "upload_flow" not in st.session_state:
5
+ st.session_state.upload_flow = False
6
+ if "query_flow" not in st.session_state:
7
+ st.session_state.query_flow = False
8
+
9
  if st.button("Upload new CSV"):
10
  st.session_state.upload_flow = True
11
  st.session_state.query_flow = False
 
14
  st.session_state.query_flow = True
15
  st.session_state.upload_flow = False
16
 
 
17
  def display_class_dropdown(client):
18
  if st.session_state.upload_flow:
19
  existing_classes = [cls["class"] for cls in client.schema.get()["classes"]]
20
  class_options = existing_classes + ["New Class"]
21
+ return st.selectbox("Select a class or create a new one:", class_options)
22
+ elif st.session_state.query_flow:
23
  existing_classes = [cls["class"] for cls in client.schema.get()["classes"]]
24
  class_options = existing_classes + ["Query all data"]
25
+ return st.selectbox("Select a class or query all data:", class_options)
26
 
27
+ def handle_new_class_selection(selected_class):
 
28
  if selected_class == "New Class":
29
  class_name = st.text_input("Enter the new class name:")
30
  class_description = st.text_input("Enter a description for the class:")
 
33
  # Call function to create new class schema in Weaviate
34
  create_new_class_schema(class_name, class_description)
35
 
36
+ def csv_upload_and_ingestion(selected_class):
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
37
  csv_file = st.file_uploader("Upload a CSV file", type=["csv"])
38
  if csv_file:
39
  if st.button("Confirm CSV upload"):
40
  # Call function to ingest CSV data into Weaviate
41
  ingest_csv_to_weaviate(csv_file, selected_class)
42
 
 
43
  def display_query_input():
44
  question = st.text_input("Enter your question:")
45
  if question:
46
  if st.button("Submit Query"):
47
  # Call function to query TAPAS with selected data and entered question
 
 
 
 
 
 
48
  query_tapas_with_weaviate_data(st.session_state.data_source, question)