Kubratech3 commited on
Commit
339ffd2
ยท
verified ยท
1 Parent(s): e1786c7

Update src/streamlit_app.py

Browse files
Files changed (1) hide show
  1. src/streamlit_app.py +294 -13
src/streamlit_app.py CHANGED
@@ -1,34 +1,315 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
  /* Force Text Color for Light & Dark Mode */
2
  html, body, [class*="css"] {
3
  color: #4a148c !important;
4
  }
5
 
6
- /* Streamlit Main Text */
7
  .stMarkdown, .stText, .stSubheader, .stMetric {
8
  color: #4a148c !important;
9
  }
10
 
11
- /* Radio Button Text */
12
- div[role="radiogroup"] label span {
13
- color: #4a148c !important;
 
14
  }
15
 
16
- /* Metric Labels */
17
- [data-testid="stMetricLabel"] {
18
- color: #6a1b9a !important;
19
  }
20
 
21
- /* Metric Values */
22
- [data-testid="stMetricValue"] {
23
- color: #4a148c !important;
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
24
  }
25
 
26
- /* Info / Messages */
27
- .stAlert {
 
 
 
 
 
 
28
  color: #4a148c !important;
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
29
  }
30
 
31
  /* Footer */
32
  .footer {
33
- color: #6a1b9a !important;
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
34
  }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import streamlit as st
2
+ import random
3
+ import requests
4
+
5
+ # -----------------------------
6
+ # Page Config
7
+ # -----------------------------
8
+ st.set_page_config(
9
+ page_title="Rock Paper Scissors | Kubra",
10
+ page_icon="๐ŸŽฎ",
11
+ layout="centered"
12
+ )
13
+
14
+ # -----------------------------
15
+ # Full UI Theme + Dark/Light Fix
16
+ # -----------------------------
17
+ st.markdown("""
18
+ <style>
19
+
20
  /* Force Text Color for Light & Dark Mode */
21
  html, body, [class*="css"] {
22
  color: #4a148c !important;
23
  }
24
 
25
+ /* Main Text */
26
  .stMarkdown, .stText, .stSubheader, .stMetric {
27
  color: #4a148c !important;
28
  }
29
 
30
+ /* Background */
31
+ [data-testid="stAppViewContainer"] {
32
+ background: linear-gradient(135deg, #efe1ff, #f9f2ff);
33
+ font-family: "Segoe UI", sans-serif;
34
  }
35
 
36
+ /* Hide audio player */
37
+ audio {
38
+ display: none !important;
39
  }
40
 
41
+ /* Header */
42
+ [data-testid="stHeader"] {
43
+ background: transparent;
44
+ }
45
+
46
+ /* Title */
47
+ .title {
48
+ text-align: center;
49
+ color: #4a148c;
50
+ font-size: 46px;
51
+ font-weight: 800;
52
+ margin-bottom: 5px;
53
+ }
54
+
55
+ /* Subtitle */
56
+ .subtitle {
57
+ text-align: center;
58
+ color: #7b1fa2;
59
+ font-size: 18px;
60
+ margin-bottom: 25px;
61
+ }
62
+
63
+ /* Buttons */
64
+ .stButton>button {
65
+ background: linear-gradient(135deg, #7b1fa2, #9c27b0);
66
+ color: white !important;
67
+ border-radius: 12px;
68
+ height: 50px;
69
+ font-size: 18px;
70
+ font-weight: 600;
71
+ border: none;
72
+ width: 100%;
73
+ transition: 0.3s;
74
  }
75
 
76
+ .stButton>button:hover {
77
+ background: linear-gradient(135deg, #6a1b9a, #8e24aa);
78
+ transform: scale(1.02);
79
+ }
80
+
81
+ /* Radio Buttons */
82
+ div[role="radiogroup"] label {
83
+ background: white;
84
  color: #4a148c !important;
85
+ padding: 12px 18px;
86
+ border-radius: 10px;
87
+ margin-right: 10px;
88
+ border: 2px solid #d1b3ff;
89
+ font-weight: 600;
90
+ }
91
+
92
+ /* Selected Radio */
93
+ div[role="radiogroup"] input:checked + div {
94
+ background: #e1bee7 !important;
95
+ border-color: #7b1fa2 !important;
96
+ }
97
+
98
+ /* Result */
99
+ .result {
100
+ text-align: center;
101
+ font-size: 30px;
102
+ font-weight: 800;
103
+ color: #4a148c;
104
+ margin-top: 15px;
105
+ }
106
+
107
+ /* Card */
108
+ .card {
109
+ background: white;
110
+ padding: 18px;
111
+ border-radius: 15px;
112
+ box-shadow: 0 4px 12px rgba(0,0,0,0.1);
113
+ margin-bottom: 20px;
114
  }
115
 
116
  /* Footer */
117
  .footer {
118
+ text-align: center;
119
+ color: #7b1fa2;
120
+ font-size: 14px;
121
+ }
122
+
123
+ </style>
124
+ """, unsafe_allow_html=True)
125
+
126
+
127
+ # -----------------------------
128
+ # Title
129
+ # -----------------------------
130
+ st.markdown('<div class="title">๐ŸŽฎ Rock Paper Scissors</div>', unsafe_allow_html=True)
131
+ st.markdown('<div class="subtitle">Beat the AI โ€ข Track Your Score โ€ข Have Fun ๐Ÿ’œ</div>', unsafe_allow_html=True)
132
+
133
+
134
+ # -----------------------------
135
+ # Load Sound
136
+ # -----------------------------
137
+ @st.cache_data
138
+ def load_win_sound():
139
+ url = "https://www.soundjay.com/human/sounds/applause-01.mp3"
140
+ return requests.get(url).content
141
+
142
+
143
+ WIN_SOUND = load_win_sound()
144
+
145
+
146
+ # -----------------------------
147
+ # Session State
148
+ # -----------------------------
149
+ if "user_score" not in st.session_state:
150
+ st.session_state.user_score = 0
151
+
152
+ if "computer_score" not in st.session_state:
153
+ st.session_state.computer_score = 0
154
+
155
+ if "history" not in st.session_state:
156
+ st.session_state.history = []
157
+
158
+ if "play_sound" not in st.session_state:
159
+ st.session_state.play_sound = False
160
+
161
+
162
+ # -----------------------------
163
+ # Game Setup
164
+ # -----------------------------
165
+ choices = ["Rock", "Paper", "Scissors"]
166
+
167
+ icons = {
168
+ "Rock": "โœŠ",
169
+ "Paper": "โœ‹",
170
+ "Scissors": "โœŒ๏ธ"
171
  }
