update streamlit
Browse files- src/streamlit_app.py +90 -38
src/streamlit_app.py
CHANGED
@@ -1,40 +1,92 @@
|
|
1 |
-
import altair as alt
|
2 |
-
import numpy as np
|
3 |
-
import pandas as pd
|
4 |
import streamlit as st
|
|
|
|
|
5 |
|
6 |
-
|
7 |
-
|
8 |
-
|
9 |
-
|
10 |
-
|
11 |
-
|
12 |
-
|
13 |
-
|
14 |
-
|
15 |
-
|
16 |
-
|
17 |
-
|
18 |
-
|
19 |
-
|
20 |
-
|
21 |
-
|
22 |
-
|
23 |
-
|
24 |
-
|
25 |
-
|
26 |
-
|
27 |
-
|
28 |
-
|
29 |
-
|
30 |
-
|
31 |
-
|
32 |
-
|
33 |
-
|
34 |
-
|
35 |
-
|
36 |
-
|
37 |
-
|
38 |
-
|
39 |
-
|
40 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
import streamlit as st
|
2 |
+
from transformers import pipeline
|
3 |
+
import os
|
4 |
|
5 |
+
# constants
|
6 |
+
QUESTION = "Compute the integral of f(x) = x^2."
|
7 |
+
|
8 |
+
# creating pipeline
|
9 |
+
token = os.getenv("HUGGING_FACE_TOKEN")
|
10 |
+
|
11 |
+
pipeline = pipeline(task="text-generation", model="brgx53/3Blarenegv3-ECE-PRYMMAL-Martial")
|
12 |
+
|
13 |
+
# Initialize session state
|
14 |
+
if "help_clicks" not in st.session_state:
|
15 |
+
st.session_state.help_clicks = 0
|
16 |
+
if "button_clicked" not in st.session_state:
|
17 |
+
st.session_state.button_clicked = None
|
18 |
+
|
19 |
+
st.set_page_config(page_title="Interactive Help Interface", layout="centered")
|
20 |
+
|
21 |
+
st.markdown("## Sample Question Interface")
|
22 |
+
st.markdown("")
|
23 |
+
st.markdown(
|
24 |
+
f"<p style='font-size:20px;'>{QUESTION}</p>",
|
25 |
+
unsafe_allow_html=True
|
26 |
+
)
|
27 |
+
# Outer container for neat padding
|
28 |
+
with st.container():
|
29 |
+
# Question area
|
30 |
+
st.text_area(
|
31 |
+
label="Type your response here.",
|
32 |
+
value="",
|
33 |
+
height=100,
|
34 |
+
key="question_input",
|
35 |
+
)
|
36 |
+
|
37 |
+
st.markdown("")
|
38 |
+
|
39 |
+
# Help Button Logic
|
40 |
+
def toggle_help():
|
41 |
+
st.session_state.help_clicks += 1
|
42 |
+
st.session_state.button_clicked = None # Reset help text on new toggle
|
43 |
+
|
44 |
+
# Help Button (main toggle)
|
45 |
+
col1, col2, col3 = st.columns([1, 3, 1])
|
46 |
+
with col2:
|
47 |
+
st.button("Help", on_click=toggle_help)
|
48 |
+
|
49 |
+
# Show 3 sub-buttons if Help clicked an odd number of times
|
50 |
+
if st.session_state.help_clicks % 2 == 1:
|
51 |
+
st.markdown("### Need Help?")
|
52 |
+
st.markdown("Choose an option below to better understand the question.")
|
53 |
+
with st.container():
|
54 |
+
st.markdown("---") # Divider for clarity
|
55 |
+
col1, col2, col3 = st.columns(3)
|
56 |
+
|
57 |
+
with col1:
|
58 |
+
if st.button("π Explain the question"):
|
59 |
+
st.session_state.button_clicked = "Explain the question"
|
60 |
+
with col2:
|
61 |
+
if st.button("π‘ Give an example"):
|
62 |
+
st.session_state.button_clicked = "Give an example"
|
63 |
+
with col3:
|
64 |
+
if st.button("π€ Who cares?"):
|
65 |
+
st.session_state.button_clicked = "Who cares?"
|
66 |
+
|
67 |
+
st.markdown("---")
|
68 |
+
|
69 |
+
# Display response text if a sub-button is clicked
|
70 |
+
if st.session_state.button_clicked:
|
71 |
+
with st.container():
|
72 |
+
st.info(f"**hello world \n{QUESTION} \n{st.session_state.button_clicked}**")
|
73 |
+
|
74 |
+
# Optional: Add footer or spacing
|
75 |
+
st.markdown("<br><br>", unsafe_allow_html=True)
|
76 |
+
|
77 |
+
# css
|
78 |
+
st.markdown(
|
79 |
+
"""
|
80 |
+
<style>
|
81 |
+
div.stButton > button {
|
82 |
+
width: 200px !important;
|
83 |
+
height: 3em;
|
84 |
+
font-size: 1.1rem;
|
85 |
+
display: block;
|
86 |
+
margin-left: auto;
|
87 |
+
margin-right: auto;
|
88 |
+
}
|
89 |
+
</style>
|
90 |
+
""",
|
91 |
+
unsafe_allow_html=True,
|
92 |
+
)
|