Abbie23 commited on
Commit
028b06d
·
verified ·
1 Parent(s): 33b12e0

Upload 2 files

Browse files
Files changed (2) hide show
  1. fengshui_app.py +138 -0
  2. requirements.txt +3 -0
fengshui_app.py ADDED
@@ -0,0 +1,138 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import gradio as gr
2
+ import pandas as pd
3
+
4
+ def clean_text(text):
5
+ if not isinstance(text, str):
6
+ return text
7
+ text = text.replace('\n', ' ').replace('\r', ' ')
8
+ return ' '.join(text.split())
9
+
10
+ def generate_reports(file, inputs):
11
+ excel_data = pd.ExcelFile(file.name)
12
+ clean_sheet_names = [name.strip() for name in excel_data.sheet_names]
13
+
14
+ output_rows = []
15
+ output_rows_perm = []
16
+
17
+ for item in inputs:
18
+ dir_name = item['Direction']
19
+ bagua_area = item['Bagua']
20
+ pm = int(item['PM'])
21
+ pm_star = int(item['PM*'])
22
+ an = int(item['AN'])
23
+
24
+ # Annual
25
+ sheet_name = clean_sheet_names[pm - 1]
26
+ df = excel_data.parse(sheet_name)
27
+ match = df[(df['PM*'] == pm_star) & (df['AN'] == an)]
28
+ if match.empty:
29
+ sheet_name = clean_sheet_names[pm_star - 1]
30
+ df = excel_data.parse(sheet_name)
31
+ match = df[(df['PM*'] == pm) & (df['AN'] == an)]
32
+ if match.empty:
33
+ result = {
34
+ "Positive Energy": "No data found",
35
+ "Negative Energy": "No data found",
36
+ "REMEDY": "No data found",
37
+ "ADDITIONAL": "No data found",
38
+ "INTERPRETATIONS": "No data found"
39
+ }
40
+ else:
41
+ row = match.iloc[0]
42
+ result = {
43
+ "Positive Energy": clean_text(row['POSITIVE ENERGY']),
44
+ "Negative Energy": clean_text(row['NEGATIVE ENERGY']),
45
+ "REMEDY": clean_text(row['REMEDY']),
46
+ "ADDITIONAL": clean_text(row['ADDITIONAL']),
47
+ "INTERPRETATIONS": clean_text(row['INTERPRETATIONS'])
48
+ }
49
+ output_rows.append({
50
+ "Direction": dir_name,
51
+ "Bagua Area": bagua_area,
52
+ "PM": pm,
53
+ "PM*": pm_star,
54
+ "AN": an,
55
+ **result
56
+ })
57
+
58
+ # Permanent
59
+ sheet_name = clean_sheet_names[pm - 1]
60
+ df = excel_data.parse(sheet_name)
61
+ match_perm = df[(df['PM*'] == pm_star) & (df['AN'].isna())]
62
+ if match_perm.empty:
63
+ sheet_name = clean_sheet_names[pm_star - 1]
64
+ df = excel_data.parse(sheet_name)
65
+ match_perm = df[(df['PM*'] == pm) & (df['AN'].isna())]
66
+ if match_perm.empty:
67
+ result_perm = {
68
+ "Positive Energy": "No data found",
69
+ "Negative Energy": "No data found"
70
+ }
71
+ else:
72
+ row = match_perm.iloc[0]
73
+ result_perm = {
74
+ "Positive Energy": clean_text(row['POSITIVE ENERGY']),
75
+ "Negative Energy": clean_text(row['NEGATIVE ENERGY'])
76
+ }
77
+ output_rows_perm.append({
78
+ "Direction": dir_name,
79
+ "Bagua Area": bagua_area,
80
+ "PM": pm,
81
+ "PM*": pm_star,
82
+ **result_perm
83
+ })
84
+
85
+ df_annual = pd.DataFrame(output_rows)
86
+ annual_file = "Annual_Report_Populated.csv"
87
+ df_annual.to_csv(annual_file, index=False)
88
+
89
+ df_perm = pd.DataFrame(output_rows_perm)
90
+ perm_file = "Permanent_Report_Populated.csv"
91
+ df_perm.to_csv(perm_file, index=False)
92
+
93
+ return annual_file, perm_file
94
+
95
+ directions = [
96
+ {"Direction": "West", "Bagua": "Children & Creativity"},
97
+ {"Direction": "North West", "Bagua": "Helpful People"},
98
+ {"Direction": "North", "Bagua": "Career & Life’s Journey"},
99
+ {"Direction": "North East", "Bagua": "Knowledge & Self-Cultivation"},
100
+ {"Direction": "East", "Bagua": "Family & Community"},
101
+ {"Direction": "South East", "Bagua": "Wealth & Prosperity"},
102
+ {"Direction": "South", "Bagua": "Fame & Recognition"},
103
+ {"Direction": "South West", "Bagua": "Love & Marriage"},
104
+ {"Direction": "Centre", "Bagua": "Health"}
105
+ ]
106
+
107
+ def collect_input(*args):
108
+ result = []
109
+ for i, d in enumerate(directions):
110
+ result.append({
111
+ "Direction": d["Direction"],
112
+ "Bagua": d["Bagua"],
113
+ "PM": args[i*3],
114
+ "PM*": args[i*3+1],
115
+ "AN": args[i*3+2]
116
+ })
117
+ return result
118
+
119
+ with gr.Blocks() as demo:
120
+ file = gr.File(label="Upload your Excel file")
121
+ number_inputs = []
122
+ for d in directions:
123
+ pm = gr.Number(label=f"{d['Direction']} PM")
124
+ pm_star = gr.Number(label=f"{d['Direction']} PM*")
125
+ an = gr.Number(label=f"{d['Direction']} AN")
126
+ number_inputs.extend([pm, pm_star, an])
127
+
128
+ generate_button = gr.Button("Generate Reports")
129
+ annual_out = gr.File(label="Download Annual Report")
130
+ perm_out = gr.File(label="Download Permanent Report")
131
+
132
+ def wrapper(file, *args):
133
+ inputs = collect_input(*args)
134
+ return generate_reports(file, inputs)
135
+
136
+ generate_button.click(wrapper, inputs=[file, *number_inputs], outputs=[annual_out, perm_out])
137
+
138
+ demo.launch(share=True)
requirements.txt ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ gradio
2
+ pandas
3
+ openpyxl