testrro commited on
Commit
c9e1d82
·
verified ·
1 Parent(s): cca0af3

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +284 -74
app.py CHANGED
@@ -1,114 +1,324 @@
1
  import gradio as gr
2
  import random
3
  from statistics import mean
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
4
 
5
- # ---------- Helper functions ----------
6
  def compute_outputs(rounds):
7
- """Calculate expected multiplier, analysis, and decision based on recent rounds."""
8
  if not rounds:
9
- return "0.0", "No data", "N/A"
10
-
11
- # Use last 10 rounds (or fewer if not enough data)
12
  recent = rounds[-10:] if len(rounds) >= 10 else rounds
13
  avg = mean(recent)
14
-
15
- # Expected multiplier = average ± small random fluctuation (simulate unpredictability)
16
- expected = round(avg * random.uniform(0.95, 1.05), 2)
17
-
18
- # Simple trend analysis
19
  if len(recent) >= 2:
20
- trend = recent[-1] - recent[-2]
21
- if trend > 0.1:
22
- analysis = "Increasing"
23
- elif trend < -0.1:
24
- analysis = "Decreasing"
25
  else:
26
- analysis = "Stable"
27
  else:
28
- analysis = "Insufficient data"
29
-
30
- # Decision based on expected multiplier
31
- if expected > 2.5:
32
- decision = "High"
33
- elif expected > 1.5:
34
- decision = "Medium"
 
 
 
 
 
 
35
  else:
36
- decision = "Low"
37
-
38
- return str(expected), analysis, decision
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
39
 
40
  def update_ui(rounds):
41
- """Prepare the dataframe and the three output values from the current rounds list."""
42
- # Build table: [Round number, Multiplier]
43
- table = [[i+1, val] for i, val in enumerate(rounds)]
44
- exp, ana, dec = compute_outputs(rounds)
45
- return table, exp, ana, dec
46
 
47
  def add_round(state, new_val):
48
- """Append a new multiplier, keep only last 50, and refresh UI."""
49
  if new_val <= 0:
50
- # ignore invalid inputs (but you could show a warning – here we just return unchanged)
51
- return state + update_ui(state)[:3] # need to return state and outputs
52
  rounds = state.copy()
53
  rounds.append(new_val)
54
- if len(rounds) > 50:
55
- rounds = rounds[-50:]
56
- table, exp, ana, dec = update_ui(rounds)
57
- return rounds, table, exp, ana, dec
 
58
 
59
  def reset_rounds():
60
- """Reset to a fresh set of 20 random multipliers."""
61
- initial = [round(random.uniform(1.0, 3.0), 2) for _ in range(20)]
62
- table, exp, ana, dec = update_ui(initial)
63
- return initial, table, exp, ana, dec
64
 
65
- # ---------- Build the Gradio interface ----------
66
- with gr.Blocks(theme='dark', css="footer {visibility: hidden}") as demo:
67
- gr.Markdown("# AVOLD")
68
-
69
- # State: stores the list of multipliers
70
- rounds_state = gr.State([round(random.uniform(1.0, 3.0), 2) for _ in range(20)])
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
71
 
72
- # Input row
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
73
  with gr.Row():
74
- new_multiplier = gr.Number(label="New Multiplier", value=1.0, step=0.1)
75
- add_btn = gr.Button("Add Round")
76
-
77
- # Reset button
78
- reset_btn = gr.Button("Reset Data")
79
-
80
- # Three outputs in one row
81
  with gr.Row():
82
- expected_out = gr.Textbox(label="Expected Multiplier", interactive=False)
83
- analysis_out = gr.Textbox(label="Analysis", interactive=False)
84
- decision_out = gr.Textbox(label="Decision", interactive=False)
85
-
86
- # Table at the bottom
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
87
  rounds_table = gr.Dataframe(
88
- label="Last 50 Rounds",
89
- headers=["Round", "Multiplier"],
90
- row_count=10, # show 10 rows at a time (scrollable)
 
91
  )
92
-
93
- # Wire up the buttons
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
94
  add_btn.click(
95
  add_round,
96
  inputs=[rounds_state, new_multiplier],
97
- outputs=[rounds_state, rounds_table, expected_out, analysis_out, decision_out]
 
 
 
 
 
 
 
98
  )
