make both functions respect the "visualizations" toggle. (#1)
Browse files- make both functions respect the "visualizations" toggle. (fceae67877a85f806911c24cd5d7482b61f6c0b3)
Co-authored-by: Karim "Sins" Yehia <mewhenmonkeyavatar@users.noreply.huggingface.co>
app.py
CHANGED
|
@@ -492,41 +492,40 @@ def process_comprehensive_analysis(model_input: str, onnx_file, llms_to_query: l
|
|
| 492 |
full_response += f"{interpretation}\n\n---\n\n"
|
| 493 |
|
| 494 |
# Visualization Generation
|
| 495 |
-
viz_llm = llms_to_query[0]
|
| 496 |
-
print(f"Using {viz_llm} for visualization generation...")
|
| 497 |
-
|
| 498 |
viz_outputs = {}
|
| 499 |
viz_types = ["shap", "lime", "attention", "architecture", "parameter"]
|
| 500 |
-
|
| 501 |
-
|
| 502 |
-
|
| 503 |
-
|
| 504 |
-
|
| 505 |
-
|
| 506 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 507 |
|
| 508 |
-
|
| 509 |
-
|
| 510 |
-
|
| 511 |
-
|
| 512 |
-
|
| 513 |
-
viz_outputs[viz_type] = None
|
| 514 |
-
continue
|
| 515 |
|
| 516 |
-
|
| 517 |
-
|
| 518 |
-
|
| 519 |
-
|
| 520 |
-
|
| 521 |
-
|
|
|
|
| 522 |
|
| 523 |
-
|
| 524 |
-
|
| 525 |
-
viz_outputs[viz_type] = image_path
|
| 526 |
-
|
| 527 |
-
except Exception as e:
|
| 528 |
-
print(f"Unexpected error in main loop for {viz_type}: {e}")
|
| 529 |
-
viz_outputs[viz_type] = None
|
| 530 |
|
| 531 |
return (
|
| 532 |
full_response,
|
|
@@ -579,41 +578,40 @@ def process_text_comprehensive_analysis(model_input: str, llms_to_query, analysi
|
|
| 579 |
full_response += f"{interpretation}\n\n---\n\n"
|
| 580 |
|
| 581 |
# Visualization Generation
|
| 582 |
-
viz_llm = llms_to_query[0]
|
| 583 |
-
print(f"Using {viz_llm} for visualization generation...")
|
| 584 |
-
|
| 585 |
viz_outputs = {}
|
| 586 |
viz_types = ["shap", "lime", "attention", "architecture", "parameter"]
|
|
|
|
|
|
|
| 587 |
|
| 588 |
-
|
| 589 |
-
|
| 590 |
-
|
| 591 |
-
|
| 592 |
-
|
| 593 |
-
|
|
|
|
|
|
|
|
|
|
| 594 |
|
| 595 |
-
|
| 596 |
-
|
| 597 |
|
| 598 |
-
|
| 599 |
-
|
| 600 |
-
|
| 601 |
-
continue
|
| 602 |
|
| 603 |
-
|
| 604 |
|
| 605 |
-
|
| 606 |
-
|
| 607 |
-
|
| 608 |
-
continue
|
| 609 |
|
| 610 |
-
|
| 611 |
-
|
| 612 |
-
|
| 613 |
|
| 614 |
-
|
| 615 |
-
|
| 616 |
-
viz_outputs[viz_type] = None
|
| 617 |
|
| 618 |
return (
|
| 619 |
full_response,
|
|
|
|
| 492 |
full_response += f"{interpretation}\n\n---\n\n"
|
| 493 |
|
| 494 |
# Visualization Generation
|
|
|
|
|
|
|
|
|
|
| 495 |
viz_outputs = {}
|
| 496 |
viz_types = ["shap", "lime", "attention", "architecture", "parameter"]
|
| 497 |
+
for i in viz_types:
|
| 498 |
+
viz_outputs[i] = None
|
| 499 |
+
|
| 500 |
+
if "visualizations" in analysis_types:
|
| 501 |
+
viz_llm = llms_to_query[0]
|
| 502 |
+
print(f"Using {viz_llm} for visualization generation...")
|
| 503 |
+
|
| 504 |
+
for viz_type in viz_types:
|
| 505 |
+
try:
|
| 506 |
+
prompt = get_visualization_prompt(viz_type)
|
| 507 |
+
if not prompt:
|
| 508 |
+
continue
|
| 509 |
+
|
| 510 |
+
print(f"Generating {viz_type} visualization...")
|
| 511 |
+
generated_code_response = get_llm_response(prompt, model_description, viz_llm)
|
| 512 |
|
| 513 |
+
if "Error" in generated_code_response:
|
| 514 |
+
print(f"LLM Error for {viz_type}: {generated_code_response}")
|
| 515 |
+
continue
|
| 516 |
+
|
| 517 |
+
cleaned_code = extract_python_code(generated_code_response)
|
|
|
|
|
|
|
| 518 |
|
| 519 |
+
if not cleaned_code:
|
| 520 |
+
print(f"Could not extract valid code for {viz_type}.")
|
| 521 |
+
continue
|
| 522 |
+
|
| 523 |
+
# Execute code, save plot, and get the file path
|
| 524 |
+
image_path = safely_execute_visualization_code(cleaned_code, viz_type, run_dir)
|
| 525 |
+
viz_outputs[viz_type] = image_path
|
| 526 |
|
| 527 |
+
except Exception as e:
|
| 528 |
+
print(f"Unexpected error in main loop for {viz_type}: {e}")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 529 |
|
| 530 |
return (
|
| 531 |
full_response,
|
|
|
|
| 578 |
full_response += f"{interpretation}\n\n---\n\n"
|
| 579 |
|
| 580 |
# Visualization Generation
|
|
|
|
|
|
|
|
|
|
| 581 |
viz_outputs = {}
|
| 582 |
viz_types = ["shap", "lime", "attention", "architecture", "parameter"]
|
| 583 |
+
for i in viz_types:
|
| 584 |
+
viz_outputs[i] = None
|
| 585 |
|
| 586 |
+
if "visualizations" in analysis_types:
|
| 587 |
+
viz_llm = llms_to_query[0]
|
| 588 |
+
print(f"Using {viz_llm} for visualization generation...")
|
| 589 |
+
|
| 590 |
+
for viz_type in viz_types:
|
| 591 |
+
try:
|
| 592 |
+
prompt = get_visualization_prompt(viz_type)
|
| 593 |
+
if not prompt:
|
| 594 |
+
continue
|
| 595 |
|
| 596 |
+
print(f"Generating {viz_type} visualization...")
|
| 597 |
+
generated_code_response = get_llm_response(prompt, model_description, viz_llm)
|
| 598 |
|
| 599 |
+
if "Error" in generated_code_response:
|
| 600 |
+
print(f"LLM Error for {viz_type}: {generated_code_response}")
|
| 601 |
+
continue
|
|
|
|
| 602 |
|
| 603 |
+
cleaned_code = extract_python_code(generated_code_response)
|
| 604 |
|
| 605 |
+
if not cleaned_code:
|
| 606 |
+
print(f"Could not extract valid code for {viz_type}.")
|
| 607 |
+
continue
|
|
|
|
| 608 |
|
| 609 |
+
# Execute code, save plot, and get the file path
|
| 610 |
+
image_path = safely_execute_visualization_code(cleaned_code, viz_type, run_dir)
|
| 611 |
+
viz_outputs[viz_type] = image_path
|
| 612 |
|
| 613 |
+
except Exception as e:
|
| 614 |
+
print(f"Unexpected error in main loop for {viz_type}: {e}")
|
|
|
|
| 615 |
|
| 616 |
return (
|
| 617 |
full_response,
|