Spaces:
Sleeping
Sleeping
| 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() | |