99
-
 
100
  reset_btn.click(
101
  reset_rounds,
102
- outputs=[rounds_state, rounds_table, expected_out, analysis_out, decision_out]
 
 
 
 
 
 
 
103
  )
104
-
105
- # Initial load
106
  demo.load(
107
- lambda s: update_ui(s),
108
  inputs=[rounds_state],
109
- outputs=[rounds_table, expected_out, analysis_out, decision_out]
 
 
 
 
110
  )
111
 
112
- # Launch the app
113
  if __name__ == "__main__":
114
  demo.launch()
 
1
  import gradio as gr
2
  import random
3
  from statistics import mean
4
+ from datetime import datetime
5
+
6
+ # ---------- কনফিগারেশন ----------
7
+ MAX_ROUNDS = 50
8
+ DEFAULT_ROUNDS = 20
9
+ UPDATE_INTERVAL = 1 # সেকেন্ড
10
+
11
+ # পিঙ্ক জোন টাইম উইন্ডো (মিনিট)
12
+ PINK_WINDOWS = [
13
+ {"start": 55, "end": 57, "name": "প্রাইম পিঙ্ক", "multiplier": 1.9},
14
+ {"start": 59, "end": 1, "name": "প্রাইম পিঙ্ক", "multiplier": 1.9},
15
+ {"start": 18, "end": 20, "name": "পিঙ্ক জোন", "multiplier": 1.4},
16
+ {"start": 27, "end": 29, "name": "পিঙ্ক জোন", "multiplier": 1.4},
17
+ {"start": 38, "end": 40, "name": "পিঙ্ক জোন", "multiplier": 1.4},
18
+ {"start": 43, "end": 45, "name": "পিঙ্ক জোন", "multiplier": 1.4},
19
+ {"start": 48, "end": 50, "name": "পিঙ্ক জোন", "multiplier": 1.4},
20
+ ]
21
+
22
+ # ---------- হেল্পার ফাংশন ----------
23
+ def get_current_time_window():
24
+ """বর্তমান মিনিট অনুযায়ী পিঙ্ক জোন চেক করে"""
25
+ now = datetime.now()
26
+ minutes = now.minute
27
+
28
+ for window in PINK_WINDOWS:
29
+ if window["start"] <= window["end"]:
30
+ if minutes >= window["start"] and minutes <= window["end"]:
31
+ return window
32
+ else:
33
+ # ক্রস-আওয়ার বাউন্ডারি (যেমন 59-1)
34
+ if minutes >= window["start"] or minutes <= window["end"]:
35
+ return window
36
+ return None
37
+
38
+ def get_next_time_window():
39
+ """পরবর্তী পিঙ্ক জোন কত মিনিট পরে তা বের করে"""
40
+ now = datetime.now()
41
+ current_minutes = now.minute
42
+
43
+ nearest = None
44
+ min_distance = 60
45
+
46
+ for window in PINK_WINDOWS:
47
+ if window["start"] <= window["end"]:
48
+ if current_minutes <= window["start"]:
49
+ distance = window["start"] - current_minutes
50
+ else:
51
+ distance = (60 - current_minutes) + window["start"]
52
+ else:
53
+ if current_minutes >= window["start"]:
54
+ distance = (60 - current_minutes) + window["end"]
55
+ elif current_minutes <= window["end"]:
56
+ distance = 0
57
+ else:
58
+ distance = window["start"] - current_minutes
59
+
60
+ if distance < min_distance and distance > 0:
61
+ min_distance = distance
62
+ nearest = {"window": window, "minutes": distance}
63
+
64
+ return nearest
65
 
 
66
  def compute_outputs(rounds):
67
+ """এক্সপেক্টেড মাল্টিপ্লায়ার, অ্যানালাইসিস এবং ডিসিশন ক্যালকুলেট করে"""
68
  if not rounds:
69
+ return "0.0x", "কোন ডাটা নেই", "N/A", 0, "medium", False
70
+
71
+ # সর্বশেষ ১০টি রাউন্ড ব্যবহার করুন (অথবা কম)
72
  recent = rounds[-10:] if len(rounds) >= 10 else rounds
