Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -13,107 +13,124 @@ if api_key:
|
|
| 13 |
client = Groq(api_key=api_key)
|
| 14 |
|
| 15 |
# ==========================================
|
| 16 |
-
#
|
| 17 |
# ==========================================
|
| 18 |
-
def
|
| 19 |
"""
|
| 20 |
-
|
| 21 |
-
-
|
| 22 |
-
-
|
| 23 |
-
-
|
| 24 |
-
- spin_count: Simüle edilecek spin sayısı
|
| 25 |
-
- volatility: Düşük / Orta / Yüksek (ödeme sıklığını etkiler)
|
| 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 |
-
|
| 73 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 74 |
|
| 75 |
# ==========================================
|
| 76 |
# 🧠 3. TAHMİN VE ANALİZ MOTORU
|
| 77 |
# ==========================================
|
| 78 |
-
def predict_and_analyze(
|
| 79 |
-
|
| 80 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 81 |
|
| 82 |
-
|
|
|
|
|
|
|
|
|
|
| 83 |
|
| 84 |
# Gradio grafiği için olasılık sözlüğü
|
| 85 |
prob_dict = {
|
| 86 |
-
"
|
| 87 |
-
"
|
| 88 |
-
"
|
| 89 |
-
"Büyük Kazanç (3+ Scatter/Wild)": float(result["p_big_win"]),
|
| 90 |
}
|
| 91 |
|
| 92 |
prompt = f"""
|
| 93 |
-
Sen uzman bir
|
|
|
|
|
|
|
|
|
|
|
|
|
| 94 |
|
| 95 |
-
|
| 96 |
-
|
| 97 |
-
-
|
| 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
|
| 105 |
-
-
|
| 106 |
-
-
|
| 107 |
-
-
|
| 108 |
-
-
|
| 109 |
-
-
|
| 110 |
-
|
| 111 |
-
|
| 112 |
-
|
| 113 |
-
|
| 114 |
-
|
| 115 |
-
|
| 116 |
-
|
|
|
|
| 117 |
"""
|
| 118 |
|
| 119 |
if client:
|
|
@@ -129,45 +146,44 @@ def predict_and_analyze(game_name, symbol_count, wild_count, scatter_count, spin
|
|
| 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
|
| 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="
|
| 140 |
gr.Markdown(
|
| 141 |
"""
|
| 142 |
-
#
|
| 143 |
-
Bu uygulama,
|
| 144 |
"""
|
| 145 |
)
|
| 146 |
|
| 147 |
with gr.Row():
|
| 148 |
with gr.Column():
|
| 149 |
-
gr.Markdown("###
|
| 150 |
-
|
|
|
|
| 151 |
|
| 152 |
-
gr.Markdown("###
|
| 153 |
with gr.Row():
|
| 154 |
-
|
| 155 |
-
|
|
|
|
|
|
|
| 156 |
with gr.Row():
|
| 157 |
-
|
| 158 |
-
|
| 159 |
-
|
| 160 |
-
|
| 161 |
-
|
| 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("### 📈
|
| 171 |
prob_output = gr.Label(label="Olasılık Dağılımı")
|
| 172 |
|
| 173 |
gr.Markdown("### 🧠 Groq Yapay Zeka Analiz Raporu")
|
|
@@ -175,16 +191,14 @@ with gr.Blocks(theme=gr.themes.Soft(primary_hue="amber", secondary_hue="slate"))
|
|
| 175 |
|
| 176 |
submit_btn.click(
|
| 177 |
fn=predict_and_analyze,
|
| 178 |
-
inputs=[
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 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()
|
|
|
|
| 13 |
client = Groq(api_key=api_key)
|
| 14 |
|
| 15 |
# ==========================================
|
| 16 |
+
# ⚽ 2. FIFA H2H POISSON GOL TAHMİN MOTORU
|
| 17 |
# ==========================================
|
| 18 |
+
def calculate_poisson_probabilities(home_rating, away_rating, home_form, away_form, home_injuries, away_injuries):
|
| 19 |
"""
|
| 20 |
+
FIFA H2H sanal lig için Poisson tabanlı gol tahmini.
|
| 21 |
+
- rating: Takım genel gücü (1-99, FIFA Overall Rating)
|
| 22 |
+
- form: Son 5 maç formu (0-15 puan)
|
| 23 |
+
- injuries: Sakat/cezalı oyuncu sayısı
|
|
|
|
|
|
|
| 24 |
"""
|
| 25 |
+
# 1. Takım güçlerini normalize et (FIFA rating 1-99 arası)
|
| 26 |
+
home_attack = max(0.5, home_rating / 70.0) # 70 ortalama rating kabul edildi
|
| 27 |
+
away_attack = max(0.5, away_rating / 70.0)
|
| 28 |
+
|
| 29 |
+
# 2. Form gücü (0-15 -> 0.5-2.0 çarpan)
|
| 30 |
+
home_form_power = (home_form / 15.0) * 1.5 + 0.5
|
| 31 |
+
away_form_power = (away_form / 15.0) * 1.5 + 0.5
|
| 32 |
+
|
| 33 |
+
# 3. Sakatlık cezası: her eksik oyuncu %12 güç kaybı
|
| 34 |
+
home_penalty = max(0.4, 1.0 - (home_injuries * 0.12))
|
| 35 |
+
away_penalty = max(0.4, 1.0 - (away_injuries * 0.12))
|
| 36 |
+
|
| 37 |
+
# 4. Ev sahibi avantajı (FIFA H2H'de ev sahibi ~%15 avantajlı)
|
| 38 |
+
home_advantage = 1.15
|
| 39 |
+
|
| 40 |
+
# 5. Beklenen gol sayıları (Lambda - λ)
|
| 41 |
+
# FIFA H2H ortalama gol: Ev ~1.6, Deplasman ~1.2
|
| 42 |
+
base_home_goals = 1.6
|
| 43 |
+
base_away_goals = 1.2
|
| 44 |
+
|
| 45 |
+
lambda_home = base_home_goals * home_attack * home_form_power * home_penalty * home_advantage
|
| 46 |
+
lambda_away = base_away_goals * away_attack * away_form_power * away_penalty
|
| 47 |
+
|
| 48 |
+
# Lambda değerlerini makul aralığa sıkıştır
|
| 49 |
+
lambda_home = max(0.1, min(4.5, lambda_home))
|
| 50 |
+
lambda_away = max(0.1, min(4.5, lambda_away))
|
| 51 |
+
|
| 52 |
+
# 6. Poisson matrisi (0-6 gol arası)
|
| 53 |
+
max_goals = 6
|
| 54 |
+
home_probs = [poisson.pmf(i, lambda_home) for i in range(max_goals + 1)]
|
| 55 |
+
away_probs = [poisson.pmf(i, lambda_away) for i in range(max_goals + 1)]
|
| 56 |
+
|
| 57 |
+
score_matrix = np.outer(home_probs, away_probs)
|
| 58 |
+
|
| 59 |
+
# 7. Sonuç olasılıkları
|
| 60 |
+
p_home_win = np.sum(np.tril(score_matrix, -1))
|
| 61 |
+
p_draw = np.sum(np.diag(score_matrix))
|
| 62 |
+
p_away_win = np.sum(np.triu(score_matrix, 1))
|
| 63 |
+
|
| 64 |
+
# 8. Alt/Üst 2.5 gol olasılığı
|
| 65 |
+
p_under_25 = 0.0
|
| 66 |
+
p_over_25 = 0.0
|
| 67 |
+
for i in range(max_goals + 1):
|
| 68 |
+
for j in range(max_goals + 1):
|
| 69 |
+
if i + j <= 2:
|
| 70 |
+
p_under_25 += score_matrix[i, j]
|
| 71 |
+
else:
|
| 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(home_team, away_team, home_rating, away_rating,
|
| 87 |
+
home_form, away_form, home_injuries, away_injuries):
|
| 88 |
+
if not home_team or not away_team:
|
| 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 |
+
# En olası skoru bul
|
| 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 |
+
f"{home_team} Galibiyeti (1)": float(p_home),
|
| 104 |
+
"Beraberlik (X)": float(p_draw),
|
| 105 |
+
f"{away_team} Galibiyeti (2)": float(p_away)
|
|
|
|
| 106 |
}
|
| 107 |
|
| 108 |
prompt = f"""
|
| 109 |
+
Sen uzman bir FIFA (EA Sports FC) H2H sanal futbol analistisin.
|
| 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 |
+
📊 Takım Güçleri (FIFA Overall Rating):
|
| 116 |
+
- {home_team}: Rating {home_rating}, Form (Son 5 Maç) {home_form}/15, Sakat/Cezalı {home_injuries}
|
| 117 |
+
- {away_team}: Rating {away_rating}, Form (Son 5 Maç) {away_form}/15, Sakat/Cezalı {away_injuries}
|
|
|
|
|
|
|
|
|
|
|
|
|
| 118 |
|
| 119 |
📈 Poisson Modeli Sonuçları:
|
| 120 |
+
- Beklenen Gol (λ): {home_team} {lam_home:.2f} - {away_team} {lam_away:.2f}
|
| 121 |
+
- 1 (Ev Sahibi): %{p_home*100:.1f}
|
| 122 |
+
- X (Beraberlik): %{p_draw*100:.1f}
|
| 123 |
+
- 2 (Deplasman): %{p_away*100:.1f}
|
| 124 |
+
- En Olası Skor: {most_likely_score} (%{most_likely_prob:.1f})
|
| 125 |
+
- Alt 2.5: %{p_under*100:.1f} | Üst 2.5: %{p_over*100:.1f}
|
| 126 |
+
- Karşılıklı Gol (BTTS): %{p_btts*100:.1f}
|
| 127 |
+
|
| 128 |
+
Raporda şu başlıklar bulunsun:
|
| 129 |
+
1. 🎯 Model Yorumu (Poisson ve beklenen gollerin mantığı)
|
| 130 |
+
2. ⚽ Olası Skor ve Gol Tahmini (Alt/Üst, BTTS değerlendirmesi)
|
| 131 |
+
3. 💡 Değerli Bahis Önerisi (+EV değerlendirmesi)
|
| 132 |
+
|
| 133 |
+
Yorumların rasyonel, nesnel ve profesyonel olsun.
|
| 134 |
"""
|
| 135 |
|
| 136 |
if client:
|
|
|
|
| 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 Poisson grafik tahminini görebilirsiniz.)")
|
| 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="green", secondary_hue="slate")) as demo:
|
| 157 |
gr.Markdown(
|
| 158 |
"""
|
| 159 |
+
# ⚽ FIFA H2H Sanal Lig Poisson Tahmin Radarı
|
| 160 |
+
Bu uygulama, FIFA H2H sanal lig maçları için **Poisson Dağılımı** kullanarak gol ve sonuç tahminleri üretir; ardından **Groq (GPT-OSS)** yapay zekası ile analiz raporu hazırlar.
|
| 161 |
"""
|
| 162 |
)
|
| 163 |
|
| 164 |
with gr.Row():
|
| 165 |
with gr.Column():
|
| 166 |
+
gr.Markdown("### 🏟️ Takım İsimleri")
|
| 167 |
+
home_input = gr.Textbox(label="Ev Sahibi Takım", value="Real Madrid")
|
| 168 |
+
away_input = gr.Textbox(label="Deplasman Takım", value="Barcelona")
|
| 169 |
|
| 170 |
+
gr.Markdown("### ⭐ Takım Güçleri (FIFA Overall Rating)")
|
| 171 |
with gr.Row():
|
| 172 |
+
home_rating_input = gr.Number(label="Ev Sahibi Rating (1-99)", value=85, precision=0)
|
| 173 |
+
away_rating_input = gr.Number(label="Deplasman Rating (1-99)", value=84, precision=0)
|
| 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 |
+
home_inj_input = gr.Number(label="Ev Sakat/Cezalı Sayısı", value=1, precision=0)
|
| 181 |
+
away_inj_input = gr.Number(label="Deplasman Sakat/Cezalı Sayısı", value=2, precision=0)
|
|
|
|
|
|
|
|
|
|
|
|
|
| 182 |
|
| 183 |
submit_btn = gr.Button("Analiz Et ve Tahmin Üret", variant="primary")
|
| 184 |
|
| 185 |
with gr.Column():
|
| 186 |
+
gr.Markdown("### 📈 Maç Sonucu Olasılıkları (Poisson)")
|
| 187 |
prob_output = gr.Label(label="Olasılık Dağılımı")
|
| 188 |
|
| 189 |
gr.Markdown("### 🧠 Groq Yapay Zeka Analiz Raporu")
|
|
|
|
| 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()
|