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|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import gradio as gr
|
| 2 |
+
import time
|
| 3 |
+
import json
|
| 4 |
+
from typing import Dict, List, Tuple
|
| 5 |
+
import random
|
| 6 |
+
|
| 7 |
+
class ChromecastController:
|
| 8 |
+
def __init__(self):
|
| 9 |
+
self.tv_states = {
|
| 10 |
+
1: {"name": "TV - Sala Principal", "device": "Chromecast Ultra", "connected": True, "playing": False, "volume": 50, "content": "Esperando..."},
|
| 11 |
+
2: {"name": "TV - Barra", "device": "Chromecast 4K", "connected": True, "playing": False, "volume": 50, "content": "Esperando..."},
|
| 12 |
+
3: {"name": "TV - Terraza", "device": "Chromecast with Google TV", "connected": True, "playing": False, "volume": 50, "content": "Esperando..."}
|
| 13 |
+
}
|
| 14 |
+
self.current_video = None
|
| 15 |
+
self.is_playing = False
|
| 16 |
+
self.progress = 0
|
| 17 |
+
self.playlist = [
|
| 18 |
+
{"title": "Video Promocional", "source": "YouTube", "url": "https://www.youtube.com/watch?v=dQw4w9WgXcQ", "duration": "3:45"},
|
| 19 |
+
{"title": "Video Corporativo", "source": "Vimeo", "url": "https://vimeo.com/123456789", "duration": "2:30"},
|
| 20 |
+
{"title": "Video Evento", "source": "Directo", "url": "https://example.com/video.mp4", "duration": "5:15"}
|
| 21 |
+
]
|
| 22 |
+
|
| 23 |
+
def get_tv_status(self, tv_id: int) -> Dict:
|
| 24 |
+
"""Get status of a specific TV"""
|
| 25 |
+
return self.tv_states.get(tv_id, {})
|
| 26 |
+
|
| 27 |
+
def get_all_tvs_status(self) -> List[Dict]:
|
| 28 |
+
"""Get status of all TVs"""
|
| 29 |
+
return [self.tv_states[i] for i in range(1, 4)]
|
| 30 |
+
|
| 31 |
+
def load_video(self, url: str) -> Tuple[str, str, str]:
|
| 32 |
+
"""Load a video URL to all TVs"""
|
| 33 |
+
if not url:
|
| 34 |
+
return "❌ Error", "Por favor, introduce una URL válida", "error"
|
| 35 |
+
|
| 36 |
+
self.current_video = url
|
| 37 |
+
video_name = self._extract_video_name(url)
|
| 38 |
+
|
| 39 |
+
for i in range(1, 4):
|
| 40 |
+
self.tv_states[i]["content"] = video_name
|
| 41 |
+
|
| 42 |
+
self.progress = 0
|
| 43 |
+
return "✅ Éxito", f"Video '{video_name}' cargado en todas las TVs", "success"
|
| 44 |
+
|
| 45 |
+
def _extract_video_name(self, url: str) -> str:
|
| 46 |
+
"""Extract video name from URL"""
|
| 47 |
+
if "youtube" in url.lower():
|
| 48 |
+
return "Video de YouTube"
|
| 49 |
+
elif "vimeo" in url.lower():
|
| 50 |
+
return "Video de Vimeo"
|
| 51 |
+
elif ".mp4" in url.lower():
|
| 52 |
+
return "Video Directo"
|
| 53 |
+
else:
|
| 54 |
+
return "Video Online"
|
| 55 |
+
|
| 56 |
+
def control_tv(self, tv_id: int, action: str) -> Tuple[str, str, str]:
|
| 57 |
+
"""Control individual TV"""
|
| 58 |
+
if tv_id not in self.tv_states:
|
| 59 |
+
return "❌ Error", f"TV {tv_id} no encontrada", "error"
|
| 60 |
+
|
| 61 |
+
tv = self.tv_states[tv_id]
|
| 62 |
+
|
| 63 |
+
if action == "play":
|
| 64 |
+
if not self.current_video:
|
| 65 |
+
return "❌ Error", "No hay video cargado", "error"
|
| 66 |
+
tv["playing"] = True
|
| 67 |
+
self.is_playing = True
|
| 68 |
+
return "✅ Reproduciendo", f"TV {tv_id} está reproduciendo", "success"
|
| 69 |
+
|
| 70 |
+
elif action == "pause":
|
| 71 |
+
tv["playing"] = False
|
| 72 |
+
return "⏸️ Pausado", f"TV {tv_id} pausado", "info"
|
| 73 |
+
|
| 74 |
+
elif action == "stop":
|
| 75 |
+
tv["playing"] = False
|
| 76 |
+
tv["content"] = "Esperando..."
|
| 77 |
+
return "⏹️ Detenido", f"TV {tv_id} detenido", "info"
|
| 78 |
+
|
| 79 |
+
elif action == "mute":
|
| 80 |
+
tv["volume"] = 0 if tv["volume"] > 0 else 50
|
| 81 |
+
status = "silenciado" if tv["volume"] == 0 else "activado"
|
| 82 |
+
return "🔇 Volumen", f"TV {tv_id} {status}", "info"
|
| 83 |
+
|
| 84 |
+
return "❌ Error", "Acción no reconocida", "error"
|
| 85 |
+
|
| 86 |
+
def control_all_tvs(self, action: str) -> Tuple[str, str, str]:
|
| 87 |
+
"""Control all TVs simultaneously"""
|
| 88 |
+
if action == "play":
|
| 89 |
+
if not self.current_video:
|
| 90 |
+
return "❌ Error", "Por favor, carga un video primero", "error"
|
| 91 |
+
|
| 92 |
+
for i in range(1, 4):
|
| 93 |
+
self.tv_states[i]["playing"] = True
|
| 94 |
+
|
| 95 |
+
self.is_playing = True
|
| 96 |
+
return "✅ Reproduciendo", "Reproduciendo en todas las TVs", "success"
|
| 97 |
+
|
| 98 |
+
elif action == "pause":
|
| 99 |
+
for i in range(1, 4):
|
| 100 |
+
self.tv_states[i]["playing"] = False
|
| 101 |
+
|
| 102 |
+
self.is_playing = False
|
| 103 |
+
return "⏸️ Pausado", "Pausado en todas las TVs", "info"
|
| 104 |
+
|
| 105 |
+
elif action == "stop":
|
| 106 |
+
for i in range(1, 4):
|
| 107 |
+
self.tv_states[i]["playing"] = False
|
| 108 |
+
self.tv_states[i]["content"] = "Esperando..."
|
| 109 |
+
|
| 110 |
+
self.is_playing = False
|
| 111 |
+
self.current_video = None
|
| 112 |
+
self.progress = 0
|
| 113 |
+
return "⏹️ Detenido", "Transmisión detenida", "info"
|
| 114 |
+
|
| 115 |
+
elif action == "mute":
|
| 116 |
+
for i in range(1, 4):
|
| 117 |
+
self.tv_states[i]["volume"] = 0 if self.tv_states[i]["volume"] > 0 else 50
|
| 118 |
+
|
| 119 |
+
return "🔇 Volumen", "Silencio toggled en todas las TVs", "info"
|
| 120 |
+
|
| 121 |
+
return "❌ Error", "Acción no reconocida", "error"
|
| 122 |
+
|
| 123 |
+
def change_volume(self, volume: int) -> Tuple[str, str, str]:
|
| 124 |
+
"""Change volume for all TVs"""
|
| 125 |
+
volume = max(0, min(100, volume))
|
| 126 |
+
for i in range(1, 4):
|
| 127 |
+
self.tv_states[i]["volume"] = volume
|
| 128 |
+
|
| 129 |
+
return "🔊 Volumen", f"Volumen ajustado a {volume}%", "info"
|
| 130 |
+
|
| 131 |
+
def update_progress(self) -> Tuple[float, str, str]:
|
| 132 |
+
"""Update playback progress"""
|
| 133 |
+
if self.is_playing and self.progress < 100:
|
| 134 |
+
self.progress += 0.5
|
| 135 |
+
|
| 136 |
+
current_seconds = int(self.progress * 2.25)
|
| 137 |
+
current_time = f"{current_seconds // 60:02d}:{current_seconds % 60:02d}"
|
| 138 |
+
duration = "03:45"
|
| 139 |
+
|
| 140 |
+
return self.progress, current_time, duration
|
| 141 |
+
|
| 142 |
+
def get_playlist(self) -> List[Dict]:
|
| 143 |
+
"""Get current playlist"""
|
| 144 |
+
return self.playlist
|
| 145 |
+
|
| 146 |
+
def add_to_playlist(self, url: str, title: str = "") -> Tuple[str, str, str]:
|
| 147 |
+
"""Add video to playlist"""
|
| 148 |
+
if not url:
|
| 149 |
+
return "❌ Error", "Introduce una URL primero", "error"
|
| 150 |
+
|
| 151 |
+
if not title:
|
| 152 |
+
title = self._extract_video_name(url)
|
| 153 |
+
|
| 154 |
+
self.playlist.append({
|
| 155 |
+
"title": title,
|
| 156 |
+
"source": "Custom",
|
| 157 |
+
"url": url,
|
| 158 |
+
"duration": "--:--"
|
| 159 |
+
})
|
| 160 |
+
|
| 161 |
+
return "✅ Éxito", "Video agregado a la playlist", "success"
|
| 162 |
+
|
| 163 |
+
def play_from_playlist(self, index: int) -> Tuple[str, str, str]:
|
| 164 |
+
"""Play video from playlist"""
|
| 165 |
+
if 0 <= index < len(self.playlist):
|
| 166 |
+
video = self.playlist[index]
|
| 167 |
+
return self.load_video(video["url"])
|
| 168 |
+
|
| 169 |
+
return "❌ Error", "Video no encontrado en playlist", "error"
|
| 170 |
+
|
| 171 |
+
# Initialize controller
|
| 172 |
+
controller = ChromecastController()
|
| 173 |
+
|
| 174 |
+
def update_tvs_display():
|
| 175 |
+
"""Update the TVs status display"""
|
| 176 |
+
statuses = controller.get_all_tvs_status()
|
| 177 |
+
html = ""
|
| 178 |
+
|
| 179 |
+
for i, tv in enumerate(statuses, 1):
|
| 180 |
+
status_class = "connected" if tv["connected"] else "disconnected"
|
| 181 |
+
if tv["playing"]:
|
| 182 |
+
status_class = "playing"
|
| 183 |
+
|
| 184 |
+
status_text = "Conectado" if status_class == "connected" else "Desconectado"
|
| 185 |
+
if status_class == "playing":
|
| 186 |
+
status_text = "Reproduciendo"
|
| 187 |
+
|
| 188 |
+
status_color = {
|
| 189 |
+
"connected": "#16a34a",
|
| 190 |
+
"playing": "#d97706",
|
| 191 |
+
"disconnected": "#dc2626"
|
| 192 |
+
}[status_class]
|
| 193 |
+
|
| 194 |
+
html += f"""
|
| 195 |
+
<div style="background: white; border-radius: 12px; padding: 16px; margin: 8px 0; box-shadow: 0 2px 8px rgba(0,0,0,0.1);">
|
| 196 |
+
<div style="display: flex; justify-content: space-between; align-items: center; margin-bottom: 12px;">
|
| 197 |
+
<h3 style="margin: 0; display: flex; align-items: center; gap: 8px;">
|
| 198 |
+
📺 {tv['name']}
|
| 199 |
+
</h3>
|
| 200 |
+
<span style="background: {status_color}20; color: {status_color}; padding: 4px 12px; border-radius: 8px; font-size: 12px; font-weight: 600;">
|
| 201 |
+
{status_text}
|
| 202 |
+
</span>
|
| 203 |
+
</div>
|
| 204 |
+
<div style="display: grid; gap: 8px; margin-bottom: 12px;">
|
| 205 |
+
<div style="display: flex; justify-content: space-between; padding: 8px; background: #f3f4f6; border-radius: 8px;">
|
| 206 |
+
<span style="font-weight: 600; color: #6b7280;">Dispositivo:</span>
|
| 207 |
+
<span>{tv['device']}</span>
|
| 208 |
+
</div>
|
| 209 |
+
<div style="display: flex; justify-content: space-between; padding: 8px; background: #f3f4f6; border-radius: 8px;">
|
| 210 |
+
<span style="font-weight: 600; color: #6b7280;">Reproduciendo:</span>
|
| 211 |
+
<span id="tv{i}-content">{tv['content']}</span>
|
| 212 |
+
</div>
|
| 213 |
+
<div style="display: flex; justify-content: space-between; padding: 8px; background: #f3f4f6; border-radius: 8px;">
|
| 214 |
+
<span style="font-weight: 600; color: #6b7280;">Volumen:</span>
|
| 215 |
+
<span id="tv{i}-volume">{tv['volume']}%</span>
|
| 216 |
+
</div>
|
| 217 |
+
</div>
|
| 218 |
+
</div>
|
| 219 |
+
"""
|
| 220 |
+
|
| 221 |
+
return html
|
| 222 |
+
|
| 223 |
+
def update_playlist_display():
|
| 224 |
+
"""Update the playlist display"""
|
| 225 |
+
playlist = controller.get_playlist()
|
| 226 |
+
html = ""
|
| 227 |
+
|
| 228 |
+
for i, video in enumerate(playlist):
|
| 229 |
+
html += f"""
|
| 230 |
+
<div style="background: #f3f4f6; border-radius: 8px; padding: 12px; margin: 4px 0; cursor: pointer; transition: all 0.3s;"
|
| 231 |
+
onmouseover="this.style.background='#e5e7eb'" onmouseout="this.style.background='#f3f4f6'">
|
| 232 |
+
<div style="display: flex; justify-content: space-between; align-items: center;">
|
| 233 |
+
<div style="display: flex; align-items: center; gap: 12px;">
|
| 234 |
+
<img src="https://picsum.photos/seed/video{i}/60/40" alt="Thumbnail" style="width: 60px; height: 40px; border-radius: 4px; object-fit: cover;">
|
| 235 |
+
<div>
|
| 236 |
+
<h4 style="margin: 0; font-size: 14px;">{video['title']}</h4>
|
| 237 |
+
<p style="margin: 0; font-size: 12px; color: #6b7280;">{video['source']} • {video['duration']}</p>
|
| 238 |
+
</div>
|
| 239 |
+
</div>
|
| 240 |
+
<div style="display: flex; gap: 4px;">
|
| 241 |
+
<button onclick="play_playlist_item({i})" style="background: #10b981; color: white; border: none; padding: 6px 12px; border-radius: 6px; cursor: pointer;">▶️</button>
|
| 242 |
+
</div>
|
| 243 |
+
</div>
|
| 244 |
+
</div>
|
| 245 |
+
"""
|
| 246 |
+
|
| 247 |
+
return html
|
| 248 |
+
|
| 249 |
+
def load_video_url(url):
|
| 250 |
+
"""Load video from URL"""
|
| 251 |
+
title, message, status = controller.load_video(url)
|
| 252 |
+
return title, message, update_tvs_display(), url
|
| 253 |
+
|
| 254 |
+
def control_individual_tv(tv_id, action):
|
| 255 |
+
"""Control individual TV"""
|
| 256 |
+
title, message, status = controller.control_tv(tv_id, action)
|
| 257 |
+
return title, message, update_tvs_display()
|
| 258 |
+
|
| 259 |
+
def control_all_tvs_action(action):
|
| 260 |
+
"""Control all TVs"""
|
| 261 |
+
title, message, status = controller.control_all_tvs(action)
|
| 262 |
+
return title, message, update_tvs_display(), "" if action == "stop" else gr.update()
|
| 263 |
+
|
| 264 |
+
def change_volume_all(volume):
|
| 265 |
+
"""Change volume for all TVs"""
|
| 266 |
+
title, message, status = controller.change_volume(volume)
|
| 267 |
+
return title, message, update_tvs_display(), f"{volume}%"
|
| 268 |
+
|
| 269 |
+
def update_playback_progress():
|
| 270 |
+
"""Update playback progress"""
|
| 271 |
+
progress, current_time, duration = controller.update_progress()
|
| 272 |
+
return progress, current_time, duration
|
| 273 |
+
|
| 274 |
+
def add_video_to_playlist(url, title):
|
| 275 |
+
"""Add video to playlist"""
|
| 276 |
+
result_title, message, status = controller.add_to_playlist(url, title)
|
| 277 |
+
return result_title, message, update_playlist_display()
|
| 278 |
+
|
| 279 |
+
def play_playlist_item(index):
|
| 280 |
+
"""Play item from playlist"""
|
| 281 |
+
title, message, status = controller.play_from_playlist(index)
|
| 282 |
+
return title, message, update_tvs_display()
|
| 283 |
+
|
| 284 |
+
def load_sample_video(sample_type):
|
| 285 |
+
"""Load sample video"""
|
| 286 |
+
samples = {
|
| 287 |
+
"youtube": "https://www.youtube.com/watch?v=dQw4w9WgXcQ",
|
| 288 |
+
"vimeo": "https://vimeo.com/123456789",
|
| 289 |
+
"direct": "https://commondatastorage.googleapis.com/gtv-videos-bucket/sample/BigBuckBunny.mp4"
|
| 290 |
+
}
|
| 291 |
+
|
| 292 |
+
url = samples.get(sample_type, "")
|
| 293 |
+
return load_video_url(url)
|
| 294 |
+
|
| 295 |
+
# Create Gradio interface - CORREGIDO: theme se pasa en launch(), no en Blocks()
|
| 296 |
+
with gr.Blocks(title="Control Multimedia Chromecast") as demo:
|
| 297 |
+
gr.HTML("""
|
| 298 |
+
<div style="background: linear-gradient(135deg, #667eea 0%, #764ba2 100%); color: white; padding: 20px; border-radius: 12px; margin-bottom: 20px;">
|
| 299 |
+
<h1 style="margin: 0; display: flex; align-items: center; gap: 10px;">
|
| 300 |
+
📺 Control Multimedia Chromecast - Hostelería
|
| 301 |
+
</h1>
|
| 302 |
+
<p style="margin: 8px 0 0 0; opacity: 0.9;">Sistema de control para múltiples dispositivos Chromecast</p>
|
| 303 |
+
</div>
|
| 304 |
+
""")
|
| 305 |
+
|
| 306 |
+
with gr.Row():
|
| 307 |
+
with gr.Column(scale=2):
|
| 308 |
+
# Quick Actions
|
| 309 |
+
gr.HTML("<h2>⚡ Acciones Rápidas</h2>")
|
| 310 |
+
with gr.Row():
|
| 311 |
+
play_all_btn = gr.Button("▶️ Reproducir", variant="primary", size="sm")
|
| 312 |
+
pause_all_btn = gr.Button("⏸️ Pausar", variant="secondary", size="sm")
|
| 313 |
+
stop_all_btn = gr.Button("⏹️ Detener", variant="stop", size="sm")
|
| 314 |
+
mute_all_btn = gr.Button("🔇 Silenciar", variant="secondary", size="sm")
|
| 315 |
+
|
| 316 |
+
# TV Status Display
|
| 317 |
+
gr.HTML("<h2>📺 Estado de los Dispositivos</h2>")
|
| 318 |
+
tvs_display = gr.HTML(update_tvs_display())
|
| 319 |
+
|
| 320 |
+
# Video Input Section
|
| 321 |
+
gr.HTML("<h2>🎬 Control de Reproducción</h2>")
|
| 322 |
+
with gr.Row():
|
| 323 |
+
video_url = gr.Textbox(label="URL del Video", placeholder="Introduce URL (YouTube, Vimeo, directa)")
|
| 324 |
+
load_btn = gr.Button("📥 Cargar Video", variant="primary")
|
| 325 |
+
|
| 326 |
+
with gr.Row():
|
| 327 |
+
youtube_btn = gr.Button("📺 YouTube Sample", size="sm")
|
| 328 |
+
vimeo_btn = gr.Button("🎥 Vimeo Sample", size="sm")
|
| 329 |
+
direct_btn = gr.Button("🔗 URL Directa", size="sm")
|
| 330 |
+
|
| 331 |
+
# Progress Bar
|
| 332 |
+
gr.HTML("<h3>📊 Progreso de Reproducción</h3>")
|
| 333 |
+
progress = gr.Slider(0, 100, value=0, label="Progreso", interactive=True)
|
| 334 |
+
with gr.Row():
|
| 335 |
+
current_time = gr.Textbox("00:00", label="Tiempo Actual", interactive=False)
|
| 336 |
+
duration_time = gr.Textbox("03:45", label="Duración", interactive=False)
|
| 337 |
+
|
| 338 |
+
# Media Controls
|
| 339 |
+
gr.HTML("<h3>🎮 Controles de Multimedia</h3>")
|
| 340 |
+
with gr.Row():
|
| 341 |
+
rewind_btn = gr.Button("⏪ Rebobinar", size="sm")
|
| 342 |
+
play_btn = gr.Button("▶️ Reproducir", variant="primary", size="sm")
|
| 343 |
+
pause_btn = gr.Button("⏸️ Pausar", variant="secondary", size="sm")
|
| 344 |
+
stop_btn = gr.Button("⏹️ Detener", variant="stop", size="sm")
|
| 345 |
+
forward_btn = gr.Button("⏩ Adelantar", size="sm")
|
| 346 |
+
|
| 347 |
+
# Volume Control
|
| 348 |
+
gr.HTML("<h3>🔊 Control de Volumen</h3>")
|
| 349 |
+
with gr.Row():
|
| 350 |
+
volume_slider = gr.Slider(0, 100, value=50, label="Volumen Maestro")
|
| 351 |
+
volume_percentage = gr.Textbox("50%", label="Porcentaje", interactive=False)
|
| 352 |
+
|
| 353 |
+
with gr.Column(scale=1):
|
| 354 |
+
# Individual TV Controls
|
| 355 |
+
gr.HTML("<h2>🎛️ Controles Individuales</h2>")
|
| 356 |
+
with gr.Group():
|
| 357 |
+
gr.HTML("<h4>TV 1 - Sala Principal</h4>")
|
| 358 |
+
with gr.Row():
|
| 359 |
+
tv1_play = gr.Button("▶️", size="sm", variant="primary")
|
| 360 |
+
tv1_pause = gr.Button("⏸️", size="sm")
|
| 361 |
+
tv1_stop = gr.Button("⏹️", size="sm", variant="stop")
|
| 362 |
+
tv1_mute = gr.Button("🔇", size="sm")
|
| 363 |
+
|
| 364 |
+
gr.HTML("<h4>TV 2 - Barra</h4>")
|
| 365 |
+
with gr.Row():
|
| 366 |
+
tv2_play = gr.Button("▶️", size="sm", variant="primary")
|
| 367 |
+
tv2_pause = gr.Button("⏸️", size="sm")
|
| 368 |
+
tv2_stop = gr.Button("⏹️", size="sm", variant="stop")
|
| 369 |
+
tv2_mute = gr.Button("🔇", size="sm")
|
| 370 |
+
|
| 371 |
+
gr.HTML("<h4>TV 3 - Terraza</h4>")
|
| 372 |
+
with gr.Row():
|
| 373 |
+
tv3_play = gr.Button("▶️", size="sm", variant="primary")
|
| 374 |
+
tv3_pause = gr.Button("⏸️", size="sm")
|
| 375 |
+
tv3_stop = gr.Button("⏹️", size="sm", variant="stop")
|
| 376 |
+
tv3_mute = gr.Button("🔇", size="sm")
|
| 377 |
+
|
| 378 |
+
# Playlist Section
|
| 379 |
+
gr.HTML("<h2>📋 Playlist de Videos</h2>")
|
| 380 |
+
playlist_display = gr.HTML(update_playlist_display())
|
| 381 |
+
|
| 382 |
+
with gr.Group():
|
| 383 |
+
playlist_url = gr.Textbox(label="URL para Playlist", placeholder="Agrega video a playlist")
|
| 384 |
+
playlist_title = gr.Textbox(label="Título (opcional)")
|
| 385 |
+
add_playlist_btn = gr.Button("➕ Agregar a Playlist", variant="primary")
|
| 386 |
+
|
| 387 |
+
# Status Display
|
| 388 |
+
with gr.Row():
|
| 389 |
+
status_title = gr.Textbox("✅ Sistema Listo", label="Estado", interactive=False)
|
| 390 |
+
status_message = gr.Textbox("Todos los dispositivos conectados", label="Mensaje", interactive=False)
|
| 391 |
+
|
| 392 |
+
# Event Handlers
|
| 393 |
+
load_btn.click(load_video_url, inputs=[video_url], outputs=[status_title, status_message, tvs_display, video_url])
|
| 394 |
+
|
| 395 |
+
# Sample videos
|
| 396 |
+
youtube_btn.click(fn=lambda: load_sample_video("youtube"), outputs=[status_title, status_message, tvs_display, video_url])
|
| 397 |
+
vimeo_btn.click(fn=lambda: load_sample_video("vimeo"), outputs=[status_title, status_message, tvs_display, video_url])
|
| 398 |
+
direct_btn.click(fn=lambda: load_sample_video("direct"), outputs=[status_title, status_message, tvs_display, video_url])
|
| 399 |
+
|
| 400 |
+
# Quick actions
|
| 401 |
+
play_all_btn.click(fn=lambda: control_all_tvs_action("play"), outputs=[status_title, status_message, tvs_display, video_url])
|
| 402 |
+
pause_all_btn.click(fn=lambda: control_all_tvs_action("pause"), outputs=[status_title, status_message, tvs_display, video_url])
|
| 403 |
+
stop_all_btn.click(fn=lambda: control_all_tvs_action("stop"), outputs=[status_title, status_message, tvs_display, video_url])
|
| 404 |
+
mute_all_btn.click(fn=lambda: control_all_tvs_action("mute"), outputs=[status_title, status_message, tvs_display, video_url])
|
| 405 |
+
|
| 406 |
+
# Media controls
|
| 407 |
+
play_btn.click(fn=lambda: control_all_tvs_action("play"), outputs=[status_title, status_message, tvs_display, video_url])
|
| 408 |
+
pause_btn.click(fn=lambda: control_all_tvs_action("pause"), outputs=[status_title, status_message, tvs_display, video_url])
|
| 409 |
+
stop_btn.click(fn=lambda: control_all_tvs_action("stop"), outputs=[status_title, status_message, tvs_display, video_url])
|
| 410 |
+
|
| 411 |
+
# Volume control
|
| 412 |
+
volume_slider.change(change_volume_all, inputs=[volume_slider], outputs=[status_title, status_message, tvs_display, volume_percentage])
|
| 413 |
+
|
| 414 |
+
# Individual TV controls
|
| 415 |
+
tv1_play.click(fn=lambda: control_individual_tv(1, "play"), outputs=[status_title, status_message, tvs_display])
|
| 416 |
+
tv1_pause.click(fn=lambda: control_individual_tv(1, "pause"), outputs=[status_title, status_message, tvs_display])
|
| 417 |
+
tv1_stop.click(fn=lambda: control_individual_tv(1, "stop"), outputs=[status_title, status_message, tvs_display])
|
| 418 |
+
tv1_mute.click(fn=lambda: control_individual_tv(1, "mute"), outputs=[status_title, status_message, tvs_display])
|
| 419 |
+
|
| 420 |
+
tv2_play.click(fn=lambda: control_individual_tv(2, "play"), outputs=[status_title, status_message, tvs_display])
|
| 421 |
+
tv2_pause.click(fn=lambda: control_individual_tv(2, "pause"), outputs=[status_title, status_message, tvs_display])
|
| 422 |
+
tv2_stop.click(fn=lambda: control_individual_tv(2, "stop"), outputs=[status_title, status_message, tvs_display])
|
| 423 |
+
tv2_mute.click(fn=lambda: control_individual_tv(2, "mute"), outputs=[status_title, status_message, tvs_display])
|
| 424 |
+
|
| 425 |
+
tv3_play.click(fn=lambda: control_individual_tv(3, "play"), outputs=[status_title, status_message, tvs_display])
|
| 426 |
+
tv3_pause.click(fn=lambda: control_individual_tv(3, "pause"), outputs=[status_title, status_message, tvs_display])
|
| 427 |
+
tv3_stop.click(fn=lambda: control_individual_tv(3, "stop"), outputs=[status_title, status_message, tvs_display])
|
| 428 |
+
tv3_mute.click(fn=lambda: control_individual_tv(3, "mute"), outputs=[status_title, status_message, tvs_display])
|
| 429 |
+
|
| 430 |
+
# Playlist controls
|
| 431 |
+
add_playlist_btn.click(add_video_to_playlist, inputs=[playlist_url, playlist_title], outputs=[status_title, status_message, playlist_display])
|
| 432 |
+
|
| 433 |
+
# Timer for progress update
|
| 434 |
+
timer = gr.Timer(1.0)
|
| 435 |
+
timer.tick(update_playback_progress, outputs=[progress, current_time, duration_time])
|
| 436 |
+
|
| 437 |
+
# Footer
|
| 438 |
+
gr.HTML("""
|
| 439 |
+
<div style="text-align: center; margin-top: 30px; padding: 20px; border-top: 1px solid #e5e7eb;">
|
| 440 |
+
<a href="https://huggingface.co/spaces/akhaliq/anycoder" target="_blank" style="color: #3b82f6; text-decoration: none; font-weight: 600;">
|
| 441 |
+
Built with anycoder
|
| 442 |
+
</a>
|
| 443 |
+
</div>
|
| 444 |
+
""")
|
| 445 |
+
|
| 446 |
+
if __name__ == "__main__":
|
| 447 |
+
# CORREGIDO: El tema se pasa aquí, en el método launch()
|
| 448 |
+
demo.launch(theme=gr.themes.Soft())
|
requirements.txt
ADDED
|
@@ -0,0 +1,9 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
gradio
|
| 2 |
+
requests
|
| 3 |
+
Pillow
|
| 4 |
+
numpy
|
| 5 |
+
pandas
|
| 6 |
+
matplotlib
|
| 7 |
+
fastapi
|
| 8 |
+
uvicorn
|
| 9 |
+
pydantic
|