73
  avg = mean(recent)
74
+
75
+ # ছোট র‍্যান্ডম ফ্লাকচুয়েশন যোগ করুন (আসল গেমের টাইমার-ভিত্তিক র‍্যান্ডমনেস অনুকরণ)
76
+ expected = round(avg * random.uniform(0.92, 1.08), 2)
77
+
78
+ # ট্রেন্ড অ্যানালাইসিস
79
  if len(recent) >= 2:
80
+ trend_val = recent[-1] - recent[-2]
81
+ if trend_val > 0.15:
82
+ trend = "উর্ধ্বমুখী 📈"
83
+ elif trend_val < -0.15:
84
+ trend = "নিম্নমুখী 📉"
85
  else:
86
+ trend = "স্থিতিশীল ➡️"
87
  else:
88
+ trend = "পর্যাপ্ত ডাটা নেই"
89
+
90
+ # পিঙ্ক প্রোবাবিলিটি
91
+ pink_count = sum(1 for r in recent if r >= 3.0)
92
+ pink_prob = min(0.9, pink_count / len(recent) + 0.1)
93
+ is_pink_expected = pink_prob > 0.4 or expected > 2.8
94
+
95
+ # টাইম উইন্ডো চেক
96
+ current_window = get_current_time_window()
97
+ if current_window:
98
+ expected *= current_window["multiplier"]
99
+ expected = round(min(15.0, expected), 2)
100
+ pink_boost = "টাইম উইন্ডো একটিভ!"
101
  else:
102
+ pink_boost = ""
103
+
104
+ # কনফিডেন্স লেভেল
105
+ confidence = min(0.9, 0.5 + (len(rounds) / 100) + (pink_prob * 0.2))
106
+
107
+ # রিস্ক লেভেল
108
+ if expected > 5.0:
109
+ risk = "উচ্চ ⚠️"
110
+ elif expected > 2.5:
111
+ risk = "মাঝারি ⚖️"
112
+ else:
113
+ risk = "নিম্ন ✅"
114
+
115
+ # ডিসিশন
116
+ if is_pink_expected:
117
+ decision = "পিঙ্ক আশান্বিত 🌸"
118
+ elif expected > 3.0:
119
+ decision = "বড় মাল্টিপ্লায়ার 🚀"
120
+ elif expected > 1.8:
121
+ decision = "মাঝারি 💪"
122
+ else:
123
+ decision = "ছোট 🎯"
124
+
125
+ # অ্যানালাইসিস টেক্সট
126
+ analysis_parts = [trend]
127
+ if pink_boost:
128
+ analysis_parts.append(pink_boost)
129
+ if is_pink_expected:
130
+ analysis_parts.append("🌸 পিঙ্ক সম্ভাবনা")
131
+ analysis = " | ".join(analysis_parts)
132
+
133
+ return f"{expected}x", analysis, decision, confidence, risk, is_pink_expected
134
 
135
  def update_ui(rounds):
136
+ """UI আপডেট করার জন্য ডাটা প্রস্তুত করে"""
137
+ table = [[i+1, f"{val}x"] for i, val in enumerate(rounds)]
138
+ exp, ana, dec, conf, risk, pink = compute_outputs(rounds)
139
+ return table, exp, ana, dec, conf, risk, pink
 
140
 
141
  def add_round(state, new_val):
142
+ """নতুন মাল্টিপ্লায়ার যোগ করে"""
143
  if new_val <= 0:
144
+ return state + update_ui(state)[:6]
145
+
146
  rounds = state.copy()
147
  rounds.append(new_val)
148
+ if len(rounds) > MAX_ROUNDS:
149
+ rounds = rounds[-MAX_ROUNDS:]
150
+
151
+ table, exp, ana, dec, conf, risk, pink = update_ui(rounds)
152
+ return rounds, table, exp, ana, dec, conf, risk, pink
153
 
154
  def reset_rounds():
155
+ """ডাটা রিসেট করে"""
156
+ initial = [round(random.uniform(1.0, 3.5), 2) for _ in range(DEFAULT_ROUNDS)]
157
+ table, exp, ana, dec, conf, risk, pink = update_ui(initial)
158
+ return initial, table, exp, ana, dec, conf, risk, pink
159
 
