File size: 5,764 Bytes
76bfb75
bddf29f
 
2d6a87c
2d48be5
61e6b62
 
 
 
 
 
 
 
 
 
7e1f943
 
2d48be5
7e1f943
 
 
61e6b62
5950746
 
 
61e6b62
d2b24d8
 
61e6b62
d2b24d8
 
61e6b62
d2b24d8
 
61e6b62
d2b24d8
61e6b62
d2b24d8
61e6b62
d2b24d8
 
 
 
 
61e6b62
 
 
 
443053b
 
d2b24d8
 
443053b
bddf29f
e4d07f2
 
 
 
 
443053b
61e6b62
3fca7f2
3d103e2
f7bb109
3d103e2
3fca7f2
3d103e2
443053b
e4d07f2
 
bddf29f
1398651
 
 
 
 
21e8468
 
 
 
 
 
1398651
bddf29f
 
 
99fe899
1398651
 
 
0b34e59
8d1b0ca
0b34e59
 
1bf26c9
8695021
1bf26c9
fa36f72
db05398
88e6c23
 
fa36f72
88e6c23
 
60cbd2f
c3e7cfc
60cbd2f
21e8468
fa36f72
d95655c
 
76bfb75
 
0b34e59
1446dbe
7e1f943
 
21e8468
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
import gradio as gr
import pandas as pd

def data_pre_processing(file_responses):
    # Financial Weights can be anything (ultimately the row-wise weights are aggregated and the corresponding fractions are obtained from that rows' total tax payed)
    try:
        # Define the columns to be processed
        columns = [
            '''Your financial allocation for Problem 1:
            Mention the percentage of your Tax Amount which you wish the Government would allocate through their annual budget, to implement a specific solution for your 1st problem.''',
            '''Your financial allocation for Problem 2:
            Mention the percentage of your Tax Amount which you wish the Government would allocate through their annual budget, to implement a solution specifically to your 2nd problem.''',
            '''Your financial allocation for Problem 3:
            Mention the percentage of your Tax Amount which you wish the Government would allocate through their annual budget, to implement a solution specifically to your 3rd problem.'''
        ]
        file_responses = file_responses[[
            "Personal_TaxDirection_1_Wish",
            "Personal_TaxDirection_2_TaxWeightageAllocated"
            ]]

        
        
        # # Convert columns to numeric and fill NaN values with 0
        # for col in columns:
        #     file_responses[col] = pd.to_numeric(file_responses[col], errors='coerce').fillna(0)
        
        # # Calculate the Total Allocation
        # file_responses['Total Allocation'] = file_responses[columns].sum(axis=1)
        
        # # Convert the Tax Payment column to numeric
        # tax_payment_col = '''How much was your latest Tax payment (in U$D) ?
        
        # Please try to be as accurate as possible:
        # Eg.: If your last tax amount was INR 25,785/-; then convert it in U$D and enter only the amount as: 310.
        
        # If you have never paid tax, consider putting in a realistic donation amount which wish to contribute towards helping yourself obtain the desired relief.'''
        
        # file_responses[tax_payment_col] = pd.to_numeric(file_responses[tax_payment_col], errors='coerce').fillna(0)
        
        # # Calculate Financial Token Weights
        # for i, col in enumerate(columns, start=1):
        #     file_responses[f'Financial Token Weight for Problem {i}'] = (
        #         file_responses[tax_payment_col] * file_responses[col] / file_responses['Total Allocation']
        #     ).fillna(0)
        
        return file_responses
    except Exception as e:
        return str(e)

def nlp_pipeline(original_df):
    processed_df = data_pre_processing(original_df)
    return processed_df

def process_excel(file):
    try:
        # Ensure the file path is correct
        file_path = file.name if hasattr(file, 'name') else file
        # Read the Excel file
        df = pd.read_excel(file_path)
        
        # Process the DataFrame
        result_df = nlp_pipeline(df)

        output_file = "Output_ProjectProposals.xlsx"
        result_df.to_excel(output_file, index=False)
        
        return output_file  # Return the processed DataFrame as Excel file
        
    except Exception as e:
        return str(e)  # Return the error message






example_files = ['#TaxDirection (Responses)_BasicExample.xlsx',
                 '#TaxDirection (Responses)_IntermediateExample.xlsx',
                 '#TaxDirection (Responses)_UltimateExample.xlsx'
                ]


    
# Define the Gradio interface
interface = gr.Interface(
    fn=process_excel,  # The function to process the uploaded file
    inputs=gr.File(type="filepath", label="Upload Excel File here. \t Be sure to check that the column headings in your upload are the same as in the Example files below. \t (Otherwise there will be Error during the processing)"),  # File upload input
    
    examples=example_files,  # Add the example files
    
    # outputs=gr.File(label="Download Processed Excel File"),  # File download output
    outputs=gr.File(label="Download the processed Excel File containing the ** Project Proposals ** for each Location~Problem paired combination"),  # File download output
    
    
    # title="Excel File Uploader",
    title="Upload Excel file containing #TaxDirections → Download HyperLocal Project Proposals\n",
    

    description=(
        "<p style='font-weight: bold; font-size: 15px;'>Upload an Excel file to process and download the result or use the Example files:</p>"
        "<p style='font-weight: bold; font-size: 15px;'>(click on any of them to directly process the file and Download the result)</p>"
        
        "<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>"
        "<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>"
        
        "<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>."
        "\t For more information, visit <a href='https://santanban.github.io/TaxDirection/' target='_blank'>#TaxDirection weblink</a>.</p>"
    )  # Solid description with right-aligned second sentence

)



# Launch the interface
if __name__ == "__main__":
    interface.launch()