Spaces:
Running
Running
UI updated.
Browse files
app.py
CHANGED
@@ -5,6 +5,7 @@ import hmac
|
|
5 |
import os
|
6 |
|
7 |
st.header(" Scientific Claim Verification ")
|
|
|
8 |
|
9 |
def check_password():
|
10 |
"""Returns `True` if the user had a correct password."""
|
@@ -40,12 +41,69 @@ def check_password():
|
|
40 |
return False
|
41 |
|
42 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
43 |
if not check_password():
|
44 |
st.stop()
|
45 |
|
46 |
-
#Start of the Agentic Demo
|
47 |
|
48 |
-
st.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
49 |
|
50 |
# Initialize chat history
|
51 |
if "messages" not in st.session_state:
|
@@ -61,7 +119,15 @@ def retriever(query: str):
|
|
61 |
with st.chat_message("assistant"):
|
62 |
placeholder = st.empty()
|
63 |
text=""
|
64 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
65 |
for chunk in message.split():
|
66 |
text += chunk + " "
|
67 |
time.sleep(0.05)
|
@@ -76,7 +142,14 @@ def reasoner(info: list[str]):
|
|
76 |
with st.chat_message("assistant"):
|
77 |
placeholder = st.empty()
|
78 |
text=""
|
79 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
80 |
for chunk in message.split():
|
81 |
text += chunk + " "
|
82 |
time.sleep(0.05)
|
@@ -89,6 +162,7 @@ def reasoner(info: list[str]):
|
|
89 |
# Accept user input
|
90 |
if prompt := st.chat_input("Type here"):
|
91 |
# Add user message to chat history
|
|
|
92 |
st.session_state.messages.append({"role": "user", "content": prompt})
|
93 |
# Display user message in chat message container
|
94 |
with st.chat_message("user"):
|
@@ -96,8 +170,6 @@ if prompt := st.chat_input("Type here"):
|
|
96 |
|
97 |
|
98 |
retrieved_documents=retriever(prompt)
|
99 |
-
|
100 |
-
|
101 |
reasoning = reasoner(retrieved_documents)
|
102 |
|
103 |
# Display assistant response in chat message container
|
@@ -120,3 +192,4 @@ if prompt := st.chat_input("Type here"):
|
|
120 |
message_placeholder.markdown(full_response)
|
121 |
# Add assistant response to chat history
|
122 |
st.session_state.messages.append({"role": "assistant", "content": full_response})
|
|
|
|
5 |
import os
|
6 |
|
7 |
st.header(" Scientific Claim Verification ")
|
8 |
+
st.caption("Team UMBC-SBU-UT")
|
9 |
|
10 |
def check_password():
|
11 |
"""Returns `True` if the user had a correct password."""
|
|
|
41 |
return False
|
42 |
|
43 |
|
44 |
+
def select_models():
|
45 |
+
"""Returns only when a valid option is selected from both dropdowns."""
|
46 |
+
|
47 |
+
#placeholders
|
48 |
+
retriever_options = ["Choose one...", "Simple", "Trained", "No Retriever"]
|
49 |
+
reasoner_options = ["Choose one...", "Claude Sonnet", "GPT-4o", "o3-mini"]
|
50 |
+
|
51 |
+
#selectboxes
|
52 |
+
|
53 |
+
retriever = st.selectbox(
|
54 |
+
"Select the Retriever Model",
|
55 |
+
retriever_options,
|
56 |
+
key="retriever"
|
57 |
+
)
|
58 |
+
|
59 |
+
reasoner = st.selectbox(
|
60 |
+
"Select the Reasoner Model",
|
61 |
+
reasoner_options,
|
62 |
+
key="reasoner"
|
63 |
+
)
|
64 |
+
|
65 |
+
#next button
|
66 |
+
|
67 |
+
if st.button("Next"):
|
68 |
+
# Check that both selections are not the placeholder.
|
69 |
+
if retriever == "Choose one..." or reasoner == "Choose one...":
|
70 |
+
st.info("Please select both a retriever and a reasoner.")
|
71 |
+
return None, None
|
72 |
+
else:
|
73 |
+
# Store the valid selections in session state
|
74 |
+
st.session_state["selected_models"] = (retriever, reasoner)
|
75 |
+
return retriever, reasoner
|
76 |
+
else:
|
77 |
+
st.info("Click 'Next' once you have made your selections.")
|
78 |
+
return None, None
|
79 |
+
|
80 |
if not check_password():
|
81 |
st.stop()
|
82 |
|
|
|
83 |
|
84 |
+
if "selected_models" not in st.session_state:
|
85 |
+
selected_retriever, selected_reasoner = select_models()
|
86 |
+
# If valid selections are returned, store them and reset the change flag.
|
87 |
+
if selected_retriever is not None and selected_reasoner is not None:
|
88 |
+
st.session_state.selected_models = (selected_retriever, selected_reasoner)
|
89 |
+
st.rerun()
|
90 |
+
else:
|
91 |
+
st.stop() # Halt further execution until valid selections are made.
|
92 |
+
else:
|
93 |
+
selected_retriever, selected_reasoner = st.session_state.selected_models
|
94 |
+
|
95 |
+
#START OF AGENTIC DEMO
|
96 |
+
|
97 |
+
column1, column2 = st.columns(2)
|
98 |
+
column1.caption(f"Retriever Selected: {selected_retriever}")
|
99 |
+
column2.caption(f"Reasoner Selected: {selected_reasoner}")
|
100 |
+
|
101 |
+
|
102 |
+
if st.button("Change Selection", key="change_selection_btn"):
|
103 |
+
st.session_state.pop("selected_models", None)
|
104 |
+
st.session_state.pop("retriever", None)
|
105 |
+
st.session_state.pop("reasoner", None)
|
106 |
+
st.rerun()
|
107 |
|
108 |
# Initialize chat history
|
109 |
if "messages" not in st.session_state:
|
|
|
119 |
with st.chat_message("assistant"):
|
120 |
placeholder = st.empty()
|
121 |
text=""
|
122 |
+
|
123 |
+
if selected_retriever == "Simple":
|
124 |
+
message = "Using the simple retriever to search for documents related to your query..."
|
125 |
+
elif selected_retriever == "Trained":
|
126 |
+
message = "Using the trained retriever to fetch detailed documents relevant to your query..."
|
127 |
+
else:
|
128 |
+
message = "No retriever selected. Skipping document retrieval."
|
129 |
+
|
130 |
+
|
131 |
for chunk in message.split():
|
132 |
text += chunk + " "
|
133 |
time.sleep(0.05)
|
|
|
142 |
with st.chat_message("assistant"):
|
143 |
placeholder = st.empty()
|
144 |
text=""
|
145 |
+
|
146 |
+
if selected_reasoner == "Claude Sonnet":
|
147 |
+
message = "Using Claude Sonnet to reason and verify the claim..."
|
148 |
+
elif selected_reasoner == "GPT-4o":
|
149 |
+
message = "Using GPT-4o to analyze and verify the claim in detail..."
|
150 |
+
else:
|
151 |
+
message = "Using o3-mini to quickly analyze the claim..."
|
152 |
+
|
153 |
for chunk in message.split():
|
154 |
text += chunk + " "
|
155 |
time.sleep(0.05)
|
|
|
162 |
# Accept user input
|
163 |
if prompt := st.chat_input("Type here"):
|
164 |
# Add user message to chat history
|
165 |
+
prompt= prompt + " \n"+ " \n"+ f"Retriever: {selected_retriever}, Reasoner: {selected_reasoner}"
|
166 |
st.session_state.messages.append({"role": "user", "content": prompt})
|
167 |
# Display user message in chat message container
|
168 |
with st.chat_message("user"):
|
|
|
170 |
|
171 |
|
172 |
retrieved_documents=retriever(prompt)
|
|
|
|
|
173 |
reasoning = reasoner(retrieved_documents)
|
174 |
|
175 |
# Display assistant response in chat message container
|
|
|
192 |
message_placeholder.markdown(full_response)
|
193 |
# Add assistant response to chat history
|
194 |
st.session_state.messages.append({"role": "assistant", "content": full_response})
|
195 |
+
|