| import gradio as gr |
| import numpy as np |
| import pandas as pd |
| from datetime import datetime |
| import random |
| from collections import defaultdict |
| import math |
| import traceback |
|
|
| |
| CONFIG = { |
| "HISTORY_LIMIT": 1000, |
| "SEQUENCE_LENGTH": 12, |
| "PATTERN_DEPTH": 6, |
| "PINK_THRESHOLD": 3.0, |
| "BIG_PINK_THRESHOLD": 5.0, |
| "CONFIDENCE_THRESHOLD": 0.65, |
| "ENSEMBLE_WEIGHTS": { |
| "neuralNetwork": 0.35, |
| "sequencePattern": 0.30, |
| "markovChain": 0.20, |
| "statisticalModel": 0.15 |
| } |
| } |
|
|
| |
| TIME_WINDOWS = [ |
| {"start": 55, "end": 57, "name": "প্রাইম পিঙ্ক", "multiplier": 1.9, "probability": 0.90}, |
| {"start": 59, "end": 1, "name": "প্রাইম পিঙ্ক", "multiplier": 1.9, "probability": 0.90}, |
| {"start": 18, "end": 20, "name": "পিঙ্ক জোন", "multiplier": 1.4, "probability": 0.70}, |
| {"start": 27, "end": 29, "name": "পিঙ্ক জোন", "multiplier": 1.4, "probability": 0.70}, |
| {"start": 38, "end": 40, "name": "পিঙ্ক জোন", "multiplier": 1.4, "probability": 0.70}, |
| {"start": 43, "end": 45, "name": "পিঙ্ক জোন", "multiplier": 1.4, "probability": 0.70}, |
| {"start": 48, "end": 50, "name": "পিঙ্ক জোন", "multiplier": 1.4, "probability": 0.70}, |
| ] |
|
|
| |
|
|
| class NeuralNetwork: |
| """নিউরাল নেটওয়ার্ক - প্যাটার্ন রিকগনিশনের জন্য""" |
| |
| def __init__(self): |
| self.weights = { |
| 'input': np.random.randn(15) * 0.1, |
| 'hidden': np.random.randn(10) * 0.1, |
| 'output': np.random.randn(5) * 0.1 |
| } |
| self.performance_history = [] |
| |
| def extract_features(self, history): |
| """ডাটা থেকে ফিচার এক্সট্র্যাক্ট করে""" |
| recent = history[:12] |
| features = [] |
| |
| |
| for val in recent: |
| features.append(math.log(val + 0.1) / math.log(10)) |
| |
| |
| mean_val = np.mean(recent) if recent else 1.5 |
| std_val = np.std(recent) if recent else 0.2 |
| features.append(mean_val) |
| features.append(std_val / (mean_val + 0.1)) |
| |
| |
| if len(recent) >= 3: |
| trend = (recent[0] - recent[-1]) / len(recent) |
| features.append(trend) |
| else: |
| features.append(0) |
| |
| |
| pink_count = sum(1 for v in recent if v >= CONFIG["PINK_THRESHOLD"]) |
| features.append(pink_count / len(recent) if recent else 0) |
| |
| |
| while len(features) < 15: |
| features.append(0) |
| |
| return np.array(features[:15]) |
| |
| def predict(self, history): |
| """প্রেডিকশন করে""" |
| try: |
| if len(history) < 5: |
| return {'prediction': 1.5, 'confidence': 0.3, 'analysis': 'পর্যাপ্ত ডাটা নেই', 'raw_value': 0} |
| |
| features = self.extract_features(history) |
| |
| |
| hidden = np.tanh(np.dot(features, self.weights['input'][:len(features)])) |
| output = np.tanh(hidden * np.mean(self.weights['hidden'])) |
| |
| |
| prediction = 1.5 + (output * 3.0) |
| prediction = max(1.05, min(15.0, prediction)) |
| |
| |
| confidence = min(0.9, 0.5 + (len(history) / 200) + abs(output) * 0.2) |
| |
| analysis = self.generate_analysis(features, output) |
| |
| return { |
| 'prediction': float(prediction), |
| 'confidence': float(confidence), |
| 'analysis': analysis, |
| 'raw_value': float(output) |
| } |
| except Exception as e: |
| print(f"NeuralNetwork error: {e}") |
| return {'prediction': 1.5, 'confidence': 0.3, 'analysis': 'এরর হয়েছে', 'raw_value': 0} |
| |
| def generate_analysis(self, features, output): |
| """অ্যানালাইসিস জেনারেট করে""" |
| if output > 0.6: |
| return "🧠 শক্তিশালী নিউরাল সিগন্যাল" |
| elif output < -0.4: |
| return "🧠 দুর্বল নিউরাল সিগন্যাল" |
| else: |
| return "🧠 নিউট্রাল নিউরাল প্যাটার্ন" |
|
|
|
|
| class SequenceAnalyzer: |
| """সিকোয়েন্স অ্যানালাইজার - প্যাটার্ন খুঁজে বের করে""" |
| |
| def __init__(self): |
| self.patterns = defaultdict(list) |
| self.max_pattern_length = CONFIG["PATTERN_DEPTH"] |
| |
| def find_patterns(self, history): |
| """ইতিহাসে প্যাটার্ন খুঁজে বের করে""" |
| patterns = [] |
| |
| for length in range(2, min(self.max_pattern_length, len(history) // 2)): |
| for i in range(len(history) - length * 2): |
| pattern = history[i:i+length] |
| next_seq = history[i+length:i+length*2] |
| |
| similarity = self.calculate_similarity(pattern, next_seq) |
| if similarity > 0.6: |
| patterns.append({ |
| 'pattern': pattern, |
| 'next': next_seq, |
| 'similarity': similarity, |
| 'length': length |
| }) |
| |
| return patterns |
| |
| def calculate_similarity(self, seq1, seq2): |
| """দুটি সিকোয়েন্সের মিল ক্যালকুলেট করে""" |
| if len(seq1) != len(seq2) or len(seq1) == 0: |
| return 0 |
| |
| diffs = [abs(seq1[i] - seq2[i]) / (max(seq1[i], seq2[i]) + 0.1) |
| for i in range(len(seq1))] |
| avg_diff = np.mean(diffs) if diffs else 1 |
| return max(0, 1 - avg_diff) |
| |
| def predict(self, history): |
| """প্যাটার্ন-ভিত্তিক প্রেডিকশন""" |
| try: |
| if len(history) < 4: |
| return {'prediction': 1.5, 'confidence': 0.3, 'analysis': 'পর্যাপ্ত প্যাটার্ন নেই'} |
| |
| patterns = self.find_patterns(history) |
| |
| if not patterns: |
| return { |
| 'prediction': 1.5, |
| 'confidence': 0.4, |
| 'analysis': '🔗 কোন প্যাটার্ন মেলেনি' |
| } |
| |
| |
| best_pattern = max(patterns, key=lambda p: p['similarity'] * p['length']) |
| |
| |
| trend = (best_pattern['pattern'][-1] - best_pattern['pattern'][0]) / len(best_pattern['pattern']) |
| prediction = best_pattern['pattern'][-1] + trend |
| |
| |
| prediction = max(1.05, min(12.0, prediction)) |
| |
| confidence = best_pattern['similarity'] * 0.8 |
| |
| analysis = f"🔗 {best_pattern['length']}-দৈর্ঘ্যের প্যাটার্ন ({int(best_pattern['similarity']*100)}% মিল)" |
| |
| return { |
| 'prediction': float(prediction), |
| 'confidence': float(confidence), |
| 'analysis': analysis |
| } |
| except Exception as e: |
| print(f"SequenceAnalyzer error: {e}") |
| return {'prediction': 1.5, 'confidence': 0.3, 'analysis': 'প্যাটার্ন অ্যানালাইসিস এরর'} |
|
|
|
|
| class MarkovChain: |
| """মার্কভ চেইন - স্টেট ট্রানজিশন প্রেডিক্ট করে""" |
| |
| def __init__(self): |
| self.transition_matrix = defaultdict(lambda: defaultdict(float)) |
| self.states = ['খুব_ছোট', 'ছোট', 'মাঝারি', 'বড়', 'পিঙ্ক'] |
| |
| def discretize(self, value): |
| """ভ্যালুকে স্টেটে রূপান্তর করে""" |
| if value < 1.3: |
| return 'খুব_ছোট' |
| elif value < 1.8: |
| return 'ছোট' |
| elif value < 2.5: |
| return 'মাঝারি' |
| elif value < CONFIG["PINK_THRESHOLD"]: |
| return 'বড়' |
| else: |
| return 'পিঙ্ক' |
| |
| def build_model(self, history): |
| """ট্রানজিশন ম্যাট্রিক্স বিল্ড করে""" |
| self.transition_matrix.clear() |
| |
| for i in range(len(history) - 1): |
| current = self.discretize(history[i]) |
| next_state = self.discretize(history[i + 1]) |
| self.transition_matrix[current][next_state] += 1 |
| |
| |
| for state in self.transition_matrix: |
| total = sum(self.transition_matrix[state].values()) |
| if total > 0: |
| for next_state in self.transition_matrix[state]: |
| self.transition_matrix[state][next_state] /= total |
| |
| def predict(self, history): |
| """মার্কভ চেইন থেকে প্রেডিকশন""" |
| try: |
| if len(history) < 2: |
| return {'prediction': 1.5, 'confidence': 0.3, 'analysis': 'পর্যাপ্ত ডাটা নেই'} |
| |
| self.build_model(history) |
| |
| current_state = self.discretize(history[0]) |
| next_state_probs = self.transition_matrix.get(current_state, {}) |
| |
| if not next_state_probs: |
| |
| next_state_probs = { |
| 'খুব_ছোট': 0.2, |
| 'ছোট': 0.4, |
| 'মাঝারি': 0.25, |
| 'বড়': 0.1, |
| 'পিঙ্ক': 0.05 |
| } |
| |
| |
| state_values = { |
| 'খুব_ছোট': 1.15, |
| 'ছোট': 1.5, |
| 'মাঝারি': 2.2, |
| 'বড়': 2.8, |
| 'পিঙ্ক': 4.5 |
| } |
| |
| |
| prediction = 0 |
| total_prob = 0 |
| for s, prob in next_state_probs.items(): |
| prediction += state_values.get(s, 1.5) * prob |
| total_prob += prob |
| |
| if total_prob > 0: |
| prediction /= total_prob |
| else: |
| prediction = 1.5 |
| |
| confidence = max(next_state_probs.values()) * 0.9 if next_state_probs else 0.3 |
| |
| most_likely = max(next_state_probs.items(), key=lambda x: x[1])[0] if next_state_probs else 'ছোট' |
| |
| analysis = f"⛓️ মার্কভ: {current_state} → {most_likely} ({int(max(next_state_probs.values())*100)}%)" |
| |
| return { |
| 'prediction': float(prediction), |
| 'confidence': float(confidence), |
| 'analysis': analysis |
| } |
| except Exception as e: |
| print(f"MarkovChain error: {e}") |
| return {'prediction': 1.5, 'confidence': 0.3, 'analysis': 'মার্কভ এরর'} |
|
|
|
|
| class StatisticalModel: |
| """পরিসংখ্যানিক মডেল - গড়, মিডিয়ান, ট্রেন্ড""" |
| |
| def predict(self, history): |
| """পরিসংখ্যানিক প্রেডিকশন""" |
| try: |
| if len(history) < 3: |
| return {'prediction': 1.5, 'confidence': 0.3, 'analysis': 'পর্যাপ্ত ডাটা নেই'} |
| |
| recent = history[:10] |
| |
| |
| mean_val = np.mean(recent) if recent else 1.5 |
| median_val = np.median(recent) if recent else 1.5 |
| std_val = np.std(recent) if recent else 0.2 |
| |
| |
| if len(recent) >= 3: |
| x = np.arange(len(recent)) |
| z = np.polyfit(x, recent, 1) |
| trend = z[0] |
| else: |
| trend = 0 |
| |
| |
| prediction = median_val + trend * 2 |
| |
| |
| if std_val > 1.0: |
| prediction += random.uniform(-0.5, 0.5) |
| |
| prediction = max(1.05, min(10.0, prediction)) |
| |
| |
| confidence = min(0.8, 0.5 + (len(history) / 200) - (std_val / 10)) |
| |
| |
| if abs(trend) > 0.2: |
| trend_text = "উর্ধ্বমুখী" if trend > 0 else "নিম্নমুখী" |
| analysis = f"📊 {trend_text} ট্রেন্ড, মিডিয়ান: {median_val:.2f}x" |
| else: |
| analysis = f"📊 স্থিতিশীল, গড়: {mean_val:.2f}x" |
| |
| return { |
| 'prediction': float(prediction), |
| 'confidence': float(confidence), |
| 'analysis': analysis |
| } |
| except Exception as e: |
| print(f"StatisticalModel error: {e}") |
| return {'prediction': 1.5, 'confidence': 0.3, 'analysis': 'স্ট্যাটিস্টিক্যাল এরর'} |
|
|
|
|
| class EnsemblePredictor: |
| """এনসেম্বল মডেল - সব মডেলকে একত্রে ব্যবহার করে""" |
| |
| def __init__(self): |
| self.models = { |
| 'neuralNetwork': NeuralNetwork(), |
| 'sequencePattern': SequenceAnalyzer(), |
| 'markovChain': MarkovChain(), |
| 'statisticalModel': StatisticalModel() |
| } |
| self.weights = CONFIG["ENSEMBLE_WEIGHTS"].copy() |
| self.pattern_memory = {} |
| self.performance = {'overall': []} |
| |
| def predict(self, history): |
| """এনসেম্বল প্রেডিকশন""" |
| try: |
| if len(history) < 5: |
| return self.get_default_prediction() |
| |
| predictions = {} |
| total_weighted = 0 |
| total_weight = 0 |
| |
| for name, model in self.models.items(): |
| try: |
| pred = model.predict(history) |
| predictions[name] = pred |
| |
| weight = self.weights.get(name, 0.2) * pred['confidence'] |
| total_weighted += pred['prediction'] * weight |
| total_weight += weight |
| |
| except Exception as e: |
| print(f"Error in {name}: {e}") |
| predictions[name] = {'prediction': 1.5, 'confidence': 0.3, 'analysis': 'এরর'} |
| |
| |
| ensemble_pred = total_weighted / total_weight if total_weight > 0 else 1.5 |
| |
| |
| time_window = self.get_current_time_window() |
| if time_window: |
| ensemble_pred *= time_window['multiplier'] |
| ensemble_pred = min(15.0, ensemble_pred) |
| |
| |
| confidences = [p.get('confidence', 0.3) for p in predictions.values()] |
| avg_confidence = np.mean(confidences) if confidences else 0.3 |
| |
| |
| pink_prob = self.calculate_pink_probability(history, predictions, time_window) |
| is_pink_expected = pink_prob > 0.4 |
| |
| |
| interval = self.calculate_prediction_interval(predictions, ensemble_pred, avg_confidence) |
| |
| |
| risk = self.calculate_risk(interval, avg_confidence) |
| |
| |
| analysis = self.generate_analysis(predictions, time_window, is_pink_expected) |
| |
| |
| model_details_str = self.format_model_details(predictions) |
| |
| return { |
| 'prediction': float(ensemble_pred), |
| 'interval_lower': float(interval['lower']), |
| 'interval_upper': float(interval['upper']), |
| 'confidence': float(avg_confidence), |
| 'risk': risk, |
| 'is_pink_expected': is_pink_expected, |
| 'pink_probability': float(pink_prob), |
| 'analysis': analysis, |
| 'model_details': model_details_str, |
| 'time_window': time_window['name'] if time_window else None |
| } |
| except Exception as e: |
| print(f"EnsemblePredictor error: {e}") |
| return self.get_default_prediction() |
| |
| def format_model_details(self, predictions): |
| """মডেল ডিটেইলসকে স্ট্রিং ফরম্যাটে কনভার্ট করে""" |
| lines = [] |
| for name, pred in predictions.items(): |
| model_names = { |
| 'neuralNetwork': '🧠 নিউরাল', |
| 'sequencePattern': '🔗 সিকোয়েন্স', |
| 'markovChain': '⛓️ মার্কভ', |
| 'statisticalModel': '📊 স্ট্যাট' |
| } |
| display_name = model_names.get(name, name) |
| lines.append(f"{display_name}: {pred.get('prediction', 1.5):.2f}x (কনফি: {int(pred.get('confidence', 0)*100)}%) - {pred.get('analysis', '')[:30]}") |
| return "\n".join(lines) |
| |
| def get_default_prediction(self): |
| """ডিফল্ট প্রেডিকশন""" |
| return { |
| 'prediction': 1.5, |
| 'interval_lower': 1.3, |
| 'interval_upper': 1.7, |
| 'confidence': 0.3, |
| 'risk': 'মাঝারি ⚖️', |
| 'is_pink_expected': False, |
| 'pink_probability': 0.1, |
| 'analysis': '🧠 পর্যাপ্ত ডাটা নেই। কমপক্ষে ৫টি রাউন্ড প্রয়োজন।', |
| 'model_details': 'কোন মডেল ডাটা নেই', |
| 'time_window': None |
| } |
| |
| def get_current_time_window(self): |
| """বর্তমান টাইম উইন্ডো চেক করে""" |
| now = datetime.now() |
| minutes = now.minute |
| |
| for window in TIME_WINDOWS: |
| if window['start'] <= window['end']: |
| if minutes >= window['start'] and minutes <= window['end']: |
| return window |
| else: |
| if minutes >= window['start'] or minutes <= window['end']: |
| return window |
| return None |
| |
| def calculate_pink_probability(self, history, predictions, time_window): |
| """পিঙ্ক হওয়ার সম্ভাবনা ক্যালকুলেট করে""" |
| factors = [] |
| |
| |
| if time_window: |
| factors.append(time_window['probability']) |
| |
| |
| if predictions: |
| pink_predictions = sum(1 for p in predictions.values() |
| if p.get('prediction', 1.5) >= CONFIG["PINK_THRESHOLD"]) |
| factors.append(pink_predictions / len(predictions)) |
| |
| |
| if history: |
| recent_pinks = sum(1 for v in history[:20] if v >= CONFIG["PINK_THRESHOLD"]) |
| factors.append(min(0.9, recent_pinks / 20)) |
| |
| return np.mean(factors) if factors else 0.2 |
| |
| def calculate_prediction_interval(self, predictions, center, confidence): |
| """প্রেডিকশন ইন্টারভ্যাল ক্যালকুলেট করে""" |
| pred_values = [p.get('prediction', 1.5) for p in predictions.values()] |
| std = np.std(pred_values) if len(pred_values) > 1 else 0.2 |
| |
| spread = std * (2 - confidence) |
| spread = max(0.1, min(1.5, spread)) |
| |
| return { |
| 'lower': max(1.01, center - spread/2), |
| 'upper': center + spread/2 |
| } |
| |
| def calculate_risk(self, interval, confidence): |
| """রিস্ক লেভেল ক্যালকুলেট করে""" |
| spread = interval['upper'] - interval['lower'] |
| avg = (interval['lower'] + interval['upper']) / 2 |
| relative_spread = spread / avg if avg > 0 else 0.5 |
| |
| if relative_spread < 0.2 and confidence > 0.7: |
| return "নিম্ন ✅" |
| elif relative_spread > 0.5 or confidence < 0.45: |
| return "উচ্চ ⚠️" |
| else: |
| return "মাঝারি ⚖️" |
| |
| def generate_analysis(self, predictions, time_window, is_pink): |
| """অ্যানালাইসিস টেক্সট জেনারেট করে""" |
| parts = [] |
| |
| |
| for name, pred in predictions.items(): |
| if pred.get('confidence', 0) > 0.6: |
| parts.append(pred.get('analysis', '')) |
| |
| |
| if time_window: |
| parts.append(f"⏰ {time_window['name']}") |
| |
| |
| if is_pink: |
| parts.append("🌸 পিঙ্ক সম্ভাবনা") |
| |
| if not parts: |
| return "🧠 মডেল অ্যানালাইসিস চলছে..." |
| |
| return " | ".join(parts[:3]) |
|
|
|
|
| |
|
|
| class AviatorPredictorApp: |
| """মেইন অ্যাপ্লিকেশন ক্লাস""" |
| |
| def __init__(self): |
| self.history = [] |
| self.predictor = EnsemblePredictor() |
| self.last_prediction = None |
| |
| def add_round(self, multiplier): |
| """নতুন রাউন্ড যোগ করে""" |
| if multiplier <= 0: |
| return False |
| |
| self.history.insert(0, float(multiplier)) |
| if len(self.history) > CONFIG["HISTORY_LIMIT"]: |
| self.history = self.history[:CONFIG["HISTORY_LIMIT"]] |
| |
| return True |
| |
| def reset(self): |
| """হিস্ট্রি রিসেট করে""" |
| self.history = [] |
| self.last_prediction = None |
| |
| for _ in range(20): |
| self.history.append(round(random.uniform(1.0, 3.5), 2)) |
| self.history.sort(reverse=True) |
| |
| def get_prediction(self): |
| """বর্তমান প্রেডিকশন রিটার্ন করে""" |
| if len(self.history) < 3: |
| return self.predictor.get_default_prediction() |
| |
| self.last_prediction = self.predictor.predict(self.history) |
| return self.last_prediction |
| |
| def get_history_table(self): |
| """হিস্ট্রি টেবিল রিটার্ন করে (শুধু ডাটা, কোন বুলিয়ান না)""" |
| return [[i+1, f"{val:.2f}x"] for i, val in enumerate(self.history[:50])] |
| |
| def get_time_status(self): |
| """টাইম স্ট্যাটাস রিটার্ন করে""" |
| now = datetime.now() |
| time_str = now.strftime("%H:%M:%S") |
| |
| current = self.predictor.get_current_time_window() |
| |
| if current: |
| status = f"🌸 {current['name']} একটিভ! 🌸" |
| detail = f"বুস্ট: +{int((current['multiplier']-1)*100)}% | {int(current['probability']*100)}% পিঙ্ক সম্ভাবনা" |
| css_class = "active-window" |
| else: |
| |
| next_window = None |
| min_minutes = 60 |
| |
| for window in TIME_WINDOWS: |
| if window['start'] <= window['end']: |
| if now.minute < window['start']: |
| minutes = window['start'] - now.minute |
| else: |
| minutes = (60 - now.minute) + window['start'] |
| else: |
| if now.minute >= window['start']: |
| minutes = (60 - now.minute) + window['end'] |
| elif now.minute <= window['end']: |
| minutes = 0 |
| else: |
| minutes = window['start'] - now.minute |
| |
| if 0 < minutes < min_minutes: |
| min_minutes = minutes |
| next_window = window |
| |
| if next_window and min_minutes <= 2: |
| status = f"⚠️ {next_window['name']} আসছে {min_minutes} মিনিটে" |
| detail = "প্রস্তুত হোন!" |
| css_class = "approaching-window" |
| else: |
| status = "পিঙ্ক জোনের অপেক্ষায়..." |
| detail = next_window and f"পরবর্তী: {next_window['name']} {min_minutes} মিনিটে" or "কোন উইন্ডো নেই" |
| css_class = "waiting-window" |
| |
| return f""" |
| <div class="time-box {css_class}"> |
| <div style="font-size: 24px; font-weight: 700;">{time_str}</div> |
| <div style="font-size: 16px; font-weight: 600; margin: 5px 0;">{status}</div> |
| <div style="font-size: 12px; opacity: 0.9;">{detail}</div> |
| </div> |
| """ |
| |
| def get_confidence_html(self): |
| """কনফিডেন্স বার এইচটিএমএল রিটার্ন করে""" |
| if not self.last_prediction: |
| conf = 0.3 |
| is_pink = False |
| else: |
| conf = self.last_prediction.get('confidence', 0.3) |
| is_pink = self.last_prediction.get('is_pink_expected', False) |
| |
| color_class = "pink-text" if is_pink else "" |
| pink_text = "🌸 পিঙ্ক মোড" if is_pink else "" |
| |
| return f""" |
| <div style="margin: 10px 0;"> |
| <div style="display: flex; justify-content: space-between; margin-bottom: 4px;"> |
| <span class="{color_class}">এমএল কনফিডেন্স: {int(conf*100)}%</span> |
| <span class="{color_class}">{pink_text}</span> |
| </div> |
| <div class="confidence-bar"> |
| <div class="confidence-fill" style="width: {int(conf*100)}%;"></div> |
| </div> |
| </div> |
| """ |
|
|
|
|
| |
| CUSTOM_CSS = """ |
| /* ডার্ক মোড বেস */ |
| .gradio-container { |
| background: #0a0a0f !important; |
| color: #ffffff !important; |
| } |
| footer {visibility: hidden} |
| |
| /* টাইম বক্স স্টাইল */ |
| .time-box { |
| text-align: center; |
| padding: 15px; |
| border-radius: 10px; |
| margin-bottom: 20px; |
| transition: all 0.3s; |
| font-weight: 500; |
| } |
| .active-window { |
| background: linear-gradient(135deg, #ff1493, #ff69b4) !important; |
| color: white !important; |
| box-shadow: 0 0 20px #ff1493; |
| } |
| .approaching-window { |
| background: linear-gradient(135deg, #ffa726, #ff9800) !important; |
| color: white !important; |
| box-shadow: 0 0 20px #ffa726; |
| } |
| .waiting-window { |
| background: linear-gradient(135deg, #1a1a2e, #16213e) !important; |
| color: white !important; |
| border: 1px solid #00d4ff; |
| } |
| |
| /* পিঙ্ক টেক্সট */ |
| .pink-text { |
| color: #ff1493 !important; |
| font-weight: bold !important; |
| } |
| |
| /* কনফিডেন্স বার */ |
| .confidence-bar { |
| height: 8px; |
| background: #333; |
| border-radius: 4px; |
| overflow: hidden; |
| margin: 5px 0; |
| } |
| .confidence-fill { |
| height: 100%; |
| background: linear-gradient(90deg, #00d4ff, #ff1493); |
| transition: width 0.3s; |
| } |
| |
| /* প্রেডিকশন ইন্টারভ্যাল */ |
| .prediction-interval { |
| font-size: 32px; |
| font-weight: 700; |
| text-align: center; |
| margin: 10px 0; |
| padding: 15px; |
| background: rgba(255,255,255,0.05); |
| border-radius: 10px; |
| } |
| .prediction-interval.pink-mode { |
| color: #ff1493; |
| text-shadow: 0 0 10px #ff1493; |
| } |
| .interval-lower { |
| color: #00d4ff; |
| } |
| .interval-upper { |
| color: #ffa726; |
| } |
| .interval-separator { |
| color: white; |
| margin: 0 10px; |
| } |
| |
| /* টেক্সটবক্স স্টাইল */ |
| .gr-box { |
| border: 1px solid #333 !important; |
| background: rgba(255,255,255,0.05) !important; |
| } |
| .gr-box label { |
| color: #00d4ff !important; |
| } |
| |
| /* বাটন স্টাইল */ |
| .gr-button-primary { |
| background: linear-gradient(135deg, #00d4ff, #0088ff) !important; |
| border: none !important; |
| } |
| .gr-button-secondary { |
| background: rgba(255,255,255,0.1) !important; |
| border: 1px solid #00d4ff !important; |
| } |
| |
| /* ডাটাফ্রেম */ |
| .gr-dataframe { |
| background: rgba(255,255,255,0.05) !important; |
| } |
| """ |
|
|
| |
|
|
| |
| app = AviatorPredictorApp() |
| app.reset() |
|
|
| |
| with gr.Blocks(css=CUSTOM_CSS) as demo: |
| |
| gr.HTML(""" |
| <div style="text-align: center; margin-bottom: 20px;"> |
| <h1 style="color: #00d4ff; font-size: 48px; margin: 0; text-shadow: 0 0 10px #00d4ff;">✈️ AVOLD ML</h1> |
| <p style="color: #888; font-size: 14px;">এনসেম্বল এমএল এভিয়েটর প্রেডিক্টর v3.0</p> |
| </div> |
| """) |
| |
| |
| time_html = gr.HTML(value=app.get_time_status()) |
| |
| |
| with gr.Row(): |
| new_multiplier = gr.Number( |
| label="নতুন মাল্টিপ্লায়ার", |
| value=1.0, |
| step=0.1, |
| minimum=1.0, |
| maximum=100.0 |
| ) |
| add_btn = gr.Button("➕ যোগ করুন", variant="primary") |
| |
| |
| reset_btn = gr.Button("🔄 রিসেট ডাটা", variant="secondary") |
| |
| |
| with gr.Row(): |
| with gr.Column(): |
| gr.Markdown("### 🎯 প্রেডিকশন ইন্টারভ্যাল") |
| prediction_html = gr.HTML() |
| |
| |
| with gr.Row(): |
| expected_out = gr.Textbox(label="📊 এক্সপেক্টেড", interactive=False) |
| analysis_out = gr.Textbox(label="📈 অ্যানালাইসিস", interactive=False) |
| decision_out = gr.Textbox(label="🎯 ডিসিশন", interactive=False) |
| |
| |
| with gr.Row(): |
| with gr.Column(scale=3): |
| confidence_html = gr.HTML(value=app.get_confidence_html()) |
| with gr.Column(scale=1): |
| risk_out = gr.Textbox(label="রিস্ক লেভেল", interactive=False) |
| |
| |
| pink_prob_out = gr.Textbox(label="🌸 পিঙ্ক সম্ভাবনা", interactive=False) |
| |
| |
| model_details = gr.Textbox( |
| label="🧠 মডেল ডিটেইলস", |
| interactive=False, |
| lines=5 |
| ) |
| |
| |
| rounds_table = gr.Dataframe( |
| label="📜 শেষ ৫০ রাউন্ড", |
| headers=["রাউন্ড", "মাল্টিপ্লায়ার"], |
| row_count=10, |
| interactive=False |
| ) |
| |
| |
| def update_all(): |
| """সব ডিসপ্লে আপডেট করে - শুধু ডাটা রিটার্ন করে, কোন বুলিয়ান না""" |
| try: |
| pred = app.get_prediction() |
| history_table = app.get_history_table() |
| time_status = app.get_time_status() |
| confidence = app.get_confidence_html() |
| |
| |
| pink_class = "pink-mode" if pred.get('is_pink_expected', False) else "" |
| prediction_html_str = f""" |
| <div class="prediction-interval {pink_class}"> |
| <span class="interval-lower">{pred.get('interval_lower', 1.3):.2f}x</span> |
| <span class="interval-separator">—</span> |
| <span class="interval-upper">{pred.get('interval_upper', 1.7):.2f}x</span> |
| </div> |
| """ |
| |
| |
| if pred.get('is_pink_expected', False): |
| decision = "পিঙ্ক আশান্বিত 🌸" |
| elif pred.get('prediction', 1.5) > 3.0: |
| decision = "বড় মাল্টিপ্লায়ার 🚀" |
| elif pred.get('prediction', 1.5) > 1.8: |
| decision = "মাঝারি 💪" |
| else: |
| decision = "ছোট 🎯" |
| |
| |
| pink_prob_text = f"{int(pred.get('pink_probability', 0)*100)}%" |
| |
| |
| model_text = pred.get('model_details', 'কোন ডাটা নেই') |
| |
| return [ |
| history_table, |
| time_status, |
| confidence, |
| prediction_html_str, |
| f"{pred.get('prediction', 1.5):.2f}x", |
| pred.get('analysis', 'অ্যানালাইসিস নেই'), |
| decision, |
| pred.get('risk', 'মাঝারি ⚖️'), |
| pink_prob_text, |
| model_text |
| ] |
| except Exception as e: |
| print(f"Update error: {e}") |
| traceback.print_exc() |
| |
| default_table = [[1, "1.00x"]] |
| default_time = '<div class="time-box waiting-window"><div style="font-size:24px;">--:--:--</div><div>আপডেট এরর</div></div>' |
| default_conf = '<div>এমএল কনফিডেন্স: 0%</div>' |
| 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>' |
| |
| return [ |
| default_table, |
| default_time, |
| default_conf, |
| default_pred, |
| "1.50x", |
| "আপডেট এরর", |
| "ছোট 🎯", |
| "মাঝারি ⚖️", |
| "0%", |
| "মডেল লোড করতে সমস্যা হয়েছে" |
| ] |
| |
| |
| add_btn.click( |
| fn=lambda x: ( |
| app.add_round(x), |
| *update_all() |
| )[-10:], |
| inputs=[new_multiplier], |
| outputs=[rounds_table, time_html, confidence_html, prediction_html, |
| expected_out, analysis_out, decision_out, risk_out, |
| pink_prob_out, model_details] |
| ) |
| |
| |
| reset_btn.click( |
| fn=lambda: ( |
| app.reset(), |
| *update_all() |
| )[-10:], |
| outputs=[rounds_table, time_html, confidence_html, prediction_html, |
| expected_out, analysis_out, decision_out, risk_out, |
| pink_prob_out, model_details] |
| ) |
| |
| |
| demo.load( |
| fn=update_all, |
| outputs=[rounds_table, time_html, confidence_html, prediction_html, |
| expected_out, analysis_out, decision_out, risk_out, |
| pink_prob_out, model_details] |
| ) |
|
|
| |
| if __name__ == "__main__": |
| demo.launch( |
| server_name="0.0.0.0", |
| server_port=7860, |
| share=False |
| ) |