File size: 8,277 Bytes
258692d
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
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
    )