160
+ def get_time_status():
161
+ """সময়-ভিত্তিক স্ট্যাটাস আপডেট করে"""
162
+ now = datetime.now()
163
+ time_str = now.strftime("%H:%M:%S")
164
+
165
+ current = get_current_time_window()
166
+ next_window = get_next_time_window()
167
+
168
+ if current:
169
+ status = f"🌸 {current['name']} একটিভ! 🌸"
170
+ detail = f"বুস্ট: +{int((current['multiplier']-1)*100)}%"
171
+ css_class = "active-window"
172
+ elif next_window and next_window["minutes"] <= 2:
173
+ status = f"⚠️ {next_window['window']['name']} আসছে {next_window['minutes']} মিনিটে"
174
+ detail = "প্রস্তুত হোন!"
175
+ css_class = "approaching-window"
176
+ else:
177
+ status = "পিঙ্ক জোনের অপেক্ষায়..."
178
+ detail = next_window and f"পরবর্তী: {next_window['window']['name']} {next_window['minutes']} মিনিটে" or ""
179
+ css_class = "waiting-window"
180
+
181
+ return time_str, status, detail, css_class
182
 
183
+ # ---------- গ্র্যাডিও ইন্টারফেস ----------
184
+ with gr.Blocks(theme='dark', css="""
185
+ footer {visibility: hidden}
186
+ .active-window { background: linear-gradient(135deg, #ff1493, #ff69b4) !important; }
187
+ .approaching-window { background: linear-gradient(135deg, #ffa726, #ff9800) !important; }
188
+ .waiting-window { background: linear-gradient(135deg, #1a1a2e, #16213e) !important; }
189
+ .pink-text { color: #ff1493 !important; }
190
+ .confidence-bar { height: 8px; background: #333; border-radius: 4px; overflow: hidden; }
191
+ .confidence-fill { height: 100%; background: linear-gradient(90deg, #00d4ff, #ff1493); transition: width 0.3s; }
192
+ .risk-badge { padding: 2px 8px; border-radius: 12px; font-size: 12px; font-weight: 600; }
193
+ .risk-high { background: #ff4757; color: white; }
194
+ .risk-medium { background: #ffa726; color: black; }
195
+ .risk-low { background: #66bb6a; color: white; }
196
+ .time-box { text-align: center; padding: 12px; border-radius: 8px; margin-bottom: 16px; transition: all 0.3s; }
197
+ """) as demo:
198
+
199
+ gr.Markdown("""
200
+ <div style="text-align: center; margin-bottom: 20px;">
201
+ <h1 style="color: #00d4ff; font-size: 48px; margin: 0;">✈️ AVOLD</h1>
202
+ <p style="color: #888; font-size: 14px;">এভিয়েটর রাউন্ড অ্যানালাইজার</p>
203
+ </div>
204
+ """)
205
+
206
+ # স্টেট
207
+ rounds_state = gr.State([round(random.uniform(1.0, 3.5), 2) for _ in range(DEFAULT_ROUNDS)])
208
+
209
+ # টাইম সেকশন (ডায়নামিক)
210
  with gr.Row():
211
+ time_box = gr.HTML(label="টাইম স্ট্যাটাস")
212
+
213
+ # ইনপুট রো
 
 
 
 
214
  with gr.Row():
