Spaces:
Runtime error
Runtime error
| import gradio as gr | |
| import os | |
| import time | |
| from typing import Dict, List, Optional | |
| import requests | |
| from pathlib import Path | |
| import tempfile | |
| # Simulated database of available fixtures | |
| FIXTURE_DATABASE = { | |
| "clay paky z4 19": { | |
| "manufacturer": "Clay Paky", | |
| "model": "Z4 19", | |
| "modes": ["Mode 1", "Mode 2", "Mode 3", "Mode 4", "Mode 5", "Mode 6", "Mode 7", "Mode 8", "Extended"], | |
| "available": True, | |
| "formats": ["ma2", "ma3"], | |
| "description": "Professional moving head fixture with advanced features" | |
| }, | |
| "martin mac quantum wash": { | |
| "manufacturer": "Martin", | |
| "model": "MAC Quantum Wash", | |
| "modes": ["Mode 1", "Mode 2", "Mode 3", "Mode 4"], | |
| "available": True, | |
| "formats": ["ma2", "ma3"] | |
| }, | |
| "robe robln 600": { | |
| "manufacturer": "Robe", | |
| "model": "Robin 600", | |
| "modes": ["Mode 1", "Mode 2", "Mode 3", "Mode 4", "Mode 5"], | |
| "available": True, | |
| "formats": ["ma2", "ma3"] | |
| } | |
| } | |
| # Simulated web search function | |
| def search_fixture_online(fixture_name: str) -> Dict: | |
| """Simulate searching for fixture documentation online""" | |
| time.sleep(2) # Simulate search time | |
| # Check if fixture exists in our simulated database | |
| if fixture_name.lower() in [name.lower() for name in FIXTURE_DATABASE.keys()]: | |
| return {"found": True, "source": "Official manufacturer website"} | |
| return {"found": False, "source": "No official documentation found"} | |
| # Fixture creation function | |
| def create_fixture_library(fixture_name: str, pdf_files: List[str] = None) -> Dict: | |
| """Create fixture library from collected information""" | |
| # Simulate library creation process | |
| time.sleep(3) | |
| library_data = { | |
| "fixture_name": fixture_name, | |
| "status": "created", | |
| "ma2_download": f"/downloads/{fixture_name.replace(' ', '_')}_ma2.gma", | |
| "ma3_download": f"/downloads/{fixture_name.replace(' ', '_')}_ma3.gma"} | |
| return library_data | |
| def process_fixture_request(fixture_name: str, pdf_files: List[str] = None) -> Dict: | |
| """ | |
| Main function to process fixture library requests | |
| """ | |
| # Step 1: Check if fixture exists in our system | |
| if fixture_name.lower() in [name.lower() for name in FIXTURE_DATABASE.keys()]: | |
| fixture_info = FIXTURE_DATABASE[fixture_name.lower()]] | |
| return { | |
| "status": "available", | |
| "fixture_info": fixture_info, | |
| "download_links": None | |
| } | |
| # Step 2: If not available, search online | |
| search_result = search_fixture_online(fixture_name) | |
| if not search_result["found"]: | |
| return { | |
| "status": "not_found", | |
| "message": "Fixture not found in our system. Starting online search..."} | |
| # Step 3: Create library | |
| library_data = create_fixture_library(fixture_name, pdf_files) | |
| return { | |
| "status": "created", | |
| "fixture_name": fixture_name, | |
| "message": "Library created successfully!", | |
| "downloads": { | |
| "ma2_format": f"https://example.com/downloads/{fixture_name.replace(' ', '_')}_ma2.gma", | |
| "ma3_format": f"https://example.com/downloads/{fixture_name.replace(' ', '_')}_ma3.gma"} | |
| } | |
| def check_fixture_availability(fixture_name: str) -> Dict: | |
| """Check if fixture library is available in our system""" | |
| time.sleep(1) # Simulate checking process | |
| # Check if fixture exists in our database | |
| for name, data in FIXTURE_DATABASE.items(): | |
| if fixture_name.lower() in name.lower(): | |
| return { | |
| "available": True, | |
| "data": data | |
| } | |
| return { | |
| "available": False, | |
| "message": "Fixture not found in local database"} | |
| } | |
| with gr.Blocks( | |
| title="GrandMA Fixture Library Creator", | |
| footer_links=[{"label": "Built with anycoder", "url": "https://huggingface.co/spaces/akhaliq/anycoder"] | |
| ) as demo: | |
| gr.Markdown("# 🎭 GrandMA Fixture Library Creator") | |
| gr.Markdown("Crea librerías de fixtures para GrandMA2 y GrandMA3") | |
| with gr.Row(): | |
| with gr.Column(scale=1): | |
| gr.Markdown("## Paso 1: Buscar Librería") | |
| fixture_name = gr.Textbox( | |
| label="Nombre del Aparato", | |
| placeholder="Ej: Clay Paky Z4 19, Martin MAC Quantum Wash, Robe Robin 600") | |
| check_btn = gr.Button("Comprobar Disponibilidad", variant="primary") | |
| availability_status = gr.Textbox( | |
| label="Estado de la Librería", | |
| interactive=False | |
| ) | |
| with gr.Row(): | |
| with gr.Column(scale=1): | |
| gr.Markdown("## Paso 2: Subir Documentación (Opcional)") | |
| pdf_upload = gr.File( | |
| file_count="multiple", | |
| file_types=[".pdf"], | |
| label="Documentos Técnicos (PDF)" | |
| ) | |
| with gr.Row(): | |
| with gr.Column(scale=1): | |
| gr.Markdown("## Paso 3: Crear Librería") | |
| create_btn = gr.Button("Crear Librería", variant="primary") | |
| download_section = gr.Column(visible=False) | |
| with download_section: | |
| gr.Markdown("### 📥 Descargas Disponibles") | |
| ma2_download = gr.DownloadButton("Descargar formato MA2")) | |
| ma3_download = gr.DownloadButton("Descargar formato MA3")) | |
| # Event handlers | |
| def on_check_click(fixture_name: str): | |
| if not fixture_name: | |
| return "Por favor, introduce el nombre del aparato", None, None | |
| result = check_fixture_availability(fixture_name) | |
| if result["available"]: | |
| return { | |
| availability_status: f"✅ Librería disponible: {result['data']['manufacturer']} {result['data']['model']}", | |
| download_section: gr.Column(visible=True) | |
| } | |
| else: | |
| return { | |
| availability_status: f"❌ Librería no encontrada. Se iniciará búsqueda online..."} | |
| def on_create_click(fixture_name: str, pdf_files: List[str]): | |
| if not fixture_name: | |
| return { | |
| availability_status: "Por favor, introduce el nombre del aparato", | |
| download_section: gr.Column(visible=False) | |
| } | |
| def on_creation_complete(fixture_data: Dict): | |
| return { | |
| availability_status: f"✅ Librería creada: {fixture_data['fixture_name']}", | |
| download_section: gr.Column(visible=True) | |
| } | |
| check_btn.click( | |
| fn=on_check_click, | |
| inputs=[fixture_name], | |
| outputs=[availability_status, download_section], | |
| api_visibility="public" | |
| ) | |
| create_btn.click( | |
| fn=on_create_click, | |
| inputs=[fixture_name, pdf_upload], | |
| outputs=[availability_status, download_section], | |
| api_visibility="public" | |
| ) | |
| # Simulate the creation process with progress | |
| def create_library_with_progress(fixture_name: str, pdf_files: List[str]): | |
| progress = gr.Progress() | |
| for i in range(5): | |
| time.sleep(0.5) | |
| progress((i+1)/5, f"Procesando... paso {i+1}/5") | |
| library_data = create_fixture_library(fixture_name, pdf_files) | |
| return { | |
| ma2_download: library_data["ma2_download"]}, | |
| ma3_download: library_data["ma3_download"]}, | |
| download_section: gr.Column(visible=True) | |
| } | |
| gr.Markdown("---") | |
| gr.Markdown("### Información del Sistema") | |
| gr.Markdown("Este sistema permite:"") | |
| gr.Markdown("- Buscar librerías de fixtures existentes") | |
| gr.Markdown("- Crear nuevas librerías a partir de documentación técnica") | |
| gr.Markdown("- Descargar en formatos MA2 y MA3") | |
| # Footer with anycoder credit | |
| gr.HTML( | |
| """ | |
| <div style='text-align: center; margin-top: 20px; color: #666;'> | |
| Built with <a href='https://huggingface.co/spaces/akhaliq/anycoder' target='_blank'>anycoder</a> | |
| </div> | |
| """ | |
| ) | |
| if __name__ == "__main__": | |
| demo.launch( | |
| server_name="0.0.0.0", | |
| server_port=7860, | |
| share=True | |
| ) |