Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -405,6 +405,8 @@ def create_project_proposals(budget_cluster_df, problem_cluster_df, location_clu
|
|
| 405 |
consoleMessage_and_Print("\n Starting function: create_project_proposals")
|
| 406 |
proposals = {}
|
| 407 |
|
|
|
|
|
|
|
| 408 |
for loc in budget_cluster_df.index:
|
| 409 |
consoleMessage_and_Print(f"\n loc: {loc}")
|
| 410 |
|
|
@@ -436,8 +438,15 @@ def create_project_proposals(budget_cluster_df, problem_cluster_df, location_clu
|
|
| 436 |
# Check if proposal is valid
|
| 437 |
if isinstance(proposal, str) and proposal.strip(): # Valid string that's not empty
|
| 438 |
proposals[(loc, prob)] = proposal
|
|
|
|
|
|
|
|
|
|
|
|
|
| 439 |
else:
|
| 440 |
print(f"Skipping empty problem descriptions for location: {location}, problem domain: {problem_domain}")
|
|
|
|
|
|
|
|
|
|
| 441 |
|
| 442 |
return proposals
|
| 443 |
|
|
@@ -609,27 +618,82 @@ def process_excel(file):
|
|
| 609 |
consoleMessage_and_Print("Processing the DataFrame...")
|
| 610 |
processed_df, budget_cluster_df, problem_cluster_df, project_proposals, location_clusters, problem_clusters = nlp_pipeline(df)
|
| 611 |
# processed_df, budget_cluster_df, problem_cluster_df, location_clusters, problem_clusters = nlp_pipeline(df)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 612 |
|
| 613 |
-
|
| 614 |
-
|
| 615 |
-
|
| 616 |
-
|
|
|
|
| 617 |
|
| 618 |
consoleMessage_and_Print("Creating the Excel file.")
|
| 619 |
output_filename = "OutPut_PPs.xlsx"
|
| 620 |
with pd.ExcelWriter(output_filename) as writer:
|
|
|
|
| 621 |
|
| 622 |
try:
|
| 623 |
project_proposals_df.to_excel(writer, sheet_name='Project_Proposals', index=False)
|
| 624 |
except Exception as e:
|
| 625 |
consoleMessage_and_Print("Error during Project Proposal excelling at the end")
|
| 626 |
-
|
| 627 |
-
|
| 628 |
-
|
| 629 |
|
| 630 |
budget_cluster_df.to_excel(writer, sheet_name='Financial_Weights')
|
| 631 |
problem_cluster_df.to_excel(writer, sheet_name='Problem_Descriptions')
|
| 632 |
-
|
| 633 |
|
| 634 |
|
| 635 |
|
|
|
|
| 405 |
consoleMessage_and_Print("\n Starting function: create_project_proposals")
|
| 406 |
proposals = {}
|
| 407 |
|
| 408 |
+
sanban_debug = False
|
| 409 |
+
|
| 410 |
for loc in budget_cluster_df.index:
|
| 411 |
consoleMessage_and_Print(f"\n loc: {loc}")
|
| 412 |
|
|
|
|
| 438 |
# Check if proposal is valid
|
| 439 |
if isinstance(proposal, str) and proposal.strip(): # Valid string that's not empty
|
| 440 |
proposals[(loc, prob)] = proposal
|
| 441 |
+
|
| 442 |
+
sanban_debug = True
|
| 443 |
+
break
|
| 444 |
+
|
| 445 |
else:
|
| 446 |
print(f"Skipping empty problem descriptions for location: {location}, problem domain: {problem_domain}")
|
| 447 |
+
|
| 448 |
+
if sanban_debug:
|
| 449 |
+
break
|
| 450 |
|
| 451 |
return proposals
|
| 452 |
|
|
|
|
| 618 |
consoleMessage_and_Print("Processing the DataFrame...")
|
| 619 |
processed_df, budget_cluster_df, problem_cluster_df, project_proposals, location_clusters, problem_clusters = nlp_pipeline(df)
|
| 620 |
# processed_df, budget_cluster_df, problem_cluster_df, location_clusters, problem_clusters = nlp_pipeline(df)
|
| 621 |
+
|
| 622 |
+
consoleMessage_and_Print("Error was here")
|
| 623 |
+
#This code first converts the dictionary to a DataFrame with a single column for the composite key.
|
| 624 |
+
#Then, it splits the composite key into separate columns for Location_Cluster and Problem_Cluster.
|
| 625 |
+
#Finally, it reorders the columns and writes the DataFrame to an Excel sheet.
|
| 626 |
+
try: # Meta AI Solution
|
| 627 |
+
# Convert project_proposals dictionary to DataFrame
|
| 628 |
+
project_proposals_df = pd.DataFrame(list(project_proposals.items()), columns=['Location_Cluster_Problem_Cluster', 'Solutions Proposed'])
|
| 629 |
+
consoleMessage_and_Print("CheckPoint 1")
|
| 630 |
+
|
| 631 |
+
# Split the composite key into separate columns
|
| 632 |
+
project_proposals_df[['Location_Cluster', 'Problem_Cluster']] = project_proposals_df['Location_Cluster_Problem_Cluster'].apply(pd.Series)
|
| 633 |
+
consoleMessage_and_Print("CheckPoint 2")
|
| 634 |
+
|
| 635 |
+
# Drop the composite key column
|
| 636 |
+
project_proposals_df.drop('Location_Cluster_Problem_Cluster', axis=1, inplace=True)
|
| 637 |
+
consoleMessage_and_Print("CheckPoint 3")
|
| 638 |
+
|
| 639 |
+
# Reorder the columns
|
| 640 |
+
project_proposals_df = project_proposals_df[['Location_Cluster', 'Problem_Cluster', 'Solutions Proposed']]
|
| 641 |
+
consoleMessage_and_Print("CheckPoint 4")
|
| 642 |
+
|
| 643 |
+
except Exception as e:
|
| 644 |
+
consoleMessage_and_Print("Meta AI Solution did not work, trying CHATGPT solution")
|
| 645 |
+
try:
|
| 646 |
+
|
| 647 |
+
# Convert project_proposals dictionary to DataFrame
|
| 648 |
+
project_proposals_df = pd.DataFrame.from_dict(
|
| 649 |
+
proposals, orient='index', columns=['Solutions Proposed']
|
| 650 |
+
)
|
| 651 |
+
|
| 652 |
+
# If the index is a tuple, it automatically becomes a MultiIndex, so we handle naming correctly:
|
| 653 |
+
if isinstance(project_proposals_df.index, pd.MultiIndex):
|
| 654 |
+
project_proposals_df.index.names = ['Location_Cluster', 'Problem_Cluster']
|
| 655 |
+
else:
|
| 656 |
+
# If for some reason it's not a MultiIndex, we name it appropriately
|
| 657 |
+
project_proposals_df.index.name = 'Cluster'
|
| 658 |
+
|
| 659 |
+
# Reset index to have Location_Cluster and Problem_Cluster as columns
|
| 660 |
+
project_proposals_df.reset_index(inplace=True)
|
| 661 |
+
|
| 662 |
+
except Exception as e:
|
| 663 |
+
print(e)
|
| 664 |
+
|
| 665 |
+
|
| 666 |
+
|
| 667 |
+
|
| 668 |
+
|
| 669 |
+
|
| 670 |
+
|
| 671 |
+
|
| 672 |
+
# ### Convert project_proposals dictionary to DataFrame
|
| 673 |
+
# project_proposals_df = pd.DataFrame.from_dict(project_proposals, orient='index', columns=['Solutions Proposed'])
|
| 674 |
+
# project_proposals_df.index.names = ['Location_Cluster', 'Problem_Cluster']
|
| 675 |
+
# project_proposals_df.reset_index(inplace=True)
|
| 676 |
+
|
| 677 |
|
| 678 |
+
|
| 679 |
+
|
| 680 |
+
|
| 681 |
+
|
| 682 |
+
|
| 683 |
|
| 684 |
consoleMessage_and_Print("Creating the Excel file.")
|
| 685 |
output_filename = "OutPut_PPs.xlsx"
|
| 686 |
with pd.ExcelWriter(output_filename) as writer:
|
| 687 |
+
processed_df.to_excel(writer, sheet_name='Input_Processed', index=False)
|
| 688 |
|
| 689 |
try:
|
| 690 |
project_proposals_df.to_excel(writer, sheet_name='Project_Proposals', index=False)
|
| 691 |
except Exception as e:
|
| 692 |
consoleMessage_and_Print("Error during Project Proposal excelling at the end")
|
|
|
|
|
|
|
|
|
|
| 693 |
|
| 694 |
budget_cluster_df.to_excel(writer, sheet_name='Financial_Weights')
|
| 695 |
problem_cluster_df.to_excel(writer, sheet_name='Problem_Descriptions')
|
| 696 |
+
|
| 697 |
|
| 698 |
|
| 699 |
|