215
+ new_multiplier = gr.Number(
216
+ label="নতুন মাল্টিপ্লায়ার",
217
+ value=1.0,
218
+ step=0.1,
219
+ minimum=1.0,
220
+ maximum=100.0
221
+ )
222
+ add_btn = gr.Button("➕ যোগ করুন", variant="primary")
223
+
224
+ # রিসেট বাটন
225
+ reset_btn = gr.Button("🔄 রিসেট ডাটা", variant="secondary")
226
+
227
+ # তিনটি আউটপুট এক লাইনে
228
+ with gr.Row():
229
+ expected_out = gr.Textbox(label="📊 এক্সপেক্টেড", interactive=False, elem_classes="pink-text")
230
+ analysis_out = gr.Textbox(label="📈 অ্যানালাইসিস", interactive=False)
231
+ decision_out = gr.Textbox(label="🎯 ডিসিশন", interactive=False)
232
+
233
+ # কনফিডেন্স এবং রিস্ক
234
+ with gr.Row():
235
+ with gr.Column(scale=3):
236
+ confidence_bar = gr.HTML(label="কনফিডেন্স")
237
+ with gr.Column(scale=1):
238
+ risk_out = gr.Textbox(label="রিস্ক লেভেল", interactive=False)
239
+
240
+ # টেবিল
241
  rounds_table = gr.Dataframe(
242
+ label="📜 শেষ ৫০ রাউন্ড",
243
+ headers=["রাউন্ড", "মাল্টিপ্লায়ার"],
244
+ row_count=10,
245
+ interactive=False
246
  )
247
+
248
+ # হিডেন স্টেট
249
+ pink_state = gr.State(False)
250
+ conf_state = gr.State(0.5)
251
+
252
+ # ---------- ইভেন্ট হ্যান্ডলার ----------
253
+ def update_time_display():
254
+ time_str, status, detail, css_class = get_time_status()
255
+ return f"""
256
+ <div class="time-box {css_class}">
257
+ <div style="font-size: 24px; font-weight: 700;">{time_str}</div>
258
+ <div style="font-size: 16px; font-weight: 600;">{status}</div>
259
+ <div style="font-size: 12px; opacity: 0.9;">{detail}</div>
260
+ </div>
261
+ """
262
+
263
+ def update_confidence_display(conf, is_pink):
264
+ color = "pink-text" if is_pink else ""
265
+ return f"""
266
+ <div>
267
+ <div style="display: flex; justify-content: space-between; margin-bottom: 4px;">
268
+ <span class="{color}">এমএল কনফিডেন্স: {int(conf*100)}%</span>
269
+ <span class="{color}">{'🌸 পিঙ্ক মোড' if is_pink else ''}</span>
270
+ </div>
271
+ <div class="confidence-bar">
272
+ <div class="confidence-fill" style="width: {int(conf*100)}%;"></div>
273
+ </div>
274
+ </div>
275
+ """
276
+
277
+ # টাইম আপডেট (প্রতি সেকেন্ড)
278
+ demo.load(
279
+ fn=lambda: (update_time_display(),),
280
+ outputs=[time_box],
281
+ every=UPDATE_INTERVAL
282
+ )
283
+
284
+ # অ্যাড বাটন
285
  add_btn.click(
286
  add_round,
287
  inputs=[rounds_state, new_multiplier],
288
+ outputs=[rounds_state, rounds_table, expected_out, analysis_out, decision_out, conf_state, risk_out, pink_state]
289
+ ).then(
290
+ lambda conf, pink: update_confidence_display(conf, pink),
291
+ inputs=[conf_state, pink_state],
292
+ outputs=[confidence_bar]
293
+ ).then(
294
+ lambda: (update_time_display(),),
295
+ outputs=[time_box]
296
  )
297
+
298
+ # রিসেট বাটন
299
  reset_btn.click(
300
  reset_rounds,
301
+ outputs=[rounds_state, rounds_table, expected_out, analysis_out, decision_out, conf_state, risk_out, pink_state]
302
+ ).then(
303
+ lambda conf, pink: update_confidence_display(conf, pink),
304
+ inputs=[conf_state, pink_state],
305
+ outputs=[confidence_bar]
306
+ ).then(
307
+ lambda: (update_time_display(),),
308
+ outputs=[time_box]
309
  )
310
+
311
+ # ইনিশিয়াল লোড
312
  demo.load(
313
+ lambda s: update_ui(s) + (0.5, False, ""),
314
  inputs=[rounds_state],
315
+ outputs=[rounds_table, expected_out, analysis_out, decision_out, conf_state, risk_out, pink_state, confidence_bar]
316
+ ).then(
317
+ lambda conf, pink: update_confidence_display(conf, pink),
318
+ inputs=[conf_state, pink_state],
319
+ outputs=[confidence_bar]
320
  )
321
 
322
+ # ---------- অ্যাপ রান ----------
323
  if __name__ == "__main__":
324
  demo.launch()