feministmystique commited on
Commit
7ce3cce
Β·
verified Β·
1 Parent(s): 2f815b6

update streamlit

Browse files
Files changed (1) hide show
  1. 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
- # Welcome to Streamlit!
8
-
9
- Edit `/streamlit_app.py` to customize this app to your heart's desire :heart:.
10
- If you have any questions, checkout our [documentation](https://docs.streamlit.io) and [community
11
- forums](https://discuss.streamlit.io).
12
-
13
- In the meantime, below is an example of what you can do with just a few lines of code:
14
- """
15
-
16
- num_points = st.slider("Number of points in spiral", 1, 10000, 1100)
17
- num_turns = st.slider("Number of turns in spiral", 1, 300, 31)
18
-
19
- indices = np.linspace(0, 1, num_points)
20
- theta = 2 * np.pi * num_turns * indices
21
- radius = indices
22
-
23
- x = radius * np.cos(theta)
24
- y = radius * np.sin(theta)
25
-
26
- df = pd.DataFrame({
27
- "x": x,
28
- "y": y,
29
- "idx": indices,
30
- "rand": np.random.randn(num_points),
31
- })
32
-
33
- st.altair_chart(alt.Chart(df, height=700, width=700)
34
- .mark_point(filled=True)
35
- .encode(
36
- x=alt.X("x", axis=None),
37
- y=alt.Y("y", axis=None),
38
- color=alt.Color("idx", legend=None, scale=alt.Scale()),
39
- size=alt.Size("rand", legend=None, scale=alt.Scale(range=[1, 150])),
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
+ )