Spaces:
Build error
Build error
Update app.py
Browse files
app.py
CHANGED
|
@@ -151,33 +151,55 @@ with gr.Blocks(title="Prepperoni - Premiere Pro to XML Converter", css=css) as a
|
|
| 151 |
logger.info(f"Raw sequence result: {result}")
|
| 152 |
|
| 153 |
try:
|
| 154 |
-
#
|
| 155 |
-
if isinstance(result, (
|
| 156 |
-
|
| 157 |
-
if isinstance(result[0], (list, tuple)):
|
| 158 |
-
# It's a list of sequences
|
| 159 |
-
sequences = result[0]
|
| 160 |
-
else:
|
| 161 |
-
# The result itself is the list of sequences
|
| 162 |
-
sequences = result
|
| 163 |
-
|
| 164 |
-
if len(result) >= 2 and isinstance(result[1], str):
|
| 165 |
-
error_msg = result[1]
|
| 166 |
-
elif isinstance(result, dict):
|
| 167 |
if 'choices' in result:
|
| 168 |
-
|
| 169 |
-
|
| 170 |
-
|
| 171 |
-
|
| 172 |
-
|
| 173 |
-
|
| 174 |
-
|
| 175 |
-
|
| 176 |
-
|
| 177 |
-
|
| 178 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 179 |
|
| 180 |
-
# Ensure sequences is a list
|
| 181 |
if not isinstance(sequences, (list, tuple)):
|
| 182 |
# Try to convert to a list if it's something else
|
| 183 |
if hasattr(sequences, 'items'): # It's a dictionary-like object
|
|
@@ -186,6 +208,13 @@ with gr.Blocks(title="Prepperoni - Premiere Pro to XML Converter", css=css) as a
|
|
| 186 |
# Try to make it a list with a single item
|
| 187 |
sequences = [sequences]
|
| 188 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 189 |
# Convert any non-string items to strings
|
| 190 |
sequences = [str(seq) for seq in sequences]
|
| 191 |
|
|
@@ -307,8 +336,18 @@ with gr.Blocks(title="Prepperoni - Premiere Pro to XML Converter", css=css) as a
|
|
| 307 |
# Check if xml_path is a string
|
| 308 |
if not isinstance(xml_path, str):
|
| 309 |
logger.warning(f"XML path is not a string: {type(xml_path)}")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 310 |
xml_path = str(xml_path)
|
| 311 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 312 |
# Download the XML file if it's a URL
|
| 313 |
if xml_path.startswith("http"):
|
| 314 |
logger.info(f"Downloading XML file from {xml_path}")
|
|
@@ -327,7 +366,12 @@ with gr.Blocks(title="Prepperoni - Premiere Pro to XML Converter", css=css) as a
|
|
| 327 |
logger.error(f"Failed to download XML: {response.status_code}")
|
| 328 |
return None, f"Error downloading XML: {response.status_code}", "Error"
|
| 329 |
else:
|
| 330 |
-
#
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 331 |
logger.info(f"XML file is at local path: {xml_path}")
|
| 332 |
return xml_path, message, "Success!"
|
| 333 |
else:
|
|
|
|
| 151 |
logger.info(f"Raw sequence result: {result}")
|
| 152 |
|
| 153 |
try:
|
| 154 |
+
# Special handling for Gradio component update objects
|
| 155 |
+
if isinstance(result, dict) and '__type__' in result and result.get('__type__') == 'update':
|
| 156 |
+
# Extract sequence choices from the Gradio update object
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 157 |
if 'choices' in result:
|
| 158 |
+
choices = result['choices']
|
| 159 |
+
|
| 160 |
+
# Handle nested lists or different formats of choices
|
| 161 |
+
if isinstance(choices, list) and len(choices) > 0:
|
| 162 |
+
if isinstance(choices[0], list):
|
| 163 |
+
# Format is likely [['name1', 'value1'], ['name2', 'value2']]
|
| 164 |
+
# or [['name1', 'name1'], ['name2', 'name2']]
|
| 165 |
+
sequences = [item[0] for item in choices] # Take the first item (name)
|
| 166 |
+
else:
|
| 167 |
+
# Format is likely ['name1', 'name2', 'name3']
|
| 168 |
+
sequences = choices
|
| 169 |
+
else:
|
| 170 |
+
# Standard response handling for non-update objects
|
| 171 |
+
if isinstance(result, (list, tuple)):
|
| 172 |
+
if len(result) > 0:
|
| 173 |
+
if isinstance(result[0], (list, tuple)):
|
| 174 |
+
# It's a list of sequences
|
| 175 |
+
sequences = result[0]
|
| 176 |
+
else:
|
| 177 |
+
# The result itself is the list of sequences
|
| 178 |
+
sequences = result
|
| 179 |
+
|
| 180 |
+
if len(result) >= 2 and isinstance(result[1], str):
|
| 181 |
+
error_msg = result[1]
|
| 182 |
+
elif isinstance(result, dict):
|
| 183 |
+
if 'choices' in result:
|
| 184 |
+
choices = result['choices']
|
| 185 |
+
if isinstance(choices, list) and len(choices) > 0:
|
| 186 |
+
if isinstance(choices[0], list):
|
| 187 |
+
# Format is likely [['name1', 'value1'], ['name2', 'value2']]
|
| 188 |
+
sequences = [item[0] for item in choices]
|
| 189 |
+
else:
|
| 190 |
+
sequences = choices
|
| 191 |
+
elif 'data' in result:
|
| 192 |
+
if isinstance(result['data'], (list, tuple)) and len(result['data']) >= 1:
|
| 193 |
+
sequences = result['data'][0]
|
| 194 |
+
else:
|
| 195 |
+
sequences = result['data']
|
| 196 |
+
elif 'sequences' in result:
|
| 197 |
+
sequences = result['sequences']
|
| 198 |
+
|
| 199 |
+
if 'error' in result:
|
| 200 |
+
error_msg = result['error']
|
| 201 |
|
| 202 |
+
# Ensure sequences is a list and contains only unique values
|
| 203 |
if not isinstance(sequences, (list, tuple)):
|
| 204 |
# Try to convert to a list if it's something else
|
| 205 |
if hasattr(sequences, 'items'): # It's a dictionary-like object
|
|
|
|
| 208 |
# Try to make it a list with a single item
|
| 209 |
sequences = [sequences]
|
| 210 |
|
| 211 |
+
# Remove duplicates while preserving order
|
| 212 |
+
unique_sequences = []
|
| 213 |
+
for seq in sequences:
|
| 214 |
+
if seq not in unique_sequences:
|
| 215 |
+
unique_sequences.append(seq)
|
| 216 |
+
sequences = unique_sequences
|
| 217 |
+
|
| 218 |
# Convert any non-string items to strings
|
| 219 |
sequences = [str(seq) for seq in sequences]
|
| 220 |
|
|
|
|
| 336 |
# Check if xml_path is a string
|
| 337 |
if not isinstance(xml_path, str):
|
| 338 |
logger.warning(f"XML path is not a string: {type(xml_path)}")
|
| 339 |
+
# If it's a dict or complex object, it's likely not a valid path
|
| 340 |
+
if isinstance(xml_path, (dict, list, tuple)):
|
| 341 |
+
logger.error(f"Invalid XML path, not a string: {xml_path}")
|
| 342 |
+
return None, "Error: Invalid response format from backend server", "Error"
|
| 343 |
+
# Try to convert to string if it's another type
|
| 344 |
xml_path = str(xml_path)
|
| 345 |
|
| 346 |
+
# Check if the path is actually a valid file path
|
| 347 |
+
if xml_path.startswith("{") or xml_path.startswith("["):
|
| 348 |
+
logger.error(f"XML path appears to be JSON or a data structure, not a path: {xml_path}")
|
| 349 |
+
return None, "Error: Invalid response format from backend server", "Error"
|
| 350 |
+
|
| 351 |
# Download the XML file if it's a URL
|
| 352 |
if xml_path.startswith("http"):
|
| 353 |
logger.info(f"Downloading XML file from {xml_path}")
|
|
|
|
| 366 |
logger.error(f"Failed to download XML: {response.status_code}")
|
| 367 |
return None, f"Error downloading XML: {response.status_code}", "Error"
|
| 368 |
else:
|
| 369 |
+
# Check if it's a local path that actually exists
|
| 370 |
+
if not os.path.exists(xml_path):
|
| 371 |
+
logger.error(f"XML path does not exist: {xml_path}")
|
| 372 |
+
return None, f"Error: XML file not found at path {xml_path}", "Error"
|
| 373 |
+
|
| 374 |
+
# It's a valid local path
|
| 375 |
logger.info(f"XML file is at local path: {xml_path}")
|
| 376 |
return xml_path, message, "Success!"
|
| 377 |
else:
|