Update app.py
Browse files
app.py
CHANGED
|
@@ -385,6 +385,95 @@ def get_theme_styles(theme_choice: str) -> Tuple[str, str, str, str]:
|
|
| 385 |
theme = themes.get(theme_choice, themes["Light"])
|
| 386 |
return (theme["explanation"], theme["code"], theme["explanation"], theme["code"])
|
| 387 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 388 |
def main():
|
| 389 |
"""Main application entry point."""
|
| 390 |
with gr.Blocks(
|
|
|
|
| 385 |
theme = themes.get(theme_choice, themes["Light"])
|
| 386 |
return (theme["explanation"], theme["code"], theme["explanation"], theme["code"])
|
| 387 |
|
| 388 |
+
def trigger_correction_wrapper(model, code):
|
| 389 |
+
"""Wrapper for trigger correction with proper error handling."""
|
| 390 |
+
try:
|
| 391 |
+
if not model or not code.strip():
|
| 392 |
+
return "Please select a model and provide code.", "", "Please provide valid inputs."
|
| 393 |
+
|
| 394 |
+
# Create dummy progress function since Gradio progress doesn't work in lambda
|
| 395 |
+
def dummy_progress(value, desc=""):
|
| 396 |
+
pass
|
| 397 |
+
|
| 398 |
+
return correct_apex_trigger(model, code, progress=dummy_progress)
|
| 399 |
+
except Exception as e:
|
| 400 |
+
logger.error(f"Trigger correction error: {str(e)}")
|
| 401 |
+
error_msg = f"Error processing request: {str(e)}"
|
| 402 |
+
return error_msg, "", error_msg
|
| 403 |
+
|
| 404 |
+
def object_conversion_wrapper(model, code):
|
| 405 |
+
"""Wrapper for object conversion with proper error handling."""
|
| 406 |
+
try:
|
| 407 |
+
if not model or not code.strip():
|
| 408 |
+
return "Please select a model and provide code.", "", "Please provide valid inputs."
|
| 409 |
+
|
| 410 |
+
def dummy_progress(value, desc=""):
|
| 411 |
+
pass
|
| 412 |
+
|
| 413 |
+
return convert_cc_object(model, code, progress=dummy_progress)
|
| 414 |
+
except Exception as e:
|
| 415 |
+
logger.error(f"Object conversion error: {str(e)}")
|
| 416 |
+
error_msg = f"Error processing request: {str(e)}"
|
| 417 |
+
return error_msg, "", error_msg
|
| 418 |
+
|
| 419 |
+
def validate_and_chart_trigger(model, original, corrected):
|
| 420 |
+
"""Wrapper for trigger validation with error handling."""
|
| 421 |
+
try:
|
| 422 |
+
if not model or not original.strip() or not corrected.strip():
|
| 423 |
+
return "Please provide all required inputs for validation.", None
|
| 424 |
+
|
| 425 |
+
validation_text = validate_apex_trigger(model, original, corrected)
|
| 426 |
+
metrics = extract_validation_metrics(validation_text)
|
| 427 |
+
chart = create_enhanced_radar_chart(metrics) if metrics else None
|
| 428 |
+
return validation_text, chart
|
| 429 |
+
except Exception as e:
|
| 430 |
+
logger.error(f"Trigger validation error: {str(e)}")
|
| 431 |
+
return f"Validation error: {str(e)}", None
|
| 432 |
+
|
| 433 |
+
def validate_and_chart_object(model, original, converted):
|
| 434 |
+
"""Wrapper for object validation with error handling."""
|
| 435 |
+
try:
|
| 436 |
+
if not model or not original.strip() or not converted.strip():
|
| 437 |
+
return "Please provide all required inputs for validation.", None
|
| 438 |
+
|
| 439 |
+
validation_text = validate_cc_object_conversion(model, original, converted)
|
| 440 |
+
metrics = extract_validation_metrics(validation_text)
|
| 441 |
+
chart = create_enhanced_radar_chart(metrics) if metrics else None
|
| 442 |
+
return validation_text, chart
|
| 443 |
+
except Exception as e:
|
| 444 |
+
logger.error(f"Object validation error: {str(e)}")
|
| 445 |
+
return f"Validation error: {str(e)}", None
|
| 446 |
+
|
| 447 |
+
# In the Apex Trigger tab section:
|
| 448 |
+
trigger_button.click(
|
| 449 |
+
fn=trigger_correction_wrapper,
|
| 450 |
+
inputs=[primary_model_dropdown, trigger_input],
|
| 451 |
+
outputs=[trigger_full_response, trigger_code_output, trigger_explanation],
|
| 452 |
+
show_progress=True
|
| 453 |
+
)
|
| 454 |
+
|
| 455 |
+
validate_trigger_button.click(
|
| 456 |
+
fn=validate_and_chart_trigger,
|
| 457 |
+
inputs=[validation_model_dropdown, trigger_input, trigger_code_output],
|
| 458 |
+
outputs=[trigger_validation_output, trigger_chart],
|
| 459 |
+
show_progress=True
|
| 460 |
+
)
|
| 461 |
+
|
| 462 |
+
# In the CloudCraze Object tab section:
|
| 463 |
+
object_button.click(
|
| 464 |
+
fn=object_conversion_wrapper,
|
| 465 |
+
inputs=[primary_model_dropdown, object_input],
|
| 466 |
+
outputs=[object_full_response, object_code_output, object_explanation],
|
| 467 |
+
show_progress=True
|
| 468 |
+
)
|
| 469 |
+
|
| 470 |
+
validate_object_button.click(
|
| 471 |
+
fn=validate_and_chart_object,
|
| 472 |
+
inputs=[validation_model_dropdown, object_input, object_code_output],
|
| 473 |
+
outputs=[object_validation_output, object_chart],
|
| 474 |
+
show_progress=True
|
| 475 |
+
)
|
| 476 |
+
|
| 477 |
def main():
|
| 478 |
"""Main application entry point."""
|
| 479 |
with gr.Blocks(
|