Spaces:
Build error
Build error
Mustafa Başar commited on
Upload app.py with huggingface_hub
Browse files
app.py
CHANGED
|
@@ -398,213 +398,146 @@ def get_new_scenario(use_ai_generated=None):
|
|
| 398 |
use_ai_generated = random.random() > 0.5
|
| 399 |
|
| 400 |
if use_ai_generated:
|
| 401 |
-
|
| 402 |
else:
|
| 403 |
-
|
| 404 |
-
|
| 405 |
-
# Check if this is a relational scenario (has multiple tables)
|
| 406 |
-
if "tables" in scenario and len(scenario["tables"]) > 1:
|
| 407 |
-
# For relational scenarios, show the multiple tables
|
| 408 |
-
tables = scenario["tables"]
|
| 409 |
-
sample_data = scenario["sample_data"]
|
| 410 |
-
answer = scenario["answer"] if "answer" in scenario else "No answer provided."
|
| 411 |
-
|
| 412 |
-
# Prepare visibility states for tables
|
| 413 |
-
table1_visible = True
|
| 414 |
-
table2_visible = len(tables) > 1
|
| 415 |
-
table3_visible = len(tables) > 2
|
| 416 |
-
|
| 417 |
-
# Prepare labels for tables
|
| 418 |
-
table1_label = f"### {tables[0].replace('_', ' ').title()}"
|
| 419 |
-
table2_label = f"### {tables[1].replace('_', ' ').title()}" if len(tables) > 1 else "Table 2"
|
| 420 |
-
table3_label = f"### {tables[2].replace('_', ' ').title()}" if len(tables) > 2 else "Table 3"
|
| 421 |
-
|
| 422 |
-
# Prepare HTML content for tables
|
| 423 |
-
table1_html = sample_data.get(tables[0], "No data available")
|
| 424 |
-
table2_html = sample_data.get(tables[1], "No data available") if len(tables) > 1 else ""
|
| 425 |
-
table3_html = sample_data.get(tables[2], "No data available") if len(tables) > 2 else ""
|
| 426 |
-
|
| 427 |
-
return [
|
| 428 |
-
scenario["title"],
|
| 429 |
-
scenario["description"],
|
| 430 |
-
scenario["level"],
|
| 431 |
-
scenario["category"],
|
| 432 |
-
table1_visible,
|
| 433 |
-
table2_visible,
|
| 434 |
-
table3_visible,
|
| 435 |
-
table1_label,
|
| 436 |
-
table2_label,
|
| 437 |
-
table3_label,
|
| 438 |
-
table1_html,
|
| 439 |
-
table2_html,
|
| 440 |
-
table3_html,
|
| 441 |
-
answer
|
| 442 |
-
]
|
| 443 |
-
else:
|
| 444 |
-
# For regular scenarios with single table
|
| 445 |
-
answer = scenario["answer"] if "answer" in scenario else "No answer provided."
|
| 446 |
-
sample_data = scenario["sample_data"]
|
| 447 |
-
|
| 448 |
-
return [
|
| 449 |
-
scenario["title"],
|
| 450 |
-
scenario["description"],
|
| 451 |
-
scenario["level"],
|
| 452 |
-
scenario["category"],
|
| 453 |
-
True, # Show first table
|
| 454 |
-
False, # Hide second table
|
| 455 |
-
False, # Hide third table
|
| 456 |
-
"### Sample Data", # Label for first table
|
| 457 |
-
"", # Empty label for second table
|
| 458 |
-
"", # Empty label for third table
|
| 459 |
-
sample_data, # HTML content for first table
|
| 460 |
-
"", # Empty content for second table
|
| 461 |
-
"", # Empty content for third table
|
| 462 |
-
answer
|
| 463 |
-
]
|
| 464 |
|
| 465 |
# Use the same definition for get_ai_scenario but with the updated return types
|
| 466 |
def get_ai_scenario():
|
| 467 |
-
return
|
| 468 |
|
| 469 |
# Use the same definition for get_relational_scenario
|
| 470 |
def get_relational_scenario():
|
| 471 |
-
|
| 472 |
-
|
| 473 |
-
# Prepare data for display
|
| 474 |
-
tables = scenario["tables"]
|
| 475 |
-
sample_data = scenario["sample_data"]
|
| 476 |
-
answer = scenario["answer"] if "answer" in scenario else "No answer provided."
|
| 477 |
-
|
| 478 |
-
# Prepare visibility states for tables
|
| 479 |
-
table1_visible = True
|
| 480 |
-
table2_visible = len(tables) > 1
|
| 481 |
-
table3_visible = len(tables) > 2
|
| 482 |
-
|
| 483 |
-
# Prepare labels for tables
|
| 484 |
-
table1_label = f"### {tables[0].replace('_', ' ').title()}"
|
| 485 |
-
table2_label = f"### {tables[1].replace('_', ' ').title()}" if len(tables) > 1 else "Table 2"
|
| 486 |
-
table3_label = f"### {tables[2].replace('_', ' ').title()}" if len(tables) > 2 else "Table 3"
|
| 487 |
-
|
| 488 |
-
# Prepare HTML content for tables
|
| 489 |
-
table1_html = sample_data.get(tables[0], "No data available")
|
| 490 |
-
table2_html = sample_data.get(tables[1], "No data available") if len(tables) > 1 else ""
|
| 491 |
-
table3_html = sample_data.get(tables[2], "No data available") if len(tables) > 2 else ""
|
| 492 |
-
|
| 493 |
-
return [
|
| 494 |
-
scenario["title"],
|
| 495 |
-
scenario["description"],
|
| 496 |
-
scenario["level"],
|
| 497 |
-
scenario["category"],
|
| 498 |
-
table1_visible,
|
| 499 |
-
table2_visible,
|
| 500 |
-
table3_visible,
|
| 501 |
-
table1_label,
|
| 502 |
-
table2_label,
|
| 503 |
-
table3_label,
|
| 504 |
-
table1_html,
|
| 505 |
-
table2_html,
|
| 506 |
-
table3_html,
|
| 507 |
-
answer
|
| 508 |
-
]
|
| 509 |
|
| 510 |
# Evaluate user input and provide feedback
|
| 511 |
def submit_prompt(prompt, title, description, level, category, answer_text):
|
| 512 |
-
|
| 513 |
-
|
| 514 |
-
|
| 515 |
-
|
| 516 |
-
|
| 517 |
-
scenario
|
| 518 |
-
|
| 519 |
-
|
| 520 |
-
|
| 521 |
-
|
| 522 |
-
|
| 523 |
-
|
| 524 |
-
|
| 525 |
-
|
| 526 |
-
|
| 527 |
-
|
| 528 |
-
|
| 529 |
-
|
| 530 |
-
|
| 531 |
-
|
| 532 |
-
|
| 533 |
-
|
| 534 |
-
|
| 535 |
-
|
| 536 |
-
|
| 537 |
-
|
| 538 |
-
|
| 539 |
-
|
| 540 |
-
|
| 541 |
-
|
| 542 |
-
|
| 543 |
-
|
| 544 |
-
|
| 545 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 546 |
|
| 547 |
# Helper function to update tables based on scenario type
|
| 548 |
def update_tables(tables, sample_data, answer):
|
| 549 |
-
table_labels = ["sample_table1_label", "sample_table2_label", "sample_table3_label"]
|
| 550 |
-
table_elements = [sample_table1, sample_table2, sample_table3]
|
| 551 |
-
table_rows = [table_row, table_row2, table_row3]
|
| 552 |
-
|
| 553 |
-
# Hide all tables first
|
| 554 |
-
for row in table_rows:
|
| 555 |
-
row.visible = False
|
| 556 |
-
|
| 557 |
-
# Then show only the necessary tables
|
| 558 |
-
for i, table_name in enumerate(tables[:3]): # Limit to 3 tables
|
| 559 |
-
if i < len(tables):
|
| 560 |
-
table_rows[i].visible = True
|
| 561 |
-
table_labels[i].value = f"### {table_name.replace('_', ' ').title()}"
|
| 562 |
-
table_elements[i].value = sample_data.get(table_name, "No data available")
|
| 563 |
-
|
| 564 |
-
return [
|
| 565 |
-
table_rows[0].visible, table_rows[1].visible, table_rows[2].visible,
|
| 566 |
-
table_labels[0].value, table_labels[1].value, table_labels[2].value,
|
| 567 |
-
table_elements[0].value, table_elements[1].value, table_elements[2].value,
|
| 568 |
-
answer
|
| 569 |
-
]
|
| 570 |
-
|
| 571 |
-
# Define direct loading functions for buttons
|
| 572 |
-
def load_relational_scenario():
|
| 573 |
try:
|
| 574 |
-
|
| 575 |
-
|
| 576 |
-
|
| 577 |
-
|
| 578 |
-
|
| 579 |
-
|
| 580 |
-
|
| 581 |
-
|
| 582 |
-
|
| 583 |
-
|
| 584 |
-
|
| 585 |
-
|
| 586 |
-
|
| 587 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 588 |
except Exception as e:
|
| 589 |
-
|
| 590 |
-
|
| 591 |
-
return
|
| 592 |
-
|
| 593 |
-
"
|
| 594 |
-
"
|
| 595 |
-
"
|
| 596 |
-
|
| 597 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 598 |
"<table><tr><th>CustomerID</th><th>Age</th></tr><tr><td>C0001</td><td>35</td></tr></table>",
|
| 599 |
-
"
|
| 600 |
-
""
|
| 601 |
-
|
| 602 |
-
)
|
| 603 |
|
| 604 |
def load_regular_scenario():
|
| 605 |
try:
|
| 606 |
-
#
|
| 607 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 608 |
return (
|
| 609 |
scenario["title"],
|
| 610 |
scenario["description"],
|
|
@@ -612,7 +545,7 @@ def load_regular_scenario():
|
|
| 612 |
scenario["category"],
|
| 613 |
True, False, False, # Only first table visible
|
| 614 |
"### Sample Data", "", "", # Only first table has header
|
| 615 |
-
scenario["sample_data"],
|
| 616 |
"", "", # Empty second and third tables
|
| 617 |
scenario.get("answer", "No specific answer for this scenario.")
|
| 618 |
)
|
|
@@ -631,26 +564,96 @@ def load_regular_scenario():
|
|
| 631 |
"Example answer text here."
|
| 632 |
)
|
| 633 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 634 |
def load_ai_scenario():
|
| 635 |
try:
|
| 636 |
-
#
|
| 637 |
-
|
| 638 |
-
|
| 639 |
-
|
| 640 |
-
problem = random.choice(template["problems"])
|
| 641 |
|
| 642 |
-
|
| 643 |
-
|
| 644 |
-
|
|
|
|
|
|
|
| 645 |
|
| 646 |
-
#
|
| 647 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 648 |
|
| 649 |
return (
|
| 650 |
title,
|
| 651 |
description,
|
| 652 |
"Intermediate",
|
| 653 |
-
|
| 654 |
True, False, False, # Sadece ilk tablo görünür
|
| 655 |
"### Sample Data", "", "",
|
| 656 |
sample_data, "", "",
|
|
@@ -671,28 +674,6 @@ def load_ai_scenario():
|
|
| 671 |
"Example answer text here."
|
| 672 |
)
|
| 673 |
|
| 674 |
-
def load_sample_data():
|
| 675 |
-
try:
|
| 676 |
-
# Birinci tabloyu yükle
|
| 677 |
-
sample_html1 = sample_customer_data.head(5).to_html()
|
| 678 |
-
# İkinci tabloyu yükle
|
| 679 |
-
sample_html2 = sample_sales_data.head(5).to_html()
|
| 680 |
-
|
| 681 |
-
return [
|
| 682 |
-
"### Müşteri Verileri",
|
| 683 |
-
sample_html1,
|
| 684 |
-
"### Satış Verileri",
|
| 685 |
-
sample_html2
|
| 686 |
-
]
|
| 687 |
-
except Exception as e:
|
| 688 |
-
# Hata durumunda basit bir örnek göster
|
| 689 |
-
return [
|
| 690 |
-
"### Örnek Veriler",
|
| 691 |
-
"<table><tr><th>CustomerID</th><th>Age</th></tr><tr><td>C0001</td><td>35</td></tr></table>",
|
| 692 |
-
"### Satış Verileri",
|
| 693 |
-
"<table><tr><th>OrderID</th><th>Amount</th></tr><tr><td>ORD-001</td><td>120.5</td></tr></table>"
|
| 694 |
-
]
|
| 695 |
-
|
| 696 |
# Build Gradio interface
|
| 697 |
with gr.Blocks(theme=gr.themes.Soft(), title="PromptMaster for Data Analytics") as app:
|
| 698 |
gr.Markdown("# PromptMaster for Data Analytics")
|
|
@@ -754,7 +735,7 @@ with gr.Blocks(theme=gr.themes.Soft(), title="PromptMaster for Data Analytics")
|
|
| 754 |
|
| 755 |
# Logic
|
| 756 |
new_scenario_btn.click(
|
| 757 |
-
|
| 758 |
outputs=[
|
| 759 |
title_output, description_output, level_output, category_output,
|
| 760 |
table_row, table_row2, table_row3,
|
|
@@ -765,7 +746,7 @@ with gr.Blocks(theme=gr.themes.Soft(), title="PromptMaster for Data Analytics")
|
|
| 765 |
)
|
| 766 |
|
| 767 |
relational_scenario_btn.click(
|
| 768 |
-
|
| 769 |
outputs=[
|
| 770 |
title_output, description_output, level_output, category_output,
|
| 771 |
table_row, table_row2, table_row3,
|
|
@@ -776,7 +757,7 @@ with gr.Blocks(theme=gr.themes.Soft(), title="PromptMaster for Data Analytics")
|
|
| 776 |
)
|
| 777 |
|
| 778 |
ai_scenario_btn.click(
|
| 779 |
-
|
| 780 |
outputs=[
|
| 781 |
title_output, description_output, level_output, category_output,
|
| 782 |
table_row, table_row2, table_row3,
|
|
|
|
| 398 |
use_ai_generated = random.random() > 0.5
|
| 399 |
|
| 400 |
if use_ai_generated:
|
| 401 |
+
return load_ai_scenario()
|
| 402 |
else:
|
| 403 |
+
return load_regular_scenario()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 404 |
|
| 405 |
# Use the same definition for get_ai_scenario but with the updated return types
|
| 406 |
def get_ai_scenario():
|
| 407 |
+
return load_ai_scenario()
|
| 408 |
|
| 409 |
# Use the same definition for get_relational_scenario
|
| 410 |
def get_relational_scenario():
|
| 411 |
+
return load_relational_scenario()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 412 |
|
| 413 |
# Evaluate user input and provide feedback
|
| 414 |
def submit_prompt(prompt, title, description, level, category, answer_text):
|
| 415 |
+
try:
|
| 416 |
+
# First try to find in predefined scenarios
|
| 417 |
+
scenario = next((s for s in all_scenarios if s["title"] == title), None) if isinstance(all_scenarios, list) else None
|
| 418 |
+
|
| 419 |
+
# If not found, create a temporary scenario object from inputs
|
| 420 |
+
if scenario is None:
|
| 421 |
+
scenario = {
|
| 422 |
+
"title": title,
|
| 423 |
+
"description": description,
|
| 424 |
+
"level": level,
|
| 425 |
+
"category": category,
|
| 426 |
+
"ideal_prompt": description, # Use description as a fallback for keywords
|
| 427 |
+
"answer": answer_text
|
| 428 |
+
}
|
| 429 |
+
|
| 430 |
+
# Evaluate prompt
|
| 431 |
+
evaluation = evaluate_prompt(prompt, scenario)
|
| 432 |
+
|
| 433 |
+
# Build response
|
| 434 |
+
response = f"### Evaluation Results\n\n"
|
| 435 |
+
response += f"**Score: {evaluation['score']}/5**\n\n"
|
| 436 |
+
response += f"**Feedback:**\n{evaluation['feedback']}\n\n"
|
| 437 |
+
|
| 438 |
+
# Add progress information
|
| 439 |
+
response += f"### Your Progress\n\n"
|
| 440 |
+
response += f"**Skill Level:** {user_progress['skill_level']}\n"
|
| 441 |
+
response += f"**Scenarios Completed:** {user_progress['completed_scenarios']}\n"
|
| 442 |
+
if user_progress["badges"]:
|
| 443 |
+
response += f"**Badges Earned:** {', '.join(user_progress['badges'])}\n"
|
| 444 |
+
|
| 445 |
+
# Include the answer section
|
| 446 |
+
response += f"\n### Suggested Solution Approach\n\n"
|
| 447 |
+
response += f"{scenario['answer']}\n" if "answer" in scenario else "No specific solution provided for this scenario."
|
| 448 |
+
|
| 449 |
+
return response
|
| 450 |
+
except Exception as e:
|
| 451 |
+
# Hata durumunda basit bir yanıt ver
|
| 452 |
+
print(f"Error in submit_prompt: {str(e)}")
|
| 453 |
+
return f"### Evaluation\n\nYour prompt has been received but couldn't be evaluated due to an error.\n\nPlease try with another scenario."
|
| 454 |
|
| 455 |
# Helper function to update tables based on scenario type
|
| 456 |
def update_tables(tables, sample_data, answer):
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 457 |
try:
|
| 458 |
+
table_labels = ["sample_table1_label", "sample_table2_label", "sample_table3_label"]
|
| 459 |
+
table_elements = [sample_table1, sample_table2, sample_table3]
|
| 460 |
+
table_rows = [table_row, table_row2, table_row3]
|
| 461 |
+
|
| 462 |
+
# Hide all tables first
|
| 463 |
+
for row in table_rows:
|
| 464 |
+
row.visible = False
|
| 465 |
+
|
| 466 |
+
# Then show only the necessary tables
|
| 467 |
+
for i, table_name in enumerate(tables[:3]): # Limit to 3 tables
|
| 468 |
+
if i < len(tables):
|
| 469 |
+
table_rows[i].visible = True
|
| 470 |
+
table_labels[i].value = f"### {table_name.replace('_', ' ').title()}"
|
| 471 |
+
table_elements[i].value = sample_data.get(table_name, "No data available")
|
| 472 |
+
|
| 473 |
+
return [
|
| 474 |
+
table_rows[0].visible, table_rows[1].visible, table_rows[2].visible,
|
| 475 |
+
table_labels[0].value, table_labels[1].value, table_labels[2].value,
|
| 476 |
+
table_elements[0].value, table_elements[1].value, table_elements[2].value,
|
| 477 |
+
answer
|
| 478 |
+
]
|
| 479 |
except Exception as e:
|
| 480 |
+
print(f"Error in update_tables: {str(e)}")
|
| 481 |
+
# Hata durumunda varsayılan tabloları döndür
|
| 482 |
+
return [
|
| 483 |
+
True, False, False,
|
| 484 |
+
"### Sample Data", "", "",
|
| 485 |
+
"<table><tr><th>Data</th><th>Value</th></tr><tr><td>Sample</td><td>123</td></tr></table>",
|
| 486 |
+
"", "",
|
| 487 |
+
"Example answer"
|
| 488 |
+
]
|
| 489 |
+
|
| 490 |
+
def load_sample_data():
|
| 491 |
+
try:
|
| 492 |
+
# Birinci tabloyu yükle
|
| 493 |
+
if 'sample_customer_data' in globals() and hasattr(sample_customer_data, 'head'):
|
| 494 |
+
sample_html1 = sample_customer_data.head(5).to_html()
|
| 495 |
+
else:
|
| 496 |
+
sample_html1 = "<table><tr><th>CustomerID</th><th>Age</th></tr><tr><td>C0001</td><td>35</td></tr></table>"
|
| 497 |
+
|
| 498 |
+
# İkinci tabloyu yükle
|
| 499 |
+
if 'sample_sales_data' in globals() and hasattr(sample_sales_data, 'head'):
|
| 500 |
+
sample_html2 = sample_sales_data.head(5).to_html()
|
| 501 |
+
else:
|
| 502 |
+
sample_html2 = "<table><tr><th>OrderID</th><th>Amount</th></tr><tr><td>ORD-001</td><td>120.5</td></tr></table>"
|
| 503 |
+
|
| 504 |
+
return [
|
| 505 |
+
"### Müşteri Verileri",
|
| 506 |
+
sample_html1,
|
| 507 |
+
"### Satış Verileri",
|
| 508 |
+
sample_html2
|
| 509 |
+
]
|
| 510 |
+
except Exception as e:
|
| 511 |
+
# Hata durumunda basit bir örnek göster
|
| 512 |
+
print(f"Error in load_sample_data: {str(e)}")
|
| 513 |
+
return [
|
| 514 |
+
"### Örnek Veriler",
|
| 515 |
"<table><tr><th>CustomerID</th><th>Age</th></tr><tr><td>C0001</td><td>35</td></tr></table>",
|
| 516 |
+
"### Satış Verileri",
|
| 517 |
+
"<table><tr><th>OrderID</th><th>Amount</th></tr><tr><td>ORD-001</td><td>120.5</td></tr></table>"
|
| 518 |
+
]
|
|
|
|
| 519 |
|
| 520 |
def load_regular_scenario():
|
| 521 |
try:
|
| 522 |
+
# Varsayılan normal senaryo
|
| 523 |
+
default_scenario = {
|
| 524 |
+
"title": "Data Cleaning in Power BI",
|
| 525 |
+
"description": "Duplicates, missing values ve inconsistent date formatları içeren karışık bir satış veri setiniz var. Bu veriyi Power BI'da nasıl temizlersiniz?",
|
| 526 |
+
"level": "Beginner",
|
| 527 |
+
"category": "Power BI",
|
| 528 |
+
"sample_data": sample_sales_data.head(10).to_html() if 'sample_sales_data' in globals() and hasattr(sample_sales_data, 'head') else "<table><tr><th>Data</th><th>Value</th></tr><tr><td>Example</td><td>123</td></tr></table>",
|
| 529 |
+
"answer": "Power BI'da Remove Duplicates fonksiyonunu OrderID sütununa uygula, ortalama değerle Revenue sütunundaki eksik değerleri doldur, ve tarih sütunlarını MM/DD/YYYY formatına standardize et."
|
| 530 |
+
}
|
| 531 |
+
|
| 532 |
+
# Rastgele senaryo seçmeyi dene, başarısız olursa varsayılanı kullan
|
| 533 |
+
if 'scenarios' in globals() and isinstance(scenarios, list) and len(scenarios) > 0:
|
| 534 |
+
scenario = random.choice(scenarios)
|
| 535 |
+
else:
|
| 536 |
+
scenario = default_scenario
|
| 537 |
+
|
| 538 |
+
if not isinstance(scenario.get("sample_data", ""), str):
|
| 539 |
+
scenario["sample_data"] = default_scenario["sample_data"]
|
| 540 |
+
|
| 541 |
return (
|
| 542 |
scenario["title"],
|
| 543 |
scenario["description"],
|
|
|
|
| 545 |
scenario["category"],
|
| 546 |
True, False, False, # Only first table visible
|
| 547 |
"### Sample Data", "", "", # Only first table has header
|
| 548 |
+
scenario["sample_data"] if isinstance(scenario["sample_data"], str) else default_scenario["sample_data"],
|
| 549 |
"", "", # Empty second and third tables
|
| 550 |
scenario.get("answer", "No specific answer for this scenario.")
|
| 551 |
)
|
|
|
|
| 564 |
"Example answer text here."
|
| 565 |
)
|
| 566 |
|
| 567 |
+
def load_relational_scenario():
|
| 568 |
+
try:
|
| 569 |
+
# Varsayılan ilişkisel senaryo - bu her zaman çalışacak
|
| 570 |
+
default_scenario = {
|
| 571 |
+
"title": "Customer Purchase Analysis",
|
| 572 |
+
"description": "Müşteri verileriniz ve satış işlem verileriniz var. Müşteri satın alma kalıplarını analiz etmek için nasıl bir yaklaşım önerirsiniz?",
|
| 573 |
+
"level": "Intermediate",
|
| 574 |
+
"category": "Analytics",
|
| 575 |
+
"sample_data": {
|
| 576 |
+
"customer_data": sample_customer_data.head(10).to_html() if 'sample_customer_data' in globals() and hasattr(sample_customer_data, 'head') else "<table><tr><th>CustomerID</th><th>Age</th></tr><tr><td>C0001</td><td>35</td></tr></table>",
|
| 577 |
+
"sales_data": sample_sales_data.head(10).to_html() if 'sample_sales_data' in globals() and hasattr(sample_sales_data, 'head') else "<table><tr><th>OrderID</th><th>Amount</th></tr><tr><td>ORD-001</td><td>120.5</td></tr></table>"
|
| 578 |
+
},
|
| 579 |
+
"answer": "Müşteri satın alma kalıplarını analiz etmek için RFM (Recency, Frequency, Monetary) analizi ile demografik özelliklere göre segmentasyon yapılabilir."
|
| 580 |
+
}
|
| 581 |
+
|
| 582 |
+
# Rastgele senaryo seçmeyi dene, başarısız olursa varsayılanı kullan
|
| 583 |
+
if 'relational_scenarios' in globals() and isinstance(relational_scenarios, list) and len(relational_scenarios) > 0:
|
| 584 |
+
scenario = random.choice(relational_scenarios)
|
| 585 |
+
else:
|
| 586 |
+
scenario = default_scenario
|
| 587 |
+
|
| 588 |
+
return (
|
| 589 |
+
scenario["title"],
|
| 590 |
+
scenario["description"],
|
| 591 |
+
scenario["level"],
|
| 592 |
+
scenario["category"],
|
| 593 |
+
True, True, False, # Table visibility
|
| 594 |
+
"### Customer Data", "### Sales Data", "", # Table headers
|
| 595 |
+
scenario["sample_data"].get("customer_data", default_scenario["sample_data"]["customer_data"]) if isinstance(scenario["sample_data"], dict) else default_scenario["sample_data"]["customer_data"],
|
| 596 |
+
scenario["sample_data"].get("sales_data", default_scenario["sample_data"]["sales_data"]) if isinstance(scenario["sample_data"], dict) else default_scenario["sample_data"]["sales_data"],
|
| 597 |
+
"", # Empty third table
|
| 598 |
+
scenario.get("answer", "Example answer text here.")
|
| 599 |
+
)
|
| 600 |
+
except Exception as e:
|
| 601 |
+
# Hata durumunda varsayılan senaryo göster
|
| 602 |
+
print(f"Error in load_relational_scenario: {str(e)}")
|
| 603 |
+
return (
|
| 604 |
+
"Relationship Analysis",
|
| 605 |
+
"Error loading scenario. Please try another option.",
|
| 606 |
+
"Intermediate",
|
| 607 |
+
"Analytics",
|
| 608 |
+
True, True, False,
|
| 609 |
+
"### Sample Data 1", "### Sample Data 2", "",
|
| 610 |
+
"<table><tr><th>CustomerID</th><th>Age</th></tr><tr><td>C0001</td><td>35</td></tr></table>",
|
| 611 |
+
"<table><tr><th>OrderID</th><th>Amount</th></tr><tr><td>ORD-001</td><td>120.5</td></tr></table>",
|
| 612 |
+
"",
|
| 613 |
+
"Example answer text here."
|
| 614 |
+
)
|
| 615 |
+
|
| 616 |
def load_ai_scenario():
|
| 617 |
try:
|
| 618 |
+
# Varsayılan başlık ve açıklama
|
| 619 |
+
default_title = "Data Analysis with Python"
|
| 620 |
+
default_description = "Veri setinizdeki eksik değerler için Python kullanarak nasıl bir çözüm önerirsiniz?"
|
| 621 |
+
default_category = "Python"
|
|
|
|
| 622 |
|
| 623 |
+
# Tablo verisi için güvenlik kontrolü
|
| 624 |
+
if 'sample_sales_data' in globals() and hasattr(sample_sales_data, 'head'):
|
| 625 |
+
sample_data = sample_sales_data.head(10).to_html()
|
| 626 |
+
else:
|
| 627 |
+
sample_data = "<table><tr><th>Data</th><th>Value</th></tr><tr><td>Example</td><td>123</td></tr></table>"
|
| 628 |
|
| 629 |
+
# AI template kullanılabilir mi kontrol et
|
| 630 |
+
use_templates = 'ai_scenario_templates' in globals() and isinstance(ai_scenario_templates, list) and len(ai_scenario_templates) > 0
|
| 631 |
+
|
| 632 |
+
if use_templates:
|
| 633 |
+
try:
|
| 634 |
+
template = random.choice(ai_scenario_templates)
|
| 635 |
+
tool = random.choice(template.get("tools", ["Python"]))
|
| 636 |
+
data_type = random.choice(template.get("data_types", ["sample"]))
|
| 637 |
+
problem = random.choice(template.get("problems", ["analysis"]))
|
| 638 |
+
|
| 639 |
+
title = f"{template.get('title_prefix', 'Analysis with ')}{tool}"
|
| 640 |
+
description = f"Bu {data_type} veri seti üzerinde {problem} problemini çözmek için {tool} kullanmanız gerekiyor."
|
| 641 |
+
category = tool
|
| 642 |
+
except Exception as template_error:
|
| 643 |
+
print(f"Error creating AI template: {str(template_error)}")
|
| 644 |
+
title = default_title
|
| 645 |
+
description = default_description
|
| 646 |
+
category = default_category
|
| 647 |
+
else:
|
| 648 |
+
title = default_title
|
| 649 |
+
description = default_description
|
| 650 |
+
category = default_category
|
| 651 |
|
| 652 |
return (
|
| 653 |
title,
|
| 654 |
description,
|
| 655 |
"Intermediate",
|
| 656 |
+
category,
|
| 657 |
True, False, False, # Sadece ilk tablo görünür
|
| 658 |
"### Sample Data", "", "",
|
| 659 |
sample_data, "", "",
|
|
|
|
| 674 |
"Example answer text here."
|
| 675 |
)
|
| 676 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 677 |
# Build Gradio interface
|
| 678 |
with gr.Blocks(theme=gr.themes.Soft(), title="PromptMaster for Data Analytics") as app:
|
| 679 |
gr.Markdown("# PromptMaster for Data Analytics")
|
|
|
|
| 735 |
|
| 736 |
# Logic
|
| 737 |
new_scenario_btn.click(
|
| 738 |
+
get_new_scenario,
|
| 739 |
outputs=[
|
| 740 |
title_output, description_output, level_output, category_output,
|
| 741 |
table_row, table_row2, table_row3,
|
|
|
|
| 746 |
)
|
| 747 |
|
| 748 |
relational_scenario_btn.click(
|
| 749 |
+
get_relational_scenario,
|
| 750 |
outputs=[
|
| 751 |
title_output, description_output, level_output, category_output,
|
| 752 |
table_row, table_row2, table_row3,
|
|
|
|
| 757 |
)
|
| 758 |
|
| 759 |
ai_scenario_btn.click(
|
| 760 |
+
get_ai_scenario,
|
| 761 |
outputs=[
|
| 762 |
title_output, description_output, level_output, category_output,
|
| 763 |
table_row, table_row2, table_row3,
|