Akhil4839 commited on
Commit
79ad7f1
ยท
verified ยท
1 Parent(s): 6007271

Update pages/4_Statistics.py

Browse files
Files changed (1) hide show
  1. pages/4_Statistics.py +52 -33
pages/4_Statistics.py CHANGED
@@ -3,15 +3,15 @@ import os
3
  from langchain_huggingface import HuggingFaceEndpoint, ChatHuggingFace
4
  from langchain_core.messages import HumanMessage, SystemMessage
5
 
6
- # Set environment variables
7
  hf = os.getenv('Data_science')
8
  os.environ['HUGGINGFACEHUB_API_TOKEN'] = hf
9
  os.environ['HF_TOKEN'] = hf
10
 
11
- # Page setup
12
- st.set_page_config(page_title="Statistics Mentor Chat", layout="centered")
13
 
14
- # Custom style
15
  st.markdown("""
16
  <style>
17
  .main {
@@ -19,42 +19,61 @@ st.markdown("""
19
  padding: 2rem;
20
  font-family: 'Segoe UI', sans-serif;
21
  }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
22
  .stButton>button {
23
- background: #ffffff10;
24
- border: 2px solid #ffffff50;
25
  color: white;
26
  font-size: 18px;
27
- font-weight: 600;
28
  padding: 0.8em 1.2em;
29
  border-radius: 12px;
30
  width: 100%;
31
- transition: 0.3s ease;
32
- box-shadow: 0 4px 10px rgba(0, 0, 0, 0.15);
33
  }
34
  .stButton>button:hover {
35
- background: #ffffff30;
36
- border-color: #fff;
37
- color: #ffffff;
38
  }
39
- h1, h3, p, label {
40
- color: #ffffff;
41
- text-align: center;
 
 
 
 
42
  }
43
  hr {
44
- border: 1px solid #ffffff50;
45
  margin: 2em 0;
46
  }
47
  </style>
48
  """, unsafe_allow_html=True)
49
 
50
- # Title
51
  st.title("๐Ÿ“Š Statistics Mentor Chat")
 
52
 
53
- # Sidebar
54
- st.sidebar.title("Mentor Preferences")
55
- exp = st.sidebar.selectbox("Select your experience level:", ["Beginner", "Intermediate", "Expert"])
56
 
57
- # Model setup
58
  stats_model_skeleton = HuggingFaceEndpoint(
59
  repo_id='THUDM/GLM-4-32B-0414',
60
  provider='novita',
@@ -72,30 +91,30 @@ stats_mentor = ChatHuggingFace(
72
  task='conversational'
73
  )
74
 
75
- # Session key
76
  PAGE_KEY = "chat_history_stats"
77
  if PAGE_KEY not in st.session_state:
78
  st.session_state[PAGE_KEY] = []
79
 
80
- # Chat form
81
  with st.form(key="chat_form"):
82
- user_input = st.text_input("Ask your question:")
83
- submit = st.form_submit_button("Send")
84
 
85
- # Chat logic
86
  if submit and user_input:
87
  system_prompt = (
88
- f"Act as a statistics mentor with {exp.lower()} expertise. "
89
- f"Answer in a friendly tone and within 150 words. "
90
- f"If the question is not statistics-related, politely say it's out of scope."
91
  )
92
  messages = [SystemMessage(content=system_prompt), HumanMessage(content=user_input)]
93
  result = stats_mentor.invoke(messages)
94
  st.session_state[PAGE_KEY].append((user_input, result.content))
95
 
96
- # Display chat history
97
- st.subheader("๐Ÿ—จ๏ธ Chat History")
98
  for user, bot in st.session_state[PAGE_KEY]:
99
- st.markdown(f"**You:** {user}")
100
- st.markdown(f"**Mentor:** {bot}")
101
  st.markdown("---")
 
3
  from langchain_huggingface import HuggingFaceEndpoint, ChatHuggingFace
4
  from langchain_core.messages import HumanMessage, SystemMessage
5
 
6
+ # --- Environment Token Setup ---
7
  hf = os.getenv('Data_science')
8
  os.environ['HUGGINGFACEHUB_API_TOKEN'] = hf
9
  os.environ['HF_TOKEN'] = hf
10
 
11
+ # --- Streamlit Page Config ---
12
+ st.set_page_config(page_title="๐Ÿ“Š Statistics Mentor Chat", page_icon="๐Ÿ“ˆ", layout="centered")
13
 
14
+ # --- Custom CSS Styling ---
15
  st.markdown("""