172
+
173
+
174
+ # -----------------------------
175
+ # Game Card
176
+ # -----------------------------
177
+ st.markdown('<div class="card">', unsafe_allow_html=True)
178
+
179
+ st.subheader("๐ŸŽฏ Choose Your Move")
180
+
181
+ user_choice = st.radio("", choices, horizontal=True)
182
+
183
+
184
+ # -----------------------------
185
+ # Play Button
186
+ # -----------------------------
187
+ if st.button("Play Now ๐Ÿš€"):
188
+
189
+ st.session_state.play_sound = False
190
+
191
+ computer_choice = random.choice(choices)
192
+
193
+ st.divider()
194
+
195
+ col1, col2 = st.columns(2)
196
+
197
+ with col1:
198
+ st.markdown("### ๐Ÿ‘ค You")
199
+ st.write(icons[user_choice], user_choice)
200
+
201
+ with col2:
202
+ st.markdown("### ๐Ÿค– Computer")
203
+ st.write(icons[computer_choice], computer_choice)
204
+
205
+
206
+ # -----------------------------
207
+ # Game Logic
208
+ # -----------------------------
209
+ if user_choice == computer_choice:
210
+ result = "It's a Draw ๐Ÿค"
211
+
212
+ elif (
213
+ (user_choice == "Rock" and computer_choice == "Scissors") or
214
+ (user_choice == "Paper" and computer_choice == "Rock") or
215
+ (user_choice == "Scissors" and computer_choice == "Paper")
216
+ ):
217
+
218
+ result = "You Win! ๐ŸŽ‰"
219
+ st.session_state.user_score += 1
220
+
221
+ st.session_state.play_sound = True
222
+ st.balloons()
223
+
224
+ else:
225
+
226
+ result = "Computer Wins ๐Ÿ˜ข"
227
+ st.session_state.computer_score += 1
228
+
229
+
230
+ # Save History
231
+ st.session_state.history.append({
232
+ "You": user_choice,
233
+ "Computer": computer_choice,
234
+ "Result": result
235
+ })
236
+
237
+
238
+ # Show Result
239
+ st.markdown(
240
+ f'<div class="result">{result}</div>',
241
+ unsafe_allow_html=True
242
+ )
243
+
244
+
245
+ st.markdown('</div>', unsafe_allow_html=True)
246
+
247
+
248
+ # -----------------------------
249
+ # Sound
250
+ # -----------------------------
251
+ if st.session_state.play_sound:
252
+ st.audio(WIN_SOUND, format="audio/mp3")
253
+
254
+
255
+ # -----------------------------
256
+ # Scoreboard
257
+ # -----------------------------
258
+ st.markdown('<div class="card">', unsafe_allow_html=True)
259
+
260
+ st.subheader("๐Ÿ“Š Scoreboard")
261
+
262
+ c1, c2 = st.columns(2)
263
+
264
+ with c1:
265
+ st.metric("You", st.session_state.user_score)
266
+
267
+ with c2:
268
+ st.metric("Computer", st.session_state.computer_score)
269
+
270
+ st.markdown('</div>', unsafe_allow_html=True)
271
+
272
+
273
+ # -----------------------------
274
+ # History
275
+ # -----------------------------
276
+ st.markdown('<div class="card">', unsafe_allow_html=True)
277
+
278
+ st.subheader("๐Ÿ“œ Match History")
279
+
280
+ if st.session_state.history:
281
+
282
+ for i, game in enumerate(reversed(st.session_state.history[-8:]), 1):
283
+
284
+ st.write(
285
+ f"**{i}.** ๐Ÿ‘ค {game['You']} | ๐Ÿค– {game['Computer']} | ๐Ÿ† {game['Result']}"
286
+ )
287
+
288
+ else:
289
+ st.info("No games yet. Start playing!")
290
+
291
+
292
+ st.markdown('</div>', unsafe_allow_html=True)
293
+
294
+
295
+ # -----------------------------
296
+ # Reset
297
+ # -----------------------------
298
+ if st.button("Reset Game ๐Ÿ”„"):
299
+
300
+ st.session_state.user_score = 0
301
+ st.session_state.computer_score = 0
302
+ st.session_state.history = []
303
+ st.session_state.play_sound = False
304
+
305
+ st.rerun()
306
+
307
+
308
+ # -----------------------------
309
+ # Footer
310
+ # -----------------------------
311
+ st.markdown("---")
312
+ st.markdown(
313
+ '<div class="footer">Made with ๐Ÿ’œ by Kubra | Streamlit App</div>',
314
+ unsafe_allow_html=True
315
+ )