Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -157,109 +157,5 @@ input, textarea, .gr-textbox { border-radius: 8px; font-size: 16px; }
|
|
157 |
demo.load(update_summary, outputs=[resumen1, resumen2, log_box])
|
158 |
gr.Button("🖼 Exportar Imagen Final").click(export_image, outputs=gr.Image(type="pil"))
|
159 |
|
160 |
-
if __name__ == "__main__":
|
161 |
-
demo.launch()
|
162 |
-
t1_time += elapsed
|
163 |
-
elif active_team == t2_name:
|
164 |
-
t2_time += elapsed
|
165 |
-
start_time = time.time()
|
166 |
-
active_team = t1_name if active_team == t2_name else t2_name
|
167 |
-
return f"Ahora tiene la posesión: {active_team}"
|
168 |
-
|
169 |
-
def show_stats():
|
170 |
-
total = t1_time + t2_time
|
171 |
-
p1 = round((t1_time / total) * 100, 2) if total > 0 else 0
|
172 |
-
p2 = 100 - p1 if total > 0 else 0
|
173 |
-
return f"{t1_name}: {p1}%", f"{t2_name}: {p2}%", generate_possession_bar(p1, p2)
|
174 |
-
|
175 |
-
def add_stat(team, stat):
|
176 |
-
if team == "1":
|
177 |
-
team1_stats[stat] += 1
|
178 |
-
historial.append(f"{t1_name} - {stat.upper()} +1")
|
179 |
-
else:
|
180 |
-
team2_stats[stat] += 1
|
181 |
-
historial.append(f"{t2_name} - {stat.upper()} +1")
|
182 |
-
return update_summary()
|
183 |
-
|
184 |
-
def update_summary():
|
185 |
-
sum1 = f"{t1_name} - 🟨 {team1_stats['amarillas']} | 🔵 {team1_stats['rojas']} | ⚽ {team1_stats['corners']}"
|
186 |
-
sum2 = f"{t2_name} - 🟨 {team2_stats['amarillas']} | 🔵 {team2_stats['rojas']} | ⚽ {team2_stats['corners']}"
|
187 |
-
return sum1, sum2, "\n".join(historial)
|
188 |
-
|
189 |
-
def set_team_info(name1, name2, logo1, logo2):
|
190 |
-
global t1_name, t2_name, t1_logo, t2_logo
|
191 |
-
t1_name = name1
|
192 |
-
t2_name = name2
|
193 |
-
t1_logo = logo1
|
194 |
-
t2_logo = logo2
|
195 |
-
return update_summary()
|
196 |
-
|
197 |
-
def generate_possession_bar(p1, p2):
|
198 |
-
bar = Image.new('RGB', (400, 40), color='black')
|
199 |
-
draw = ImageDraw.Draw(bar)
|
200 |
-
draw.rectangle([0, 0, int(p1 * 4), 40], fill='blue')
|
201 |
-
draw.rectangle([int(p1 * 4), 0, 400, 40], fill='red')
|
202 |
-
return bar
|
203 |
-
|
204 |
-
def export_image():
|
205 |
-
img = Image.new('RGB', (800, 400), color='#001845')
|
206 |
-
draw = ImageDraw.Draw(img)
|
207 |
-
font = ImageFont.load_default()
|
208 |
-
|
209 |
-
draw.text((20, 20), f"{t1_name} vs {t2_name}", font=font, fill='white')
|
210 |
-
draw.text((20, 50), f"🟨 {team1_stats['amarillas']} 🔵 {team1_stats['rojas']} ⚽ {team1_stats['corners']}", font=font, fill='blue')
|
211 |
-
draw.text((20, 70), f"🟨 {team2_stats['amarillas']} 🔵 {team2_stats['rojas']} ⚽ {team2_stats['corners']}", font=font, fill='red')
|
212 |
-
|
213 |
-
p1 = round((t1_time / (t1_time + t2_time)) * 100, 2) if (t1_time + t2_time) > 0 else 0
|
214 |
-
p2 = 100 - p1
|
215 |
-
|
216 |
-
draw.text((20, 120), f"Posesión: {t1_name} {p1}% - {t2_name} {p2}%", font=font, fill='white')
|
217 |
-
draw.text((20, 160), "Historial:", font=font, fill='yellow')
|
218 |
-
|
219 |
-
for i, ev in enumerate(historial[-10:]):
|
220 |
-
draw.text((40, 180 + i * 20), ev, font=font, fill='white')
|
221 |
-
|
222 |
-
return img
|
223 |
-
|
224 |
-
with gr.Blocks() as demo:
|
225 |
-
gr.Markdown("## 🏆 Medidor de Posesión y Estadísticas Estilo Champions League")
|
226 |
-
|
227 |
-
with gr.Row():
|
228 |
-
name1 = gr.Textbox(value="Equipo 1", label="Nombre Equipo 1")
|
229 |
-
name2 = gr.Textbox(value="Equipo 2", label="Nombre Equipo 2")
|
230 |
-
logo1 = gr.Image(type="pil", label="Escudo 1")
|
231 |
-
logo2 = gr.Image(type="pil", label="Escudo 2")
|
232 |
-
gr.Button("✅ Establecer Equipos").click(set_team_info, inputs=[name1, name2, logo1, logo2], outputs=[])
|
233 |
-
|
234 |
-
with gr.Row():
|
235 |
-
gr.Button("🕒 Iniciar Posesión Equipo 1").click(lambda: start_possession(t1_name), outputs=[])
|
236 |
-
gr.Button("🕒 Iniciar Posesión Equipo 2").click(lambda: start_possession(t2_name), outputs=[])
|
237 |
-
gr.Button("🔁 Cambiar Posesión").click(switch_possession, outputs=[])
|
238 |
-
|
239 |
-
with gr.Row():
|
240 |
-
btn_stats = gr.Button("📊 Mostrar posesión")
|
241 |
-
p1_out = gr.Textbox(label="Posesión Equipo 1")
|
242 |
-
p2_out = gr.Textbox(label="Posesión Equipo 2")
|
243 |
-
bar = gr.Image(label="Barra 3D de posesión")
|
244 |
-
btn_stats.click(show_stats, outputs=[p1_out, p2_out, bar])
|
245 |
-
|
246 |
-
with gr.Row():
|
247 |
-
gr.Button("🟨 Amarilla Equipo 1").click(lambda: add_stat("1", "amarillas"), outputs=[])
|
248 |
-
gr.Button("🔵 Roja Equipo 1").click(lambda: add_stat("1", "rojas"), outputs=[])
|
249 |
-
gr.Button("⚽ Córner Equipo 1").click(lambda: add_stat("1", "corners"), outputs=[])
|
250 |
-
|
251 |
-
with gr.Row():
|
252 |
-
gr.Button("🟨 Amarilla Equipo 2").click(lambda: add_stat("2", "amarillas"), outputs=[])
|
253 |
-
gr.Button("🔵 Roja Equipo 2").click(lambda: add_stat("2", "rojas"), outputs=[])
|
254 |
-
gr.Button("⚽ Córner Equipo 2").click(lambda: add_stat("2", "corners"), outputs=[])
|
255 |
-
|
256 |
-
resumen1 = gr.Textbox(label="Resumen Equipo 1")
|
257 |
-
resumen2 = gr.Textbox(label="Resumen Equipo 2")
|
258 |
-
log_box = gr.Textbox(label="Historial del partido", lines=10)
|
259 |
-
|
260 |
-
demo.load(update_summary, outputs=[resumen1, resumen2, log_box])
|
261 |
-
|
262 |
-
gr.Button("🖼 Exportar Imagen Final").click(export_image, outputs=gr.Image(type="pil"))
|
263 |
-
|
264 |
if __name__ == "__main__":
|
265 |
demo.launch()
|
|
|
157 |
demo.load(update_summary, outputs=[resumen1, resumen2, log_box])
|
158 |
gr.Button("🖼 Exportar Imagen Final").click(export_image, outputs=gr.Image(type="pil"))
|
159 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
160 |
if __name__ == "__main__":
|
161 |
demo.launch()
|