16
  <style>
17
  .main {
 
19
  padding: 2rem;
20
  font-family: 'Segoe UI', sans-serif;
21
  }
22
+ h1, h2, h3, h4, h5, h6, p, label, .css-10trblm, .css-q8sbsg {
23
+ color: #ffffff !important;
24
+ text-align: center;
25
+ }
26
+ .stTextInput > div > div > input {
27
+ background-color: rgba(255, 255, 255, 0.1);
28
+ color: white;
29
+ border: 1px solid rgba(255, 255, 255, 0.5);
30
+ border-radius: 8px;
31
+ padding: 0.6em;
32
+ }
33
+ .stTextInput > div > div > input::placeholder {
34
+ color: rgba(255, 255, 255, 0.6);
35
+ }
36
  .stButton>button {
37
+ background: rgba(255, 255, 255, 0.15);
38
+ border: 2px solid rgba(255, 255, 255, 0.4);
39
  color: white;
40
  font-size: 18px;
41
+ font-weight: bold;
42
  padding: 0.8em 1.2em;
43
  border-radius: 12px;
44
  width: 100%;
45
+ transition: all 0.3s ease;
46
+ box-shadow: 0 4px 12px rgba(0, 0, 0, 0.25);
47
  }
48
  .stButton>button:hover {
49
+ background: rgba(255, 255, 255, 0.3);
50
+ border-color: white;
51
+ color: white;
52
  }
53
+ .stSidebar > div:first-child {
54
+ background: #2c3e50;
55
+ padding: 1rem;
56
+ border-radius: 0 15px 15px 0;
57
+ }
58
+ .stSidebar h1, .stSidebar h2, .stSidebar h3, .stSidebar label, .stSidebar p {
59
+ color: white !important;
60
  }
61
  hr {
62
+ border: 1px solid rgba(255, 255, 255, 0.3);
63
  margin: 2em 0;
64
  }
65
  </style>
66
  """, unsafe_allow_html=True)
67
 
68
+ # --- Page Title ---
69
  st.title("๐Ÿ“Š Statistics Mentor Chat")
70
+ st.markdown("### ๐Ÿงฎ Ask questions about probability, distributions, testing, and more!")
71
 
72
+ # --- Sidebar: Experience Selection ---
73
+ st.sidebar.title("๐ŸŽ“ Mentor Preferences")
74
+ exp = st.sidebar.selectbox("๐Ÿ“š Select your experience level:", ["Beginner", "Intermediate", "Expert"])
75
 
76
+ # --- Load Language Model ---
77
  stats_model_skeleton = HuggingFaceEndpoint(
78
  repo_id='THUDM/GLM-4-32B-0414',
79
  provider='novita',
 
91
  task='conversational'
92
  )
93
 
94
+ # --- Chat Session State ---
95
  PAGE_KEY = "chat_history_stats"
96
  if PAGE_KEY not in st.session_state:
97
  st.session_state[PAGE_KEY] = []
98
 
99
+ # --- Chat Input ---
100
  with st.form(key="chat_form"):
101
+ user_input = st.text_input("๐Ÿ“Œ Ask your Statistics question:", placeholder="e.g. What is the difference between mean and median?")
102
+ submit = st.form_submit_button("๐Ÿ“ค Send")
103
 
104
+ # --- Chat Handling Logic ---
105
  if submit and user_input:
106
  system_prompt = (
107
+ f"You are a statistics mentor with {exp.lower()} expertise. "
108
+ f"Answer only statistics-related questions in a concise, friendly tone. "
109
+ f"Keep responses under 150 words. If the topic is out of scope, politely say so."
110
  )
111
  messages = [SystemMessage(content=system_prompt), HumanMessage(content=user_input)]
112
  result = stats_mentor.invoke(messages)
113
  st.session_state[PAGE_KEY].append((user_input, result.content))
114
 
115
+ # --- Chat History ---
116
+ st.subheader("๐Ÿ“œ Chat History")
117
  for user, bot in st.session_state[PAGE_KEY]:
118
+ st.markdown(f"**๐Ÿ™‹ You:** {user}")
119
+ st.markdown(f"**๐Ÿ“ˆ Mentor:** {bot}")
120
  st.markdown("---")