add submit button
Browse files
app.py
CHANGED
@@ -58,6 +58,9 @@ with st.sidebar:
|
|
58 |
"Upload documents", accept_multiple_files=True, type=["txt", "pdf"]
|
59 |
)
|
60 |
|
|
|
|
|
|
|
61 |
# Input filter
|
62 |
top_n = st.number_input(
|
63 |
"Insert a number (top n rows to be selected):", value=5, step=1
|
@@ -66,9 +69,11 @@ with st.sidebar:
|
|
66 |
# Use dictionary
|
67 |
use_dict_format = st.checkbox("Use dictionary format.")
|
68 |
|
|
|
|
|
|
|
69 |
# Clear button
|
70 |
clear_button = st.sidebar.button("Clear Conversation", key="clear")
|
71 |
-
|
72 |
# Credit
|
73 |
current_year = current_year() # This will print the current year
|
74 |
st.markdown(
|
@@ -102,38 +107,36 @@ if uploaded_files is None:
|
|
102 |
|
103 |
|
104 |
elif uploaded_files:
|
105 |
-
|
106 |
-
|
107 |
-
|
108 |
-
# Process the uploaded files to extract text and source information
|
109 |
-
textify_output = read_and_textify(uploaded_files)
|
110 |
|
111 |
-
|
112 |
-
|
113 |
|
114 |
-
|
115 |
-
|
116 |
|
117 |
-
|
118 |
-
|
119 |
-
|
120 |
-
|
121 |
-
|
122 |
-
|
123 |
-
|
124 |
-
|
125 |
-
|
126 |
-
|
127 |
-
|
128 |
-
|
129 |
-
|
130 |
-
|
131 |
-
|
132 |
-
|
133 |
-
|
134 |
-
|
135 |
-
|
136 |
-
|
137 |
-
|
138 |
-
|
139 |
-
|
|
|
58 |
"Upload documents", accept_multiple_files=True, type=["txt", "pdf"]
|
59 |
)
|
60 |
|
61 |
+
# Inform the user how many documents have been loaded
|
62 |
+
st.success(f"{len(uploaded_files)} document(s) loaded...")
|
63 |
+
|
64 |
# Input filter
|
65 |
top_n = st.number_input(
|
66 |
"Insert a number (top n rows to be selected):", value=5, step=1
|
|
|
69 |
# Use dictionary
|
70 |
use_dict_format = st.checkbox("Use dictionary format.")
|
71 |
|
72 |
+
# Submit button
|
73 |
+
submit_it = st.sidebar.button("Submit", type="primary")
|
74 |
+
|
75 |
# Clear button
|
76 |
clear_button = st.sidebar.button("Clear Conversation", key="clear")
|
|
|
77 |
# Credit
|
78 |
current_year = current_year() # This will print the current year
|
79 |
st.markdown(
|
|
|
107 |
|
108 |
|
109 |
elif uploaded_files:
|
110 |
+
if submit_it:
|
111 |
+
# Process the uploaded files to extract text and source information
|
112 |
+
textify_output = read_and_textify(uploaded_files)
|
|
|
|
|
113 |
|
114 |
+
# Separate the output into documents (text) and their corresponding sources
|
115 |
+
documents, sources = textify_output
|
116 |
|
117 |
+
# Call the function
|
118 |
+
query_database = list_to_nums(documents)
|
119 |
|
120 |
+
# Create reference table
|
121 |
+
refs_tab = query_search(
|
122 |
+
"pful for understanding federal income", documents, query_database, sources
|
123 |
+
)
|
124 |
+
refs_tab.head(math.ceil(top_n))
|
125 |
+
|
126 |
+
# React to user input
|
127 |
+
if prompt := st.chat_input("What is up?"):
|
128 |
+
# Display user message in chat message container
|
129 |
+
st.chat_message("user").markdown(prompt)
|
130 |
+
# Add user message to chat history
|
131 |
+
st.session_state.messages.append({"role": "user", "content": prompt})
|
132 |
+
|
133 |
+
result = refs_tab
|
134 |
+
|
135 |
+
# Display assistant response in chat message container
|
136 |
+
with st.chat_message("assistant"):
|
137 |
+
if not use_dict_format:
|
138 |
+
st.table(result)
|
139 |
+
else:
|
140 |
+
st.write(result.to_json())
|
141 |
+
# Add assistant response to chat history
|
142 |
+
st.session_state.messages.append({"role": "assistant", "content": result})
|