Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -13,124 +13,107 @@ if api_key:
|
|
| 13 |
client = Groq(api_key=api_key)
|
| 14 |
|
| 15 |
# ==========================================
|
| 16 |
-
#
|
| 17 |
# ==========================================
|
| 18 |
-
def
|
| 19 |
"""
|
| 20 |
-
|
| 21 |
-
-
|
| 22 |
-
-
|
| 23 |
-
-
|
|
|
|
|
|
|
| 24 |
"""
|
| 25 |
-
|
| 26 |
-
|
| 27 |
-
|
| 28 |
-
|
| 29 |
-
|
| 30 |
-
|
| 31 |
-
|
| 32 |
-
|
| 33 |
-
|
| 34 |
-
|
| 35 |
-
|
| 36 |
-
|
| 37 |
-
|
| 38 |
-
|
| 39 |
-
|
| 40 |
-
|
| 41 |
-
|
| 42 |
-
|
| 43 |
-
|
| 44 |
-
|
| 45 |
-
|
| 46 |
-
|
| 47 |
-
|
| 48 |
-
|
| 49 |
-
|
| 50 |
-
|
| 51 |
-
|
| 52 |
-
|
| 53 |
-
|
| 54 |
-
|
| 55 |
-
|
| 56 |
-
|
| 57 |
-
|
| 58 |
-
|
| 59 |
-
|
| 60 |
-
|
| 61 |
-
|
| 62 |
-
|
| 63 |
-
|
| 64 |
-
|
| 65 |
-
|
| 66 |
-
|
| 67 |
-
|
| 68 |
-
|
| 69 |
-
|
| 70 |
-
|
| 71 |
-
|
| 72 |
-
p_over_25 += score_matrix[i, j]
|
| 73 |
-
|
| 74 |
-
# 9. Karşılıklı gol (BTTS) olasılığı
|
| 75 |
-
p_btts_yes = 0.0
|
| 76 |
-
for i in range(1, max_goals + 1):
|
| 77 |
-
for j in range(1, max_goals + 1):
|
| 78 |
-
p_btts_yes += score_matrix[i, j]
|
| 79 |
-
|
| 80 |
-
return (p_home_win, p_draw, p_away_win, lambda_home, lambda_away,
|
| 81 |
-
score_matrix, p_under_25, p_over_25, p_btts_yes)
|
| 82 |
|
| 83 |
# ==========================================
|
| 84 |
# 🧠 3. TAHMİN VE ANALİZ MOTORU
|
| 85 |
# ==========================================
|
| 86 |
-
def predict_and_analyze(
|
| 87 |
-
|
| 88 |
-
|
| 89 |
-
return "Lütfen ev sahibi ve deplasman takımlarının isimlerini giriniz.", {}
|
| 90 |
-
|
| 91 |
-
(p_home, p_draw, p_away, lam_home, lam_away,
|
| 92 |
-
score_matrix, p_under, p_over, p_btts) = calculate_poisson_probabilities(
|
| 93 |
-
home_rating, away_rating, home_form, away_form, home_injuries, away_injuries
|
| 94 |
-
)
|
| 95 |
|
| 96 |
-
|
| 97 |
-
max_idx = np.unravel_index(np.argmax(score_matrix), score_matrix.shape)
|
| 98 |
-
most_likely_score = f"{max_idx[0]} - {max_idx[1]}"
|
| 99 |
-
most_likely_prob = score_matrix[max_idx] * 100
|
| 100 |
|
| 101 |
# Gradio grafiği için olasılık sözlüğü
|
| 102 |
prob_dict = {
|
| 103 |
-
|
| 104 |
-
"
|
| 105 |
-
|
|
|
|
| 106 |
}
|
| 107 |
|
| 108 |
prompt = f"""
|
| 109 |
-
Sen uzman bir
|
| 110 |
-
Aşağıdaki verilere göre Türkçe bir maç öncesi analiz raporu hazırla.
|
| 111 |
-
|
| 112 |
-
⚽ Karşılaşma: {home_team} (Ev) vs {away_team} (Deplasman)
|
| 113 |
-
🏆 Format: FIFA H2H Sanal Ligi
|
| 114 |
|
| 115 |
-
|
| 116 |
-
|
| 117 |
-
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 118 |
|
| 119 |
📈 Poisson Modeli Sonuçları:
|
| 120 |
-
- Beklenen
|
| 121 |
-
-
|
| 122 |
-
-
|
| 123 |
-
-
|
| 124 |
-
-
|
| 125 |
-
-
|
| 126 |
-
|
| 127 |
-
|
| 128 |
-
|
| 129 |
-
|
| 130 |
-
|
| 131 |
-
|
| 132 |
-
|
| 133 |
-
Yorumların rasyonel, nesnel ve profesyonel olsun.
|
| 134 |
"""
|
| 135 |
|
| 136 |
if client:
|
|
@@ -146,44 +129,45 @@ def predict_and_analyze(home_team, away_team, home_rating, away_rating,
|
|
| 146 |
analysis_result = f"Groq API Analiz Hatası: {str(e)}\n\n(Lütfen GROQ_API_KEY değişkeninizi Hugging Face Secrets alanına doğru eklediğinizden emin olun.)"
|
| 147 |
else:
|
| 148 |
analysis_result = ("Groq API Anahtarı bulunamadı! Lütfen Hugging Face Space alanına "
|
| 149 |
-
"'GROQ_API_KEY' adıyla bir Secret ekleyin. (Yine de yukarıdaki
|
| 150 |
|
| 151 |
return analysis_result, prob_dict
|
| 152 |
|
| 153 |
# ==========================================
|
| 154 |
# 🎨 4. GRADIO ARAYÜZÜ
|
| 155 |
# ==========================================
|
| 156 |
-
with gr.Blocks(theme=gr.themes.Soft(primary_hue="
|
| 157 |
gr.Markdown(
|
| 158 |
"""
|
| 159 |
-
#
|
| 160 |
-
Bu uygulama,
|
| 161 |
"""
|
| 162 |
)
|
| 163 |
|
| 164 |
with gr.Row():
|
| 165 |
with gr.Column():
|
| 166 |
-
gr.Markdown("###
|
| 167 |
-
|
| 168 |
-
away_input = gr.Textbox(label="Deplasman Takım", value="Barcelona")
|
| 169 |
|
| 170 |
-
gr.Markdown("###
|
| 171 |
with gr.Row():
|
| 172 |
-
|
| 173 |
-
|
| 174 |
-
|
| 175 |
-
gr.Markdown("### 📊 Form ve Sakatlık Durumu")
|
| 176 |
-
with gr.Row():
|
| 177 |
-
home_form_input = gr.Slider(label="Ev Form (Son 5 Maç Puanı, Max 15)", minimum=0, maximum=15, value=11, step=1)
|
| 178 |
-
away_form_input = gr.Slider(label="Deplasman Form (Son 5 Maç Puanı, Max 15)", minimum=0, maximum=15, value=9, step=1)
|
| 179 |
with gr.Row():
|
| 180 |
-
|
| 181 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 182 |
|
| 183 |
submit_btn = gr.Button("Analiz Et ve Tahmin Üret", variant="primary")
|
| 184 |
|
| 185 |
with gr.Column():
|
| 186 |
-
gr.Markdown("### 📈
|
| 187 |
prob_output = gr.Label(label="Olasılık Dağılımı")
|
| 188 |
|
| 189 |
gr.Markdown("### 🧠 Groq Yapay Zeka Analiz Raporu")
|
|
@@ -191,14 +175,16 @@ with gr.Blocks(theme=gr.themes.Soft(primary_hue="green", secondary_hue="slate"))
|
|
| 191 |
|
| 192 |
submit_btn.click(
|
| 193 |
fn=predict_and_analyze,
|
| 194 |
-
inputs=[
|
| 195 |
-
home_input, away_input,
|
| 196 |
-
home_rating_input, away_rating_input,
|
| 197 |
-
home_form_input, away_form_input,
|
| 198 |
-
home_inj_input, away_inj_input
|
| 199 |
-
],
|
| 200 |
outputs=[analysis_output, prob_output]
|
| 201 |
)
|
| 202 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 203 |
if __name__ == "__main__":
|
| 204 |
demo.launch()
|
|
|
|
| 13 |
client = Groq(api_key=api_key)
|
| 14 |
|
| 15 |
# ==========================================
|
| 16 |
+
# 🎰 2. SLOT OYUNU OLASILIK MOTORU (POISSON)
|
| 17 |
# ==========================================
|
| 18 |
+
def calculate_slot_probabilities(symbol_count, wild_count, scatter_count, spin_count, volatility):
|
| 19 |
"""
|
| 20 |
+
Slot oyunu için sembol düşme olasılıklarını Poisson ile hesaplar.
|
| 21 |
+
- symbol_count: Makaralarda toplam sembol sayısı (ör. 20)
|
| 22 |
+
- wild_count: Wild sembol sayısı
|
| 23 |
+
- scatter_count: Scatter sembol sayısı
|
| 24 |
+
- spin_count: Simüle edilecek spin sayısı
|
| 25 |
+
- volatility: Düşük / Orta / Yüksek (ödeme sıklığını etkiler)
|
| 26 |
"""
|
| 27 |
+
total_slots = max(1, symbol_count)
|
| 28 |
+
|
| 29 |
+
# Volatilite katsayısı (düşük = sık küçük ödeme, yüksek = nadir büyük ödeme)
|
| 30 |
+
vol_map = {"Düşük": 0.6, "Orta": 1.0, "Yüksek": 1.5}
|
| 31 |
+
vol_factor = vol_map.get(volatility, 1.0)
|
| 32 |
+
|
| 33 |
+
# Beklenen sembol düşme sayıları (λ)
|
| 34 |
+
lambda_wild = (wild_count / total_slots) * spin_count * vol_factor
|
| 35 |
+
lambda_scatter = (scatter_count / total_slots) * spin_count * vol_factor
|
| 36 |
+
lambda_line = (1.0 / total_slots) * spin_count * vol_factor # Herhangi bir ödeme çizgisi
|
| 37 |
+
|
| 38 |
+
# Poisson ile 0-10 arası düşme olasılıkları
|
| 39 |
+
max_hits = 10
|
| 40 |
+
wild_probs = [poisson.pmf(i, lambda_wild) for i in range(max_hits + 1)]
|
| 41 |
+
scatter_probs = [poisson.pmf(i, lambda_scatter) for i in range(max_hits + 1)]
|
| 42 |
+
line_probs = [poisson.pmf(i, lambda_line) for i in range(max_hits + 1)]
|
| 43 |
+
|
| 44 |
+
# Kazanç olasılıkları (en az 1 eşleşme)
|
| 45 |
+
p_wild = 1 - wild_probs[0]
|
| 46 |
+
p_scatter = 1 - scatter_probs[0]
|
| 47 |
+
p_any_win = 1 - line_probs[0]
|
| 48 |
+
|
| 49 |
+
# Büyük kazanç (3+ scatter veya 3+ wild)
|
| 50 |
+
p_big_win = sum(scatter_probs[3:]) + sum(wild_probs[3:])
|
| 51 |
+
|
| 52 |
+
# RTP tahmini (volatiliteye göre ayarlanır, %85-98 arası)
|
| 53 |
+
base_rtp = 92.0
|
| 54 |
+
rtp_estimate = base_rtp - (vol_factor - 1.0) * 5.0
|
| 55 |
+
rtp_estimate = max(80.0, min(99.0, rtp_estimate))
|
| 56 |
+
|
| 57 |
+
# Ortalama ödeme çarpanı
|
| 58 |
+
avg_multiplier = (1.0 + p_big_win * 20) * (rtp_estimate / 100.0)
|
| 59 |
+
|
| 60 |
+
return {
|
| 61 |
+
"p_wild": p_wild,
|
| 62 |
+
"p_scatter": p_scatter,
|
| 63 |
+
"p_any_win": p_any_win,
|
| 64 |
+
"p_big_win": p_big_win,
|
| 65 |
+
"lambda_wild": lambda_wild,
|
| 66 |
+
"lambda_scatter": lambda_scatter,
|
| 67 |
+
"lambda_line": lambda_line,
|
| 68 |
+
"rtp_estimate": rtp_estimate,
|
| 69 |
+
"avg_multiplier": avg_multiplier,
|
| 70 |
+
"wild_probs": wild_probs,
|
| 71 |
+
"scatter_probs": scatter_probs,
|
| 72 |
+
"line_probs": line_probs,
|
| 73 |
+
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 74 |
|
| 75 |
# ==========================================
|
| 76 |
# 🧠 3. TAHMİN VE ANALİZ MOTORU
|
| 77 |
# ==========================================
|
| 78 |
+
def predict_and_analyze(game_name, symbol_count, wild_count, scatter_count, spin_count, volatility):
|
| 79 |
+
if not game_name:
|
| 80 |
+
return "Lütfen oyun adını giriniz.", {}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 81 |
|
| 82 |
+
result = calculate_slot_probabilities(symbol_count, wild_count, scatter_count, spin_count, volatility)
|
|
|
|
|
|
|
|
|
|
| 83 |
|
| 84 |
# Gradio grafiği için olasılık sözlüğü
|
| 85 |
prob_dict = {
|
| 86 |
+
"En Az 1 Wild Düşme": float(result["p_wild"]),
|
| 87 |
+
"En Az 1 Scatter Düşme": float(result["p_scatter"]),
|
| 88 |
+
"Herhangi Bir Kazanç": float(result["p_any_win"]),
|
| 89 |
+
"Büyük Kazanç (3+ Scatter/Wild)": float(result["p_big_win"]),
|
| 90 |
}
|
| 91 |
|
| 92 |
prompt = f"""
|
| 93 |
+
Sen uzman bir slot oyunları (sanal kumarhane) analisti ve olasılık modelleyicisisin.
|
|
|
|
|
|
|
|
|
|
|
|
|
| 94 |
|
| 95 |
+
🎰 Oyun: {game_name}
|
| 96 |
+
📊 Parametreler:
|
| 97 |
+
- Toplam sembol sayısı: {symbol_count}
|
| 98 |
+
- Wild sembol sayısı: {wild_count}
|
| 99 |
+
- Scatter sembol sayısı: {scatter_count}
|
| 100 |
+
- Simüle edilen spin sayısı: {spin_count}
|
| 101 |
+
- Volatilite: {volatility}
|
| 102 |
|
| 103 |
📈 Poisson Modeli Sonuçları:
|
| 104 |
+
- Beklenen Wild (λ): {result['lambda_wild']:.2f} | En az 1 Wild: %{result['p_wild']*100:.1f}
|
| 105 |
+
- Beklenen Scatter (λ): {result['lambda_scatter']:.2f} | En az 1 Scatter: %{result['p_scatter']*100:.1f}
|
| 106 |
+
- Herhangi bir kazanç: %{result['p_any_win']*100:.1f}
|
| 107 |
+
- Büyük kazanç (3+ Scatter/Wild): %{result['p_big_win']*100:.1f}
|
| 108 |
+
- Tahmini RTP: %{result['rtp_estimate']:.1f}
|
| 109 |
+
- Ortalama ödeme çarpanı: {result['avg_multiplier']:.2f}x
|
| 110 |
+
|
| 111 |
+
Türkçe bir analiz raporu hazırla. Şu başlıklar bulunsun:
|
| 112 |
+
1. 🎯 Model Yorumu (Poisson dağılımı ve sembol düşme mantığı)
|
| 113 |
+
2. 🎰 Volatilite ve RTP Değerlendirmesi (oyunun risk profili)
|
| 114 |
+
3. 💡 Strateji ve Bahis Önerisi (spin sayısı, bütçe yönetimi, +EV değerlendirmesi)
|
| 115 |
+
|
| 116 |
+
Yorumların rasyonel, nesnel ve profesyonel olsun. Kumar bağımlılığına karşı sorumlu oyun vurgusu yap.
|
|
|
|
| 117 |
"""
|
| 118 |
|
| 119 |
if client:
|
|
|
|
| 129 |
analysis_result = f"Groq API Analiz Hatası: {str(e)}\n\n(Lütfen GROQ_API_KEY değişkeninizi Hugging Face Secrets alanına doğru eklediğinizden emin olun.)"
|
| 130 |
else:
|
| 131 |
analysis_result = ("Groq API Anahtarı bulunamadı! Lütfen Hugging Face Space alanına "
|
| 132 |
+
"'GROQ_API_KEY' adıyla bir Secret ekleyin. (Yine de yukarıdaki olasılık grafiğini görebilirsiniz.)")
|
| 133 |
|
| 134 |
return analysis_result, prob_dict
|
| 135 |
|
| 136 |
# ==========================================
|
| 137 |
# 🎨 4. GRADIO ARAYÜZÜ
|
| 138 |
# ==========================================
|
| 139 |
+
with gr.Blocks(theme=gr.themes.Soft(primary_hue="amber", secondary_hue="slate")) as demo:
|
| 140 |
gr.Markdown(
|
| 141 |
"""
|
| 142 |
+
# 🎰 Slot Oyunu Olasılık & Groq AI Tahmin Radarı
|
| 143 |
+
Bu uygulama, slot oyunu parametrelerini **Poisson Dağılımı** ile analiz ederek sembol düşme olasılıklarını ve RTP tahminini hesaplar; ardından **Groq (GPT-OSS)** yapay zekası ile strateji raporu üretir.
|
| 144 |
"""
|
| 145 |
)
|
| 146 |
|
| 147 |
with gr.Row():
|
| 148 |
with gr.Column():
|
| 149 |
+
gr.Markdown("### 🎮 Oyun Bilgileri")
|
| 150 |
+
game_input = gr.Textbox(label="Oyun Adı", value="Gates of Olympus")
|
|
|
|
| 151 |
|
| 152 |
+
gr.Markdown("### 🎰 Makara Parametreleri")
|
| 153 |
with gr.Row():
|
| 154 |
+
symbol_input = gr.Number(label="Toplam Sembol Sayısı", value=20, precision=0)
|
| 155 |
+
spin_input = gr.Number(label="Simüle Edilecek Spin", value=100, precision=0)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 156 |
with gr.Row():
|
| 157 |
+
wild_input = gr.Number(label="Wild Sembol Sayısı", value=3, precision=0)
|
| 158 |
+
scatter_input = gr.Number(label="Scatter Sembol Sayısı", value=2, precision=0)
|
| 159 |
+
|
| 160 |
+
gr.Markdown("### 📊 Volatilite")
|
| 161 |
+
volatility_input = gr.Radio(
|
| 162 |
+
choices=["Düşük", "Orta", "Yüksek"],
|
| 163 |
+
value="Orta",
|
| 164 |
+
label="Oyun Volatilitesi"
|
| 165 |
+
)
|
| 166 |
|
| 167 |
submit_btn = gr.Button("Analiz Et ve Tahmin Üret", variant="primary")
|
| 168 |
|
| 169 |
with gr.Column():
|
| 170 |
+
gr.Markdown("### 📈 Sembol Düşme Olasılıkları (Poisson)")
|
| 171 |
prob_output = gr.Label(label="Olasılık Dağılımı")
|
| 172 |
|
| 173 |
gr.Markdown("### 🧠 Groq Yapay Zeka Analiz Raporu")
|
|
|
|
| 175 |
|
| 176 |
submit_btn.click(
|
| 177 |
fn=predict_and_analyze,
|
| 178 |
+
inputs=[game_input, symbol_input, wild_input, scatter_input, spin_input, volatility_input],
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 179 |
outputs=[analysis_output, prob_output]
|
| 180 |
)
|
| 181 |
|
| 182 |
+
gr.Markdown(
|
| 183 |
+
"""
|
| 184 |
+
---
|
| 185 |
+
⚠️ **Sorumlu Oyun Uyarısı**: Bu uygulama yalnızca eğitim ve olasılık analizi amaçlıdır. Slot oyunları şans oyunlarıdır; kaybetme riski her zaman vardır. Lütfen bütçenizi aşmayın ve sorumlu oynayın.
|
| 186 |
+
"""
|
| 187 |
+
)
|
| 188 |
+
|
| 189 |
if __name__ == "__main__":
|
| 190 |
demo.launch()
|