Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -2,19 +2,50 @@ import gradio as gr
|
|
| 2 |
import json
|
| 3 |
import random
|
| 4 |
import matplotlib.pyplot as plt
|
|
|
|
| 5 |
|
| 6 |
-
#
|
| 7 |
with open("superlig_teams_2024_2025.json", "r", encoding="utf-8") as f:
|
| 8 |
teams = json.load(f)
|
| 9 |
|
| 10 |
-
#
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 11 |
comments = []
|
| 12 |
-
votes = {"home": 0, "draw": 0, "away": 0}
|
| 13 |
|
| 14 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 15 |
def predict_match(home_team, away_team):
|
| 16 |
if home_team == away_team:
|
| 17 |
-
return "
|
| 18 |
|
| 19 |
scores = {
|
| 20 |
f"{home_team} wins": random.uniform(1.5, 3.5),
|
|
@@ -23,38 +54,18 @@ def predict_match(home_team, away_team):
|
|
| 23 |
}
|
| 24 |
prediction = max(scores, key=scores.get)
|
| 25 |
|
| 26 |
-
# Grafik oluştur
|
| 27 |
fig, ax = plt.subplots()
|
| 28 |
-
ax.bar(scores.keys(), scores.values())
|
| 29 |
-
ax.set_ylabel("
|
| 30 |
ax.set_title("Tahmin Skorları")
|
| 31 |
fig.tight_layout()
|
| 32 |
|
| 33 |
return prediction, fig
|
| 34 |
|
| 35 |
-
#
|
| 36 |
-
def submit_comment(text):
|
| 37 |
-
if text.strip():
|
| 38 |
-
comments.append(text.strip())
|
| 39 |
-
return "\n".join(comments)
|
| 40 |
-
|
| 41 |
-
# Oylama
|
| 42 |
-
def vote_result(vote):
|
| 43 |
-
if vote in votes:
|
| 44 |
-
votes[vote] += 1
|
| 45 |
-
total = sum(votes.values())
|
| 46 |
-
if total == 0:
|
| 47 |
-
return "Henüz oy kullanılmadı."
|
| 48 |
-
return (
|
| 49 |
-
f"🏠 Home Win: {votes['home'] / total:.0%} | "
|
| 50 |
-
f"🤝 Draw: {votes['draw'] / total:.0%} | "
|
| 51 |
-
f"🚗 Away Win: {votes['away'] / total:.0%}"
|
| 52 |
-
)
|
| 53 |
-
|
| 54 |
-
# Arayüz
|
| 55 |
with gr.Blocks() as demo:
|
| 56 |
gr.Markdown("## ⚽ SuperLig Predictor")
|
| 57 |
-
gr.Markdown("
|
| 58 |
|
| 59 |
with gr.Row():
|
| 60 |
home = gr.Dropdown(teams, label="Ev Sahibi Takım")
|
|
@@ -63,7 +74,6 @@ with gr.Blocks() as demo:
|
|
| 63 |
predict_btn = gr.Button("Tahmin Et")
|
| 64 |
result = gr.Textbox(label="Tahmin Sonucu")
|
| 65 |
chart = gr.Plot()
|
| 66 |
-
|
| 67 |
predict_btn.click(predict_match, [home, away], [result, chart])
|
| 68 |
|
| 69 |
gr.Markdown("### 📊 Anket: Sence kim kazanır?")
|
|
|
|
| 2 |
import json
|
| 3 |
import random
|
| 4 |
import matplotlib.pyplot as plt
|
| 5 |
+
import os
|
| 6 |
|
| 7 |
+
# ---------------- TAKIMLARI YÜKLE ----------------
|
| 8 |
with open("superlig_teams_2024_2025.json", "r", encoding="utf-8") as f:
|
| 9 |
teams = json.load(f)
|
| 10 |
|
| 11 |
+
# ---------------- OYLAR (votes.json) ----------------
|
| 12 |
+
def load_votes():
|
| 13 |
+
if not os.path.exists("votes.json"):
|
| 14 |
+
with open("votes.json", "w") as f:
|
| 15 |
+
json.dump({"home": 0, "draw": 0, "away": 0}, f)
|
| 16 |
+
with open("votes.json", "r") as f:
|
| 17 |
+
return json.load(f)
|
| 18 |
+
|
| 19 |
+
def save_votes(votes):
|
| 20 |
+
with open("votes.json", "w") as f:
|
| 21 |
+
json.dump(votes, f)
|
| 22 |
+
|
| 23 |
+
def vote_result(vote):
|
| 24 |
+
votes = load_votes()
|
| 25 |
+
if vote in votes:
|
| 26 |
+
votes[vote] += 1
|
| 27 |
+
save_votes(votes)
|
| 28 |
+
total = sum(votes.values())
|
| 29 |
+
if total == 0:
|
| 30 |
+
return "Henüz oy kullanılmadı."
|
| 31 |
+
return (
|
| 32 |
+
f"🏠 Home Win: {votes['home'] / total:.0%} | "
|
| 33 |
+
f"🤝 Draw: {votes['draw'] / total:.0%} | "
|
| 34 |
+
f"🚗 Away Win: {votes['away'] / total:.0%}"
|
| 35 |
+
)
|
| 36 |
+
|
| 37 |
+
# ---------------- YORUMLAR (RAM'de tutulur) ----------------
|
| 38 |
comments = []
|
|
|
|
| 39 |
|
| 40 |
+
def submit_comment(text):
|
| 41 |
+
if text.strip():
|
| 42 |
+
comments.append(text.strip())
|
| 43 |
+
return "\n".join(comments)
|
| 44 |
+
|
| 45 |
+
# ---------------- TAHMİN VE GRAFİK ----------------
|
| 46 |
def predict_match(home_team, away_team):
|
| 47 |
if home_team == away_team:
|
| 48 |
+
return "Lütfen farklı takımlar seçin.", None
|
| 49 |
|
| 50 |
scores = {
|
| 51 |
f"{home_team} wins": random.uniform(1.5, 3.5),
|
|
|
|
| 54 |
}
|
| 55 |
prediction = max(scores, key=scores.get)
|
| 56 |
|
|
|
|
| 57 |
fig, ax = plt.subplots()
|
| 58 |
+
ax.bar(scores.keys(), scores.values(), color=["green", "red", "gray"])
|
| 59 |
+
ax.set_ylabel("Skor")
|
| 60 |
ax.set_title("Tahmin Skorları")
|
| 61 |
fig.tight_layout()
|
| 62 |
|
| 63 |
return prediction, fig
|
| 64 |
|
| 65 |
+
# ---------------- GRADIO ARAYÜZÜ ----------------
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 66 |
with gr.Blocks() as demo:
|
| 67 |
gr.Markdown("## ⚽ SuperLig Predictor")
|
| 68 |
+
gr.Markdown("Süper Lig maçlarını tahmin et, oy kullan, yorum yap!")
|
| 69 |
|
| 70 |
with gr.Row():
|
| 71 |
home = gr.Dropdown(teams, label="Ev Sahibi Takım")
|
|
|
|
| 74 |
predict_btn = gr.Button("Tahmin Et")
|
| 75 |
result = gr.Textbox(label="Tahmin Sonucu")
|
| 76 |
chart = gr.Plot()
|
|
|
|
| 77 |
predict_btn.click(predict_match, [home, away], [result, chart])
|
| 78 |
|
| 79 |
gr.Markdown("### 📊 Anket: Sence kim kazanır?")
|