Spaces:
Sleeping
Sleeping
requirements.txt
Browse files
app.py
ADDED
@@ -0,0 +1,50 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import gradio as gr
|
2 |
+
import time
|
3 |
+
|
4 |
+
team1_time = 0
|
5 |
+
team2_time = 0
|
6 |
+
start_time = None
|
7 |
+
active_team = None
|
8 |
+
|
9 |
+
def start_possession(team):
|
10 |
+
global start_time, active_team
|
11 |
+
start_time = time.time()
|
12 |
+
active_team = team
|
13 |
+
return f"Posesi贸n para: {team}"
|
14 |
+
|
15 |
+
def switch_possession():
|
16 |
+
global team1_time, team2_time, start_time, active_team
|
17 |
+
if active_team and start_time:
|
18 |
+
elapsed = time.time() - start_time
|
19 |
+
if active_team == "Equipo 1":
|
20 |
+
team1_time += elapsed
|
21 |
+
else:
|
22 |
+
team2_time += elapsed
|
23 |
+
start_time = time.time()
|
24 |
+
active_team = "Equipo 1" if active_team == "Equipo 2" else "Equipo 2"
|
25 |
+
return f"Ahora tiene la posesi贸n: {active_team}"
|
26 |
+
|
27 |
+
def show_stats():
|
28 |
+
total = team1_time + team2_time
|
29 |
+
p1 = round((team1_time / total) * 100, 2) if total > 0 else 0
|
30 |
+
p2 = 100 - p1 if total > 0 else 0
|
31 |
+
return f"Equipo 1: {p1}%", f"Equipo 2: {p2}%"
|
32 |
+
|
33 |
+
with gr.Blocks() as demo:
|
34 |
+
gr.Markdown("# Medidor de Posesi贸n de Bal贸n 鈿斤笍")
|
35 |
+
|
36 |
+
btn1 = gr.Button("Equipo 1 empieza")
|
37 |
+
btn2 = gr.Button("Equipo 2 empieza")
|
38 |
+
btn_switch = gr.Button("Cambiar posesi贸n")
|
39 |
+
btn_stats = gr.Button("Mostrar Estad铆sticas")
|
40 |
+
|
41 |
+
out = gr.Textbox()
|
42 |
+
stats1 = gr.Textbox(label="Equipo 1")
|
43 |
+
stats2 = gr.Textbox(label="Equipo 2")
|
44 |
+
|
45 |
+
btn1.click(start_possession, inputs=[], outputs=out, fn_kwargs={"team": "Equipo 1"})
|
46 |
+
btn2.click(start_possession, inputs=[], outputs=out, fn_kwargs={"team": "Equipo 2"})
|
47 |
+
btn_switch.click(switch_possession, outputs=out)
|
48 |
+
btn_stats.click(show_stats, outputs=[stats1, stats2])
|
49 |
+
|
50 |
+
demo.launch()
|