testrro commited on
Commit
9a54213
·
verified ·
1 Parent(s): a27b7f9

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +144 -52
app.py CHANGED
@@ -3,7 +3,6 @@ import numpy as np
3
  import pandas as pd
4
  from datetime import datetime
5
  import random
6
- import json
7
  from collections import defaultdict
8
  import math
9
  import traceback
@@ -155,7 +154,7 @@ class SequenceAnalyzer:
155
 
156
  diffs = [abs(seq1[i] - seq2[i]) / (max(seq1[i], seq2[i]) + 0.1)
157
  for i in range(len(seq1))]
158
- avg_diff = np.mean(diffs)
159
  return max(0, 1 - avg_diff)
160
 
161
  def predict(self, history):
@@ -394,9 +393,6 @@ class EnsemblePredictor:
394
  confidences = [p.get('confidence', 0.3) for p in predictions.values()]
395
  avg_confidence = np.mean(confidences) if confidences else 0.3
396
 
397
- # প্যাটার্ন মেমরি বুস্ট (সিম্পলিফাইড)
398
- pattern_boost = 0
399
-
400
  # পিঙ্ক সম্ভাবনা
401
  pink_prob = self.calculate_pink_probability(history, predictions, time_window)
402
  is_pink_expected = pink_prob > 0.4
@@ -440,7 +436,7 @@ class EnsemblePredictor:
440
  'statisticalModel': '📊 স্ট্যাট'
441
  }
442
  display_name = model_names.get(name, name)
443
- lines.append(f"{display_name}: {pred['prediction']:.2f}x (কনফি: {int(pred['confidence']*100)}%) - {pred.get('analysis', '')[:30]}")
444
  return "\n".join(lines)
445
 
446
  def get_default_prediction(self):
@@ -481,13 +477,15 @@ class EnsemblePredictor:
481
  factors.append(time_window['probability'])
482
 
483
  # মডেল কনসেনসাস
484
- pink_predictions = sum(1 for p in predictions.values()
485
- if p.get('prediction', 1.5) >= CONFIG["PINK_THRESHOLD"])
486
- factors.append(pink_predictions / len(predictions) if predictions else 0)
 
487
 
488
  # হিস্টোরিক্যাল ফ্যাক্টর
489
- recent_pinks = sum(1 for v in history[:20] if v >= CONFIG["PINK_THRESHOLD"])
490
- factors.append(min(0.9, recent_pinks / 20 if history else 0))
 
491
 
492
  return np.mean(factors) if factors else 0.2
493
 
@@ -579,7 +577,7 @@ class AviatorPredictorApp:
579
  return self.last_prediction
580
 
581
  def get_history_table(self):
582
- """হিস্ট্রি টেবিল রিটার্ন করে"""
583
  return [[i+1, f"{val:.2f}x"] for i, val in enumerate(self.history[:50])]
584
 
585
  def get_time_status(self):
@@ -658,39 +656,123 @@ class AviatorPredictorApp:
658
  """
659
 
660
 
661
- # ==================== গ্র্যডিও ইন্টারফেস ====================
662
-
663
- # কাস্টম সিএসএস
664
  CUSTOM_CSS = """
 
 
 
 
 
665
  footer {visibility: hidden}
