Update src/streamlit_app.py
Browse files- src/streamlit_app.py +86 -86
src/streamlit_app.py
CHANGED
@@ -34,93 +34,93 @@ def get_llm(model_id=MODEL, max_new_tokens=130, temperature=0.7):
|
|
34 |
# create llm
|
35 |
llm = get_llm()
|
36 |
|
37 |
-
#
|
38 |
-
|
39 |
-
|
40 |
-
|
41 |
-
|
42 |
-
|
43 |
-
|
44 |
-
|
45 |
-
|
46 |
-
|
47 |
-
|
48 |
-
|
49 |
-
|
50 |
-
|
51 |
-
#
|
52 |
-
|
53 |
-
#
|
54 |
-
|
55 |
-
|
56 |
-
|
57 |
-
|
58 |
-
|
59 |
-
|
60 |
-
|
61 |
-
|
62 |
-
|
63 |
-
#
|
64 |
-
|
65 |
-
|
66 |
-
|
67 |
-
|
68 |
-
#
|
69 |
-
|
70 |
-
|
71 |
-
|
72 |
-
|
73 |
-
#
|
74 |
-
|
75 |
-
|
76 |
-
|
77 |
-
|
78 |
-
|
79 |
-
|
80 |
-
|
81 |
-
|
82 |
-
|
83 |
-
|
84 |
-
|
85 |
|
86 |
-
|
87 |
-
|
88 |
-
|
89 |
-
|
90 |
-
|
91 |
|
92 |
-
|
93 |
-
|
94 |
-
|
95 |
-
|
96 |
-
|
97 |
|
98 |
-
|
99 |
-
|
100 |
-
|
101 |
-
|
102 |
-
#
|
103 |
-
|
104 |
-
|
105 |
-
|
106 |
-
|
107 |
-
#
|
108 |
-
|
109 |
-
|
110 |
-
#
|
111 |
-
|
112 |
-
|
113 |
-
|
114 |
-
|
115 |
-
|
116 |
-
|
117 |
-
|
118 |
-
|
119 |
-
|
120 |
-
|
121 |
-
|
122 |
-
|
123 |
-
|
124 |
-
|
125 |
-
|
126 |
|
|
|
34 |
# create llm
|
35 |
llm = get_llm()
|
36 |
|
37 |
+
# Initialize session state
|
38 |
+
if "help_clicks" not in st.session_state:
|
39 |
+
st.session_state.help_clicks = 0
|
40 |
+
if "button_clicked" not in st.session_state:
|
41 |
+
st.session_state.button_clicked = None
|
42 |
+
|
43 |
+
st.set_page_config(page_title="Interactive Help Interface", layout="centered")
|
44 |
+
|
45 |
+
st.markdown("## Sample Question Interface")
|
46 |
+
st.markdown("")
|
47 |
+
st.markdown(
|
48 |
+
f"<p style='font-size:20px;'>{QUESTION}</p>",
|
49 |
+
unsafe_allow_html=True
|
50 |
+
)
|
51 |
+
# Outer container for neat padding
|
52 |
+
with st.container():
|
53 |
+
# Question area
|
54 |
+
st.text_area(
|
55 |
+
label="Type your response here.",
|
56 |
+
value="",
|
57 |
+
height=100,
|
58 |
+
key="question_input",
|
59 |
+
)
|
60 |
+
|
61 |
+
st.markdown("")
|
62 |
+
|
63 |
+
# Help Button Logic
|
64 |
+
def toggle_help():
|
65 |
+
st.session_state.help_clicks += 1
|
66 |
+
st.session_state.button_clicked = None # Reset help text on new toggle
|
67 |
+
|
68 |
+
# Help Button (main toggle)
|
69 |
+
col1, col2, col3 = st.columns([1, 3, 1])
|
70 |
+
with col2:
|
71 |
+
st.button("Help", on_click=toggle_help)
|
72 |
+
|
73 |
+
# Show 3 sub-buttons if Help clicked an odd number of times
|
74 |
+
if st.session_state.help_clicks % 2 == 1:
|
75 |
+
st.markdown("### Need Help?")
|
76 |
+
st.markdown("Choose an option below to better understand the question.")
|
77 |
+
with st.container():
|
78 |
+
st.markdown("---") # Divider for clarity
|
79 |
+
col1, col2, col3 = st.columns(3)
|
80 |
+
|
81 |
+
with col1:
|
82 |
+
if st.button("π Explain the question"):
|
83 |
+
prompt = f"[INST]You are a thoughtful AI assistant.\nUser: {QUESTION} [/INST]\nAI:"
|
84 |
+
st.session_state.response = llm.invoke(prompt)
|
85 |
|
86 |
+
st.session_state.button_clicked = "Explain the question"
|
87 |
+
with col2:
|
88 |
+
if st.button("π‘ Give an example"):
|
89 |
+
prompt = f"[INST]You are a thoughtful AI assistant.\nUser: {QUESTION} [/INST]\nAI:"
|
90 |
+
st.session_state.response = llm.invoke(prompt)
|
91 |
|
92 |
+
st.session_state.button_clicked = "Give an example"
|
93 |
+
with col3:
|
94 |
+
if st.button("π€ Who cares?"):
|
95 |
+
prompt = f"[INST]You are a thoughtful AI assistant.\nUser: {QUESTION} [/INST]\nAI:"
|
96 |
+
st.session_state.response = llm.invoke(prompt)
|
97 |
|
98 |
+
st.session_state.button_clicked = "Who cares?"
|
99 |
+
|
100 |
+
st.markdown("---")
|
101 |
+
|
102 |
+
# Display response text if a sub-button is clicked
|
103 |
+
if st.session_state.button_clicked:
|
104 |
+
with st.container():
|
105 |
+
st.info(st.session_state.response)
|
106 |
+
|
107 |
+
# Optional: Add footer or spacing
|
108 |
+
st.markdown("<br><br>", unsafe_allow_html=True)
|
109 |
+
|
110 |
+
# css
|
111 |
+
st.markdown(
|
112 |
+
"""
|
113 |
+
<style>
|
114 |
+
div.stButton > button {
|
115 |
+
width: 200px !important;
|
116 |
+
height: 3em;
|
117 |
+
font-size: 1.1rem;
|
118 |
+
display: block;
|
119 |
+
margin-left: auto;
|
120 |
+
margin-right: auto;
|
121 |
+
}
|
122 |
+
</style>
|
123 |
+
""",
|
124 |
+
unsafe_allow_html=True,
|
125 |
+
)
|
126 |
|