Phytgoras commited on
Commit
aa456ef
·
verified ·
1 Parent(s): 0dc7848

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +57 -17
app.py CHANGED
@@ -1,6 +1,7 @@
1
  import gradio as gr
2
  import random
3
 
 
4
  teams = [
5
  "Adana Demirspor", "Alanyaspor", "Antalyaspor", "Beşiktaş", "Bodrum FK",
6
  "Çaykur Rizespor", "Eyüpspor", "Fenerbahçe", "Galatasaray", "Gaziantep FK",
@@ -8,27 +9,66 @@ teams = [
8
  "Konyaspor", "Samsunspor", "Sivasspor", "Trabzonspor"
9
  ]
10
 
 
 
 
 
 
11
  def predict_match(home_team, away_team):
12
  if home_team == away_team:
13
  return "Please select two different teams."
14
-
15
- result = random.choices(
16
  [f"{home_team} wins", f"{away_team} wins", "Draw"],
17
  weights=[0.4, 0.4, 0.2],
18
  k=1
19
  )[0]
20
- return result
21
-
22
- demo = gr.Interface(
23
- fn=predict_match,
24
- inputs=[
25
- gr.Dropdown(teams, label="Home Team"),
26
- gr.Dropdown(teams, label="Away Team")
27
- ],
28
- outputs=gr.Textbox(label="Prediction"),
29
- title="SuperLig Predictor",
30
- description="Select two Süper Lig teams to predict the match result."
31
- )
32
-
33
- if __name__ == "__main__":
34
- demo.launch()
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
  import gradio as gr
2
  import random
3
 
4
+ # Takım listesi
5
  teams = [
6
  "Adana Demirspor", "Alanyaspor", "Antalyaspor", "Beşiktaş", "Bodrum FK",
7
  "Çaykur Rizespor", "Eyüpspor", "Fenerbahçe", "Galatasaray", "Gaziantep FK",
 
9
  "Konyaspor", "Samsunspor", "Sivasspor", "Trabzonspor"
10
  ]
11
 
12
+ # Geçici veri yapıları (sunucu kapanınca silinir)
13
+ comments = []
14
+ votes = {"home": 0, "draw": 0, "away": 0}
15
+
16
+ # Tahmin fonksiyonu
17
  def predict_match(home_team, away_team):
18
  if home_team == away_team:
19
  return "Please select two different teams."
20
+ return random.choices(
 
21
  [f"{home_team} wins", f"{away_team} wins", "Draw"],
22
  weights=[0.4, 0.4, 0.2],
23
  k=1
24
  )[0]
25
+
26
+ # Yorum ekleme fonksiyonu
27
+ def add_comment(comment_text):
28
+ if comment_text.strip():
29
+ comments.append(comment_text.strip())
30
+ return comments
31
+
32
+ # Oylama fonksiyonu
33
+ def vote(choice):
34
+ if choice in votes:
35
+ votes[choice] += 1
36
+ total = sum(votes.values())
37
+ if total == 0:
38
+ return "No votes yet."
39
+ return (
40
+ f"🏠 Home Win: {votes['home'] / total:.0%} | "
41
+ f"🤝 Draw: {votes['draw'] / total:.0%} | "
42
+ f"🚗 Away Win: {votes['away'] / total:.0%}"
43
+ )
44
+
45
+ # Arayüz elemanları
46
+ with gr.Blocks() as demo:
47
+ gr.Markdown("## 🏆 SuperLig Predictor")
48
+ gr.Markdown("Predict match results, vote, and share your opinions!")
49
+
50
+ with gr.Row():
51
+ home = gr.Dropdown(teams, label="Home Team")
52
+ away = gr.Dropdown(teams, label="Away Team")
53
+ predict_btn = gr.Button("Predict")
54
+ prediction_output = gr.Textbox(label="Prediction Result")
55
+ predict_btn.click(predict_match, [home, away], prediction_output)
56
+
57
+ gr.Markdown("### 📊 Match Poll: Who Will Win?")
58
+ with gr.Row():
59
+ vote_home = gr.Button("Vote Home")
60
+ vote_draw = gr.Button("Vote Draw")
61
+ vote_away = gr.Button("Vote Away")
62
+ vote_result = gr.Textbox(label="Live Poll Results")
63
+ vote_home.click(lambda: vote("home"), None, vote_result)
64
+ vote_draw.click(lambda: vote("draw"), None, vote_result)
65
+ vote_away.click(lambda: vote("away"), None, vote_result)
66
+
67
+ gr.Markdown("### 💬 Match Comments")
68
+ comment_input = gr.Textbox(placeholder="Write your comment here...")
69
+ submit_comment = gr.Button("Submit Comment")
70
+ comment_list = gr.Textbox(label="All Comments", lines=10)
71
+ submit_comment.click(add_comment, comment_input, comment_list)
72
+
73
+ demo.launch()
74
+