Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -3,41 +3,62 @@ import pandas as pd
|
|
3 |
|
4 |
def data_pre_processing(file_responses):
|
5 |
# Financial Weights can be anything (ultimately the row-wise weights are aggregated and the corresponding fractions are obtained from that rows' total tax payed)
|
6 |
-
|
7 |
-
# Define the columns to be processed
|
8 |
-
try:
|
9 |
|
|
|
10 |
# Convert columns to numeric and fill NaN values with 0
|
11 |
-
|
12 |
-
|
13 |
file_responses['Personal_TaxDirection_1_TaxWeightageAllocated'] = pd.to_numeric(file_responses['Personal_TaxDirection_1_TaxWeightageAllocated'], errors='coerce').fillna(0)
|
14 |
file_responses['Personal_TaxDirection_2_TaxWeightageAllocated'] = pd.to_numeric(file_responses['Personal_TaxDirection_2_TaxWeightageAllocated'], errors='coerce').fillna(0)
|
15 |
file_responses['Personal_TaxDirection_3_TaxWeightageAllocated'] = pd.to_numeric(file_responses['Personal_TaxDirection_3_TaxWeightageAllocated'], errors='coerce').fillna(0)
|
16 |
file_responses['Latest estimated Tax payment?'] = pd.to_numeric(file_responses['Latest estimated Tax payment?'], errors='coerce').fillna(0)
|
17 |
|
18 |
-
|
19 |
-
|
20 |
-
|
21 |
-
|
22 |
-
|
23 |
-
|
24 |
-
# Adding a new column 'Total Allocation' by summing specific columns by their names
|
25 |
file_responses['TotalWeightageAllocated'] = file_responses['Personal_TaxDirection_1_TaxWeightageAllocated'] + file_responses['Personal_TaxDirection_2_TaxWeightageAllocated'] + file_responses['Personal_TaxDirection_3_TaxWeightageAllocated']
|
26 |
-
|
27 |
-
# Calculating the actual TaxAmount to be allocated against each WISH (by rewriting the existing columns)
|
28 |
-
file_responses['Personal_TaxDirection_1_TaxWeightageAllocated'] = file_responses['Personal_TaxDirection_1_TaxWeightageAllocated'] * file_responses['Latest estimated Tax payment?'] / file_responses['TotalWeightageAllocated']
|
29 |
-
file_responses['Personal_TaxDirection_2_TaxWeightageAllocated'] = file_responses['Personal_TaxDirection_2_TaxWeightageAllocated'] * file_responses['Latest estimated Tax payment?'] / file_responses['TotalWeightageAllocated']
|
30 |
-
file_responses['Personal_TaxDirection_3_TaxWeightageAllocated'] = file_responses['Personal_TaxDirection_3_TaxWeightageAllocated'] * file_responses['Latest estimated Tax payment?'] / file_responses['TotalWeightageAllocated']
|
31 |
-
|
32 |
-
|
33 |
|
|
|
34 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
35 |
|
36 |
|
37 |
-
|
38 |
-
|
39 |
-
|
40 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
41 |
|
42 |
|
43 |
|
@@ -64,7 +85,7 @@ def data_pre_processing(file_responses):
|
|
64 |
# file_responses[tax_payment_col] * file_responses[col] / file_responses['Total Allocation']
|
65 |
# ).fillna(0)
|
66 |
|
67 |
-
return
|
68 |
except Exception as e:
|
69 |
return str(e)
|
70 |
|
@@ -119,20 +140,17 @@ interface = gr.Interface(
|
|
119 |
|
120 |
description=(
|
121 |
"<p style='font-weight: bold; font-size: 15px;'>Upload an Excel file to process and download the result or use the Example files:</p>"
|
122 |
-
"<p style='font-weight: bold; font-size: 15px;'>(click on any of them to directly process the file and Download the result)</p>"
|
123 |
|
124 |
"<p style='font-weight: bold; font-size: 15px; text-align: right;'>Processed output contains a Project Proposal for each Location~Problem paired combination (i.e. each cell).</p>"
|
125 |
-
"<p style='font-weight: bold; font-size: 15px; text-align: right;'>Corresponding Budget Allocation and estimated Project Completion Time are provided in different sheets.</p>"
|
126 |
|
|
|
127 |
|
128 |
-
"<p style='font-weight: bold; font-size: 15px; text-align:
|
129 |
-
|
130 |
|
131 |
|
132 |
-
"<p style='font-size:
|
133 |
-
"Feel free to upload your own Excel files to see the results. If you have any questions, refer to the documentation-links or contact "
|
134 |
-
"<a href='https://
|
135 |
-
"\t For more information, visit <a href='https://santanban.github.io/TaxDirection/' target='_blank'>#TaxDirection weblink</a>.</p>"
|
136 |
) # Solid description with right-aligned second sentence
|
137 |
|
138 |
)
|
|
|
3 |
|
4 |
def data_pre_processing(file_responses):
|
5 |
# Financial Weights can be anything (ultimately the row-wise weights are aggregated and the corresponding fractions are obtained from that rows' total tax payed)
|
6 |
+
|
7 |
+
try: # Define the columns to be processed
|
|
|
8 |
|
9 |
+
# Developing Numeric Columns
|
10 |
# Convert columns to numeric and fill NaN values with 0
|
|
|
|
|
11 |
file_responses['Personal_TaxDirection_1_TaxWeightageAllocated'] = pd.to_numeric(file_responses['Personal_TaxDirection_1_TaxWeightageAllocated'], errors='coerce').fillna(0)
|
12 |
file_responses['Personal_TaxDirection_2_TaxWeightageAllocated'] = pd.to_numeric(file_responses['Personal_TaxDirection_2_TaxWeightageAllocated'], errors='coerce').fillna(0)
|
13 |
file_responses['Personal_TaxDirection_3_TaxWeightageAllocated'] = pd.to_numeric(file_responses['Personal_TaxDirection_3_TaxWeightageAllocated'], errors='coerce').fillna(0)
|
14 |
file_responses['Latest estimated Tax payment?'] = pd.to_numeric(file_responses['Latest estimated Tax payment?'], errors='coerce').fillna(0)
|
15 |
|
16 |
+
# Adding a new column 'TotalWeightageAllocated' by summing specific columns by their names
|
|
|
|
|
|
|
|
|
|
|
|
|
17 |
file_responses['TotalWeightageAllocated'] = file_responses['Personal_TaxDirection_1_TaxWeightageAllocated'] + file_responses['Personal_TaxDirection_2_TaxWeightageAllocated'] + file_responses['Personal_TaxDirection_3_TaxWeightageAllocated']
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
18 |
|
19 |
+
|
20 |
|
21 |
+
# Creating Datasets (we assume everything has been provided to us in English, or the translations have been done already)
|
22 |
+
# Renaming the datasets into similar column headings
|
23 |
+
initial_dataset_1 = file_responses.rename(columns={
|
24 |
+
'Personal_TaxDirection_1_Wish': 'Problem_Description',
|
25 |
+
'Personal_TaxDirection_1_GeographicalLocation': 'Geographical_Location',
|
26 |
+
'Personal_TaxDirection_1_TaxWeightageAllocated': 'Financial_Weight'
|
27 |
+
})[['Problem_Description', 'Geographical_Location', 'Financial_Weight']]
|
28 |
+
|
29 |
+
initial_dataset_2 = file_responses.rename(columns={
|
30 |
+
'Personal_TaxDirection_2_Wish': 'Problem_Description',
|
31 |
+
'Personal_TaxDirection_2_GeographicalLocation': 'Geographical_Location',
|
32 |
+
'Personal_TaxDirection_2_TaxWeightageAllocated': 'Financial_Weight'
|
33 |
+
})[['Problem_Description', 'Geographical_Location', 'Financial_Weight']]
|
34 |
+
|
35 |
+
initial_dataset_3 = file_responses.rename(columns={
|
36 |
+
'Personal_TaxDirection_3_Wish': 'Problem_Description',
|
37 |
+
'Personal_TaxDirection_3_GeographicalLocation': 'Geographical_Location',
|
38 |
+
'Personal_TaxDirection_3_TaxWeightageAllocated': 'Financial_Weight'
|
39 |
+
})[['Problem_Description', 'Geographical_Location', 'Financial_Weight']]
|
40 |
|
41 |
|
42 |
+
|
43 |
+
# Calculating the actual TaxAmount to be allocated against each WISH (by overwriting the newly created columns)
|
44 |
+
initial_dataset_1['Financial_Weight'] = file_responses['Personal_TaxDirection_1_TaxWeightageAllocated'] * file_responses['Latest estimated Tax payment?'] / file_responses['TotalWeightageAllocated']
|
45 |
+
initial_dataset_2['Financial_Weight'] = file_responses['Personal_TaxDirection_2_TaxWeightageAllocated'] * file_responses['Latest estimated Tax payment?'] / file_responses['TotalWeightageAllocated']
|
46 |
+
initial_dataset_3['Financial_Weight'] = file_responses['Personal_TaxDirection_3_TaxWeightageAllocated'] * file_responses['Latest estimated Tax payment?'] / file_responses['TotalWeightageAllocated']
|
47 |
+
|
48 |
+
# Removing useless rows
|
49 |
+
# Drop rows where Problem_Description is NaN or an empty string
|
50 |
+
initial_dataset_1 = initial_dataset_1.dropna(subset=['Problem_Description'], axis=0)
|
51 |
+
initial_dataset_2 = initial_dataset_2.dropna(subset=['Problem_Description'], axis=0)
|
52 |
+
initial_dataset_3 = initial_dataset_3.dropna(subset=['Problem_Description'], axis=0)
|
53 |
+
|
54 |
+
# Convert 'Problem_Description' column to string type
|
55 |
+
initial_dataset_1['Problem_Description'] = initial_dataset_1['Problem_Description'].astype(str)
|
56 |
+
initial_dataset_2['Problem_Description'] = initial_dataset_2['Problem_Description'].astype(str)
|
57 |
+
initial_dataset_3['Problem_Description'] = initial_dataset_3['Problem_Description'].astype(str)
|
58 |
+
|
59 |
+
# Merging the Datasets
|
60 |
+
# Vertically concatenating (merging) the 3 DataFrames
|
61 |
+
merged_dataset = pd.concat([initial_dataset_1, initial_dataset_2, initial_dataset_3], ignore_index=True)
|
62 |
|
63 |
|
64 |
|
|
|
85 |
# file_responses[tax_payment_col] * file_responses[col] / file_responses['Total Allocation']
|
86 |
# ).fillna(0)
|
87 |
|
88 |
+
return merged_dataset
|
89 |
except Exception as e:
|
90 |
return str(e)
|
91 |
|
|
|
140 |
|
141 |
description=(
|
142 |
"<p style='font-weight: bold; font-size: 15px;'>Upload an Excel file to process and download the result or use the Example files:</p>"
|
|
|
143 |
|
144 |
"<p style='font-weight: bold; font-size: 15px; text-align: right;'>Processed output contains a Project Proposal for each Location~Problem paired combination (i.e. each cell).</p>"
|
|
|
145 |
|
146 |
+
"<p style='font-weight: bold; font-size: 15px;'>(click on any of them to directly process the file and Download the result)</p>"
|
147 |
|
148 |
+
"<p style='font-weight: bold; font-size: 15px; text-align: right;'>Corresponding Budget Allocation and estimated Project Completion Time are provided in different sheets.</p>"
|
|
|
149 |
|
150 |
|
151 |
+
"<p style='font-size: 12px; color: gray; text-align: center'>This tool allows for the systematic evaluation and proposal of solutions tailored to specific location-problem pairs, ensuring efficient resource allocation and project planning.</p>"
|
152 |
+
"<p style='font-size: 12px; color: gray; text-align: center'>Note: The example files provided above are for demonstration purposes. Feel free to upload your own Excel files to see the results. If you have any questions, refer to the documentation-links or contact <a href='https://www.change.org/p/democracy-evolution-ensuring-humanity-s-eternal-existence-through-taxdirection' target='_blank'>support</a>.</p>"
|
153 |
+
"<p style='font-size: 12px; color: gray; text-align: center'>For more information, visit <a href='https://santanban.github.io/TaxDirection/' target='_blank'>#TaxDirection weblink</a>.</p>"
|
|
|
154 |
) # Solid description with right-aligned second sentence
|
155 |
|
156 |
)
|