Update app.py
Browse files
app.py
CHANGED
|
@@ -2,11 +2,11 @@ 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 = [
|
|
@@ -19,6 +19,24 @@ PINK_WINDOWS = [
|
|
| 19 |
{"start": 48, "end": 50, "name": "পিঙ্ক জোন", "multiplier": 1.4},
|
| 20 |
]
|
| 21 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 22 |
# ---------- হেল্পার ফাংশন ----------
|
| 23 |
def get_current_time_window():
|
| 24 |
"""বর্তমান মিনিট অনুযায়ী পিঙ্ক জোন চেক করে"""
|
|
@@ -57,7 +75,7 @@ def get_next_time_window():
|
|
| 57 |
else:
|
| 58 |
distance = window["start"] - current_minutes
|
| 59 |
|
| 60 |
-
if
|
| 61 |
min_distance = distance
|
| 62 |
nearest = {"window": window, "minutes": distance}
|
| 63 |
|
|
@@ -72,7 +90,7 @@ def compute_outputs(rounds):
|
|
| 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 |
# ট্রেন্ড অ্যানালাইসিস
|
|
@@ -97,7 +115,7 @@ def compute_outputs(rounds):
|
|
| 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 |
|
|
@@ -175,40 +193,54 @@ def get_time_status():
|
|
| 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
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 182 |
|
| 183 |
# ---------- গ্র্যাডিও ইন্��ারফেস ----------
|
| 184 |
-
with gr.Blocks(
|
| 185 |
-
|
| 186 |
-
.
|
| 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 |
-
|
| 211 |
-
time_box = gr.HTML(label="টাইম স্ট্যাটাস")
|
| 212 |
|
| 213 |
# ইনপুট রো
|
| 214 |
with gr.Row():
|
|
@@ -226,14 +258,14 @@ with gr.Blocks(theme='dark', css="""
|
|
| 226 |
|
| 227 |
# তিনটি আউটপুট এক লাইনে
|
| 228 |
with gr.Row():
|
| 229 |
-
expected_out = gr.Textbox(label="📊 এক্সপেক্টেড", interactive=False
|
| 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 |
-
|
| 237 |
with gr.Column(scale=1):
|
| 238 |
risk_out = gr.Textbox(label="রিস্ক লেভেল", interactive=False)
|
| 239 |
|
|
@@ -245,41 +277,7 @@ with gr.Blocks(theme='dark', css="""
|
|
| 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(
|
|
@@ -287,12 +285,12 @@ with gr.Blocks(theme='dark', css="""
|
|
| 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 |
-
|
| 291 |
inputs=[conf_state, pink_state],
|
| 292 |
-
outputs=[
|
| 293 |
).then(
|
| 294 |
-
|
| 295 |
-
outputs=[
|
| 296 |
)
|
| 297 |
|
| 298 |
# রিসেট বাটন
|
|
@@ -300,25 +298,33 @@ with gr.Blocks(theme='dark', css="""
|
|
| 300 |
reset_rounds,
|
| 301 |
outputs=[rounds_state, rounds_table, expected_out, analysis_out, decision_out, conf_state, risk_out, pink_state]
|
| 302 |
).then(
|
| 303 |
-
|
| 304 |
inputs=[conf_state, pink_state],
|
| 305 |
-
outputs=[
|
| 306 |
).then(
|
| 307 |
-
|
| 308 |
-
outputs=[
|
| 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
|
| 316 |
).then(
|
| 317 |
-
|
| 318 |
inputs=[conf_state, pink_state],
|
| 319 |
-
outputs=[
|
|
|
|
|
|
|
|
|
|
| 320 |
)
|
| 321 |
|
| 322 |
# ---------- অ্যাপ রান ----------
|
| 323 |
if __name__ == "__main__":
|
| 324 |
-
demo.launch(
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 2 |
import random
|
| 3 |
from statistics import mean
|
| 4 |
from datetime import datetime
|
| 5 |
+
import time
|
| 6 |
|
| 7 |
# ---------- কনফিগারেশন ----------
|
| 8 |
MAX_ROUNDS = 50
|
| 9 |
DEFAULT_ROUNDS = 20
|
|
|
|
| 10 |
|
| 11 |
# পিঙ্ক জোন টাইম উইন্ডো (মিনিট)
|
| 12 |
PINK_WINDOWS = [
|
|
|
|
| 19 |
{"start": 48, "end": 50, "name": "পিঙ্ক জোন", "multiplier": 1.4},
|
| 20 |
]
|
| 21 |
|
| 22 |
+
# CSS স্টাইল
|
| 23 |
+
CUSTOM_CSS = """
|
| 24 |
+
footer {visibility: hidden}
|
| 25 |
+
.active-window { background: linear-gradient(135deg, #ff1493, #ff69b4) !important; color: white !important; }
|
| 26 |
+
.approaching-window { background: linear-gradient(135deg, #ffa726, #ff9800) !important; color: white !important; }
|
| 27 |
+
.waiting-window { background: linear-gradient(135deg, #1a1a2e, #16213e) !important; color: white !important; }
|
| 28 |
+
.pink-text { color: #ff1493 !important; font-weight: bold !important; }
|
| 29 |
+
.confidence-bar { height: 8px; background: #333; border-radius: 4px; overflow: hidden; margin: 5px 0; }
|
| 30 |
+
.confidence-fill { height: 100%; background: linear-gradient(90deg, #00d4ff, #ff1493); transition: width 0.3s; }
|
| 31 |
+
.risk-badge { padding: 2px 8px; border-radius: 12px; font-size: 12px; font-weight: 600; }
|
| 32 |
+
.risk-high { background: #ff4757; color: white; padding: 2px 8px; border-radius: 12px; }
|
| 33 |
+
.risk-medium { background: #ffa726; color: black; padding: 2px 8px; border-radius: 12px; }
|
| 34 |
+
.risk-low { background: #66bb6a; color: white; padding: 2px 8px; border-radius: 12px; }
|
| 35 |
+
.time-box { text-align: center; padding: 15px; border-radius: 10px; margin-bottom: 20px; transition: all 0.3s; font-weight: 500; }
|
| 36 |
+
.gradio-container { background: #0a0a0f !important; }
|
| 37 |
+
h1 { text-align: center; margin-bottom: 10px; }
|
| 38 |
+
"""
|
| 39 |
+
|
| 40 |
# ---------- হেল্পার ফাংশন ----------
|
| 41 |
def get_current_time_window():
|
| 42 |
"""বর্তমান মিনিট অনুযায়ী পিঙ্ক জোন চেক করে"""
|
|
|
|
| 75 |
else:
|
| 76 |
distance = window["start"] - current_minutes
|
| 77 |
|
| 78 |
+
if 0 < distance < min_distance:
|
| 79 |
min_distance = distance
|
| 80 |
nearest = {"window": window, "minutes": distance}
|
| 81 |
|
|
|
|
| 90 |
recent = rounds[-10:] if len(rounds) >= 10 else rounds
|
| 91 |
avg = mean(recent)
|
| 92 |
|
| 93 |
+
# ছোট র্যান্ডম ফ্লাকচুয়েশন যোগ করুন
|
| 94 |
expected = round(avg * random.uniform(0.92, 1.08), 2)
|
| 95 |
|
| 96 |
# ট্রেন্ড অ্যানালাইসিস
|
|
|
|
| 115 |
if current_window:
|
| 116 |
expected *= current_window["multiplier"]
|
| 117 |
expected = round(min(15.0, expected), 2)
|
| 118 |
+
pink_boost = f"✨ {current_window['name']} একটিভ!"
|
| 119 |
else:
|
| 120 |
pink_boost = ""
|
| 121 |
|
|
|
|
| 193 |
css_class = "approaching-window"
|
| 194 |
else:
|
| 195 |
status = "পিঙ্ক জোনের অপেক্ষায়..."
|
| 196 |
+
detail = next_window and f"পরবর্তী: {next_window['window']['name']} {next_window['minutes']} মিনিটে" or "কোন উইন্ডো নেই"
|
| 197 |
css_class = "waiting-window"
|
| 198 |
|
| 199 |
+
return f"""
|
| 200 |
+
<div class="time-box {css_class}">
|
| 201 |
+
<div style="font-size: 24px; font-weight: 700;">{time_str}</div>
|
| 202 |
+
<div style="font-size: 16px; font-weight: 600; margin: 5px 0;">{status}</div>
|
| 203 |
+
<div style="font-size: 12px; opacity: 0.9;">{detail}</div>
|
| 204 |
+
</div>
|
| 205 |
+
"""
|
| 206 |
+
|
| 207 |
+
def update_time_display():
|
| 208 |
+
"""টাইম ডিসপ্লে আপডেট করে"""
|
| 209 |
+
return get_time_status()
|
| 210 |
+
|
| 211 |
+
def update_confidence_display(conf, is_pink):
|
| 212 |
+
"""কনফিডেন্স বার আপডেট করে"""
|
| 213 |
+
color_class = "pink-text" if is_pink else ""
|
| 214 |
+
pink_text = "🌸 পিঙ্ক মোড" if is_pink else ""
|
| 215 |
+
return f"""
|
| 216 |
+
<div style="margin: 10px 0;">
|
| 217 |
+
<div style="display: flex; justify-content: space-between; margin-bottom: 4px;">
|
| 218 |
+
<span class="{color_class}">এমএল কনফিডেন্স: {int(conf*100)}%</span>
|
| 219 |
+
<span class="{color_class}">{pink_text}</span>
|
| 220 |
+
</div>
|
| 221 |
+
<div class="confidence-bar">
|
| 222 |
+
<div class="confidence-fill" style="width: {int(conf*100)}%;"></div>
|
| 223 |
+
</div>
|
| 224 |
+
</div>
|
| 225 |
+
"""
|
| 226 |
|
| 227 |
# ---------- গ্র্যাডিও ইন্��ারফেস ----------
|
| 228 |
+
with gr.Blocks() as demo:
|
| 229 |
+
# হেডার
|
| 230 |
+
gr.HTML("""
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 231 |
<div style="text-align: center; margin-bottom: 20px;">
|
| 232 |
+
<h1 style="color: #00d4ff; font-size: 48px; margin: 0; text-shadow: 0 0 10px #00d4ff;">✈️ AVOLD</h1>
|
| 233 |
<p style="color: #888; font-size: 14px;">এভিয়েটর রাউন্ড অ্যানালাইজার</p>
|
| 234 |
</div>
|
| 235 |
""")
|
| 236 |
|
| 237 |
# স্টেট
|
| 238 |
rounds_state = gr.State([round(random.uniform(1.0, 3.5), 2) for _ in range(DEFAULT_ROUNDS)])
|
| 239 |
+
pink_state = gr.State(False)
|
| 240 |
+
conf_state = gr.State(0.5)
|
| 241 |
|
| 242 |
+
# টাইম সেকশন
|
| 243 |
+
time_html = gr.HTML(value=get_time_status())
|
|
|
|
| 244 |
|
| 245 |
# ইনপুট রো
|
| 246 |
with gr.Row():
|
|
|
|
| 258 |
|
| 259 |
# তিনটি আউটপুট এক লাইনে
|
| 260 |
with gr.Row():
|
| 261 |
+
expected_out = gr.Textbox(label="📊 এক্সপেক্টেড", interactive=False)
|
| 262 |
analysis_out = gr.Textbox(label="📈 অ্যানালাইসিস", interactive=False)
|
| 263 |
decision_out = gr.Textbox(label="🎯 ডিসিশন", interactive=False)
|
| 264 |
|
| 265 |
# কনফিডেন্স এবং রিস্ক
|
| 266 |
with gr.Row():
|
| 267 |
with gr.Column(scale=3):
|
| 268 |
+
confidence_html = gr.HTML(value=update_confidence_display(0.5, False))
|
| 269 |
with gr.Column(scale=1):
|
| 270 |
risk_out = gr.Textbox(label="রিস্ক লেভেল", interactive=False)
|
| 271 |
|
|
|
|
| 277 |
interactive=False
|
| 278 |
)
|
| 279 |
|
|
|
|
|
|
|
|
|
|
|
|
|
| 280 |
# ---------- ইভেন্ট হ্যান্ডলার ----------
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 281 |
|
| 282 |
# অ্যাড বাটন
|
| 283 |
add_btn.click(
|
|
|
|
| 285 |
inputs=[rounds_state, new_multiplier],
|
| 286 |
outputs=[rounds_state, rounds_table, expected_out, analysis_out, decision_out, conf_state, risk_out, pink_state]
|
| 287 |
).then(
|
| 288 |
+
update_confidence_display,
|
| 289 |
inputs=[conf_state, pink_state],
|
| 290 |
+
outputs=[confidence_html]
|
| 291 |
).then(
|
| 292 |
+
update_time_display,
|
| 293 |
+
outputs=[time_html]
|
| 294 |
)
|
| 295 |
|
| 296 |
# রিসেট বাটন
|
|
|
|
| 298 |
reset_rounds,
|
| 299 |
outputs=[rounds_state, rounds_table, expected_out, analysis_out, decision_out, conf_state, risk_out, pink_state]
|
| 300 |
).then(
|
| 301 |
+
update_confidence_display,
|
| 302 |
inputs=[conf_state, pink_state],
|
| 303 |
+
outputs=[confidence_html]
|
| 304 |
).then(
|
| 305 |
+
update_time_display,
|
| 306 |
+
outputs=[time_html]
|
| 307 |
)
|
| 308 |
|
| 309 |
# ইনিশিয়াল লোড
|
| 310 |
demo.load(
|
| 311 |
+
fn=lambda s: update_ui(s) + (0.5, False),
|
| 312 |
inputs=[rounds_state],
|
| 313 |
+
outputs=[rounds_table, expected_out, analysis_out, decision_out, conf_state, risk_out, pink_state]
|
| 314 |
).then(
|
| 315 |
+
update_confidence_display,
|
| 316 |
inputs=[conf_state, pink_state],
|
| 317 |
+
outputs=[confidence_html]
|
| 318 |
+
).then(
|
| 319 |
+
update_time_display,
|
| 320 |
+
outputs=[time_html]
|
| 321 |
)
|
| 322 |
|
| 323 |
# ---------- অ্যাপ রান ----------
|
| 324 |
if __name__ == "__main__":
|
| 325 |
+
demo.launch(
|
| 326 |
+
server_name="0.0.0.0",
|
| 327 |
+
server_port=7860,
|
| 328 |
+
theme='dark',
|
| 329 |
+
css=CUSTOM_CSS
|
| 330 |
+
)
|