Spaces:
Sleeping
Sleeping
File size: 3,124 Bytes
66aebfa 0caa1b8 66aebfa 0caa1b8 34e7689 66aebfa 34e7689 0caa1b8 66aebfa 34e7689 aa456ef 34e7689 66aebfa 34e7689 0caa1b8 34e7689 0caa1b8 34e7689 aa456ef 0caa1b8 34e7689 aa456ef 0caa1b8 aa456ef 0caa1b8 aa456ef |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 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 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 |
import gradio as gr
import json
import random
import matplotlib.pyplot as plt
import os
# ---------------- TAKIMLARI YÜKLE ----------------
with open("superlig_teams_2024_2025.json", "r", encoding="utf-8") as f:
teams = json.load(f)
# ---------------- OYLAR (votes.json) ----------------
def load_votes():
if not os.path.exists("votes.json"):
with open("votes.json", "w") as f:
json.dump({"home": 0, "draw": 0, "away": 0}, f)
with open("votes.json", "r") as f:
return json.load(f)
def save_votes(votes):
with open("votes.json", "w") as f:
json.dump(votes, f)
def vote_result(vote):
votes = load_votes()
if vote in votes:
votes[vote] += 1
save_votes(votes)
total = sum(votes.values())
if total == 0:
return "Henüz oy kullanılmadı."
return (
f"🏠 Home Win: {votes['home'] / total:.0%} | "
f"🤝 Draw: {votes['draw'] / total:.0%} | "
f"🚗 Away Win: {votes['away'] / total:.0%}"
)
# ---------------- YORUMLAR (RAM'de tutulur) ----------------
comments = []
def submit_comment(text):
if text.strip():
comments.append(text.strip())
return "\n".join(comments)
# ---------------- TAHMİN VE GRAFİK ----------------
def predict_match(home_team, away_team):
if home_team == away_team:
return "Lütfen farklı takımlar seçin.", None
scores = {
f"{home_team} wins": random.uniform(1.5, 3.5),
f"{away_team} wins": random.uniform(1.5, 3.5),
"Draw": random.uniform(1.0, 2.5),
}
prediction = max(scores, key=scores.get)
fig, ax = plt.subplots()
ax.bar(scores.keys(), scores.values(), color=["green", "red", "gray"])
ax.set_ylabel("Skor")
ax.set_title("Tahmin Skorları")
fig.tight_layout()
return prediction, fig
# ---------------- GRADIO ARAYÜZÜ ----------------
with gr.Blocks() as demo:
gr.Markdown("## ⚽ SuperLig Predictor")
gr.Markdown("Süper Lig maçlarını tahmin et, oy kullan, yorum yap!")
with gr.Row():
home = gr.Dropdown(teams, label="Ev Sahibi Takım")
away = gr.Dropdown(teams, label="Deplasman Takımı")
predict_btn = gr.Button("Tahmin Et")
result = gr.Textbox(label="Tahmin Sonucu")
chart = gr.Plot()
predict_btn.click(predict_match, [home, away], [result, chart])
gr.Markdown("### 📊 Anket: Sence kim kazanır?")
with gr.Row():
vote_home = gr.Button("🏠 Home")
vote_draw = gr.Button("🤝 Draw")
vote_away = gr.Button("🚗 Away")
poll_output = gr.Textbox(label="Anket Sonucu")
vote_home.click(lambda: vote_result("home"), None, poll_output)
vote_draw.click(lambda: vote_result("draw"), None, poll_output)
vote_away.click(lambda: vote_result("away"), None, poll_output)
gr.Markdown("### 💬 Yorumlar")
comment_input = gr.Textbox(placeholder="Yorumunuzu yazın ve gönderin...")
comment_button = gr.Button("Yorumu Gönder")
comment_list = gr.Textbox(label="Tüm Yorumlar", lines=10)
comment_button.click(submit_comment, comment_input, comment_list)
demo.launch()
|