666
- .active-window { background: linear-gradient(135deg, #ff1493, #ff69b4) !important; color: white !important; }
667
- .approaching-window { background: linear-gradient(135deg, #ffa726, #ff9800) !important; color: white !important; }
668
- .waiting-window { background: linear-gradient(135deg, #1a1a2e, #16213e) !important; color: white !important; }
669
- .pink-text { color: #ff1493 !important; font-weight: bold !important; }
670
- .confidence-bar { height: 8px; background: #333; border-radius: 4px; overflow: hidden; margin: 5px 0; }
671
- .confidence-fill { height: 100%; background: linear-gradient(90deg, #00d4ff, #ff1493); transition: width 0.3s; }
672
- .time-box { text-align: center; padding: 15px; border-radius: 10px; margin-bottom: 20px; transition: all 0.3s; font-weight: 500; }
673
- .prediction-interval { font-size: 32px; font-weight: 700; text-align: center; margin: 10px 0; }
674
- .prediction-interval.pink-mode { color: #ff1493; text-shadow: 0 0 10px #ff1493; }
675
- .interval-lower { color: #00d4ff; }
676
- .interval-upper { color: #ffa726; }
677
- .interval-separator { color: white; margin: 0 10px; }
678
- .model-details { background: rgba(255,255,255,0.1); border-radius: 8px; padding: 10px; margin: 10px 0; font-size: 12px; font-family: monospace; white-space: pre-line; }
679
- .gradio-container { background: #0a0a0f !important; }
680
- h1 { text-align: center; margin-bottom: 10px; }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
681
  """
682
 
 
 
683
  # অ্যাপ ইনিশিয়ালাইজ
684
  app = AviatorPredictorApp()
685
  app.reset() # শুরুতেই কিছু ডাটা জেনারেট করে
686
 
687
  # গ্র্যাডিও ইন্টারফেস
688
- with gr.Blocks() as demo:
689
  # হেডার
690
  gr.HTML("""
691
  <div style="text-align: center; margin-bottom: 20px;">
692
  <h1 style="color: #00d4ff; font-size: 48px; margin: 0; text-shadow: 0 0 10px #00d4ff;">✈️ AVOLD ML</h1>
693
- <p style="color: #888; font-size: 14px;">এনসেম্বল এমএল এভিয়েটর প্রেডিক্টর v2.0</p>
694
  </div>
695
  """)
696
 
@@ -750,7 +832,7 @@ with gr.Blocks() as demo:
750
 
751
  # ---------- আপডেট ফাংশন ----------
752
  def update_all():
753
- """সব ডিসপ্লে আপডেট করে"""
754
  try:
755
  pred = app.get_prediction()
756
  history_table = app.get_history_table()
@@ -784,26 +866,31 @@ with gr.Blocks() as demo:
784
  model_text = pred.get('model_details', 'কোন ডাটা নেই')
785
 
786
  return [
787
- history_table,
788
- time_status,
789
- confidence,
790
- prediction_html_str,
791
- f"{pred.get('prediction', 1.5):.2f}x",
792
- pred.get('analysis', 'অ্যানালাইসিস নেই'),
793
- decision,
794
- pred.get('risk', 'মাঝারি ⚖️'),
795
- pink_prob_text,
796
- model_text
797
  ]
798
  except Exception as e:
799
  print(f"Update error: {e}")
800
  traceback.print_exc()
801
  # এরর হলে ডিফল্ট ভ্যালু রিটার্ন
 
 
 
 
 
802
  return [
803
- [[1, "1.00x"]],
804
- app.get_time_status(),
805
- app.get_confidence_html(),
806
- '<div class="prediction-interval"><span class="interval-lower">1.30x</span><span class="interval-separator">—</span><span class="interval-upper">1.70x</span></div>',
807
  "1.50x",
808
  "আপডেট এরর",
809
  "ছোট 🎯",
@@ -814,7 +901,10 @@ with gr.Blocks() as demo:
814
 
815
  # অ্যাড বাটন ক্লিক
816
  add_btn.click(
817
- fn=lambda x: (app.add_round(x),) + tuple(update_all()),
 
 
 
818
  inputs=[new_multiplier],
819
  outputs=[rounds_table, time_html, confidence_html, prediction_html,
820
  expected_out, analysis_out, decision_out, risk_out,
@@ -823,7 +913,10 @@ with gr.Blocks() as demo:
823
 
824
  # রিসেট বাটন ক্লিক
825
  reset_btn.click(
826
- fn=lambda: (app.reset(),) + tuple(update_all()),
 
 
 
827
  outputs=[rounds_table, time_html, confidence_html, prediction_html,
828
  expected_out, analysis_out, decision_out, risk_out,
829
  pink_prob_out, model_details]
@@ -831,7 +924,7 @@ with gr.Blocks() as demo:
831
 
832
  # ইনিশিয়াল লোড
833
  demo.load(
834
- fn=lambda: update_all(),
835
  outputs=[rounds_table, time_html, confidence_html, prediction_html,
836
  expected_out, analysis_out, decision_out, risk_out,
837
  pink_prob_out, model_details]
@@ -842,6 +935,5 @@ if __name__ == "__main__":
842
  demo.launch(
843
  server_name="0.0.0.0",
844
  server_port=7860,
845
- theme='dark',
846
- css=CUSTOM_CSS
847
  )
 
3
  import pandas as pd
4
  from datetime import datetime
5
  import random
 
6
  from collections import defaultdict
7
  import math
8
  import traceback
 
154
 
155
  diffs = [abs(seq1[i] - seq2[i]) / (max(seq1[i], seq2[i]) + 0.1)
156
  for i in range(len(seq1))]
157
+ avg_diff = np.mean(diffs) if diffs else 1
158
  return max(0, 1 - avg_diff)
159
 
160
  def predict(self, history):
 
393
  confidences = [p.get('confidence', 0.3) for p in predictions.values()]
394
  avg_confidence = np.mean(confidences) if confidences else 0.3
395
 
 
 
 
396
  # পিঙ্ক সম্ভাবনা
397
  pink_prob = self.calculate_pink_probability(history, predictions, time_window)
398
  is_pink_expected = pink_prob > 0.4
 
436
  'statisticalModel': '📊 স্ট্যাট'
437
  }
438
  display_name = model_names.get(name, name)
439
+ lines.append(f"{display_name}: {pred.get('prediction', 1.5):.2f}x (কনফি: {int(pred.get('confidence', 0)*100)}%) - {pred.get('analysis', '')[:30]}")
440
  return "\n".join(lines)
441
 
442
  def get_default_prediction(self):
 
477
  factors.append(time_window['probability'])
478
 
479
  # মডেল কনসেনসাস
480
+ if predictions:
481
+ pink_predictions = sum(1 for p in predictions.values()
482
+ if p.get('prediction', 1.5) >= CONFIG["PINK_THRESHOLD"])
483
+ factors.append(pink_predictions / len(predictions))
484
 
485
  # হিস্টোরিক্যাল ফ্যাক্টর
486
+ if history:
487
+ recent_pinks = sum(1 for v in history[:20] if v >= CONFIG["PINK_THRESHOLD"])
488
+ factors.append(min(0.9, recent_pinks / 20))
489
 
490
  return np.mean(factors) if factors else 0.2
491
 
 
577
  return self.last_prediction
578
 
579
  def get_history_table(self):
580
+ """হিস্ট্রি টেবিল রিটার্ন করে (শুধু ডাটা, কোন বুলিয়ান না)"""
581
  return [[i+1, f"{val:.2f}x"] for i, val in enumerate(self.history[:50])]
582
 
583
  def get_time_status(self):
 
656
  """
657
 
658
 
659
+ # ==================== ্টিএসএস ====================
 
 
660
  CUSTOM_CSS = """
661
+ /* ডার্ক মোড বেস */
662
+ .gradio-container {
663
+ background: #0a0a0f !important;
664
+ color: #ffffff !important;
665
+ }
666
  footer {visibility: hidden}
667
+
668
+ /* ট��ইম বক্স স্টাইল */
669
+ .time-box {
670
+ text-align: center;
671
+ padding: 15px;
672
+ border-radius: 10px;
673
+ margin-bottom: 20px;
674
+ transition: all 0.3s;
675
+ font-weight: 500;
676
+ }
677
+ .active-window {
678
+ background: linear-gradient(135deg, #ff1493, #ff69b4) !important;
679
+ color: white !important;
680
+ box-shadow: 0 0 20px #ff1493;
681
+ }
682
+ .approaching-window {
683
+ background: linear-gradient(135deg, #ffa726, #ff9800) !important;
684
+ color: white !important;
685
+ box-shadow: 0 0 20px #ffa726;
686
+ }
687
+ .waiting-window {
688
+ background: linear-gradient(135deg, #1a1a2e, #16213e) !important;
689
+ color: white !important;
690
+ border: 1px solid #00d4ff;
691
+ }
692
+
693
+ /* পিঙ্ক টেক্সট */
694
+ .pink-text {
695
+ color: #ff1493 !important;
696
+ font-weight: bold !important;
697
+ }
698
+
699
+ /* কনফিডেন্স বার */
700
+ .confidence-bar {
701
+ height: 8px;
702
+ background: #333;
703
+ border-radius: 4px;
704
+ overflow: hidden;
705
+ margin: 5px 0;
706
+ }
707
+ .confidence-fill {
708
+ height: 100%;
709
+ background: linear-gradient(90deg, #00d4ff, #ff1493);
710
+ transition: width 0.3s;
711
+ }
712
+
713
+ /* প্রেডিকশন ইন্টারভ্যাল */
714
+ .prediction-interval {
715
+ font-size: 32px;
716
+ font-weight: 700;
717
+ text-align: center;
718
+ margin: 10px 0;
719
+ padding: 15px;
720
+ background: rgba(255,255,255,0.05);
721
+ border-radius: 10px;
722
+ }
723
+ .prediction-interval.pink-mode {
724
+ color: #ff1493;
725
+ text-shadow: 0 0 10px #ff1493;
726
+ }
727
+ .interval-lower {
728
+ color: #00d4ff;
729
+ }
730
+ .interval-upper {
731
+ color: #ffa726;
732
+ }
733
+ .interval-separator {
734
+ color: white;
735
+ margin: 0 10px;
736
+ }
737
+
738
+ /* টেক্সটবক্স স্টাইল */
739
+ .gr-box {
740
+ border: 1px solid #333 !important;
741
+ background: rgba(255,255,255,0.05) !important;
742
+ }
743
+ .gr-box label {
744
+ color: #00d4ff !important;
745
+ }
746
+
747
+ /* বাটন স্টাইল */
748
+ .gr-button-primary {
749
+ background: linear-gradient(135deg, #00d4ff, #0088ff) !important;
750
+ border: none !important;
751
+ }
752
+ .gr-button-secondary {
753
+ background: rgba(255,255,255,0.1) !important;
754
+ border: 1px solid #00d4ff !important;
755
+ }
756
+
757
+ /* ডাটাফ্রেম */
758
+ .gr-dataframe {
759
+ background: rgba(255,255,255,0.05) !important;
760
+ }
761
  """
762
 
763
+ # ==================== গ্র্যাডিও ইন্টারফেস ====================
764
+
765
  # অ্যাপ ইনিশিয়ালাইজ
766
  app = AviatorPredictorApp()
767
  app.reset() # শুরুতেই কিছু ডাটা জেনারেট করে
768
 
769
  # গ্র্যাডিও ইন্টারফেস
770
+ with gr.Blocks(css=CUSTOM_CSS) as demo:
771
  # হেডার
772
  gr.HTML("""
773
  <div style="text-align: center; margin-bottom: 20px;">
774
  <h1 style="color: #00d4ff; font-size: 48px; margin: 0; text-shadow: 0 0 10px #00d4ff;">✈️ AVOLD ML</h1>
775
+ <p style="color: #888; font-size: 14px;">এনসেম্বল এমএল এভিয়েটর প্রেডিক্টর v3.0</p>
776
  </div>
777
  """)
778
 
 
832
 
833
  # ---------- আপডেট ফাংশন ----------
834
  def update_all():
835
+ """সব ডিসপ্লে আপডেট করে - শুধু ডাটা রিটার্ন করে, কোন বুলিয়ান না"""
836
  try:
837
  pred = app.get_prediction()
838
  history_table = app.get_history_table()
 
866
  model_text = pred.get('model_details', 'কোন ডাটা নেই')
867
 
868
  return [
869
+ history_table, # dataframe
870
+ time_status, # html
871
+ confidence, # html
872
+ prediction_html_str, # html
873
+ f"{pred.get('prediction', 1.5):.2f}x", # textbox
874
+ pred.get('analysis', 'অ্যানালাইসিস নেই'), # textbox
875
+ decision, # textbox
876
+ pred.get('risk', 'মাঝারি ⚖️'), # textbox
877
+ pink_prob_text, # textbox
878
+ model_text # textbox
879
  ]
880
  except Exception as e:
881
  print(f"Update error: {e}")
882
  traceback.print_exc()
883
  # এরর হলে ডিফল্ট ভ্যালু রিটার্ন
884
+ default_table = [[1, "1.00x"]]
885
+ default_time = '<div class="time-box waiting-window"><div style="font-size:24px;">--:--:--</div><div>আপডেট এরর</div></div>'
886
+ default_conf = '<div>এমএল কনফিডেন্স: 0%</div>'
887
+ default_pred = '<div class="prediction-interval"><span class="interval-lower">1.30x</span><span class="interval-separator">—</span><span class="interval-upper">1.70x</span></div>'
888
+
889
  return [
890
+ default_table,
891
+ default_time,
892
+ default_conf,
893
+ default_pred,
894
  "1.50x",
895
  "আপডেট এরর",
896
  "ছোট 🎯",
 
901
 
902
  # অ্যাড বাটন ক্লিক
903
  add_btn.click(
904
+ fn=lambda x: (
905
+ app.add_round(x), # এইটা True রিটার্ন করে, কিন্তু আমরা ইউজ করছি না
906
+ *update_all() # শুধু আপডেট ডাটা রিটার্ন করছি
907
+ )[-10:], # শুধু শেষ ১০টি ভ্যালু নিচ্ছি (ডাটাফ্রেম থেকে শুরু)
908
  inputs=[new_multiplier],
909
  outputs=[rounds_table, time_html, confidence_html, prediction_html,
910
  expected_out, analysis_out, decision_out, risk_out,
 
913
 
914
  # রিসেট বাটন ক্লিক
915
  reset_btn.click(
916
+ fn=lambda: (
917
+ app.reset(),
918
+ *update_all()
919
+ )[-10:],
920
  outputs=[rounds_table, time_html, confidence_html, prediction_html,
921
  expected_out, analysis_out, decision_out, risk_out,
922
  pink_prob_out, model_details]
 
924
 
925
  # ইনিশিয়াল লোড
926
  demo.load(
927
+ fn=update_all,
928
  outputs=[rounds_table, time_html, confidence_html, prediction_html,
929
  expected_out, analysis_out, decision_out, risk_out,
930
  pink_prob_out, model_details]
 
935
  demo.launch(
936
  server_name="0.0.0.0",
937
  server_port=7860,
938
+ share=False
 
939
  )