neuralworm
commited on
Commit
•
88e0a0d
1
Parent(s):
769668f
initial commit
Browse files
app.py
CHANGED
@@ -91,43 +91,35 @@ def find_matching_dates(date_gematrias, names, search_journal_sum):
|
|
91 |
return matching_dates
|
92 |
|
93 |
|
94 |
-
def
|
95 |
-
"""Finds
|
96 |
-
logger.debug("Calculating shared
|
97 |
-
|
98 |
-
name_gematrias = {}
|
99 |
-
|
100 |
-
for name in names:
|
101 |
-
name_gematrias[name] = calculate_gematria_sum(name)
|
102 |
|
103 |
for date_str, date_data in date_gematrias.items():
|
104 |
date_gematria = date_data["date_gematria"]
|
105 |
-
for
|
106 |
-
|
107 |
-
|
108 |
-
|
109 |
-
|
110 |
-
|
111 |
-
|
112 |
-
|
113 |
-
|
114 |
-
|
115 |
-
|
116 |
-
|
117 |
-
|
118 |
-
|
119 |
-
|
120 |
-
|
121 |
-
|
122 |
-
|
123 |
-
|
124 |
-
|
125 |
|
126 |
-
return (
|
127 |
-
json.dumps(matching_dates, indent=4, ensure_ascii=False),
|
128 |
-
json.dumps(date_gematrias, indent=4, ensure_ascii=False), # Keep this for debugging if needed
|
129 |
-
json.dumps(shared_gematria_dates, indent=4, ensure_ascii=False)
|
130 |
-
)
|
131 |
|
132 |
|
133 |
# --- Main Gradio App ---
|
@@ -136,21 +128,40 @@ with gr.Blocks() as app:
|
|
136 |
start_date = Calendar(type="datetime", label="Start Date")
|
137 |
end_date = Calendar(type="datetime", label="End Date")
|
138 |
with gr.Row():
|
139 |
-
names_input = gr.Textbox(label="Names (one per line)", lines=5)
|
140 |
search_sum = gr.Number(label="Search Journal Sum", precision=0)
|
141 |
|
142 |
-
calculate_btn = gr.Button("Calculate")
|
143 |
with gr.Row():
|
144 |
-
|
145 |
-
|
146 |
-
|
|
|
|
|
|
|
147 |
|
148 |
|
149 |
calculate_btn.click(
|
150 |
-
calculate_and_find,
|
151 |
inputs=[start_date, end_date, names_input, search_sum],
|
152 |
-
outputs=[matching_dates_output,
|
153 |
)
|
154 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
155 |
if __name__ == "__main__":
|
156 |
app.launch(share=False)
|
|
|
91 |
return matching_dates
|
92 |
|
93 |
|
94 |
+
def find_shared_journal_sums(date_gematrias, names):
|
95 |
+
"""Finds shared journal sums and formats output with names and dates together."""
|
96 |
+
logger.debug("Calculating shared journal sums...")
|
97 |
+
shared_sums = {}
|
98 |
+
name_gematrias = {name: calculate_gematria_sum(name) for name in names}
|
|
|
|
|
|
|
99 |
|
100 |
for date_str, date_data in date_gematrias.items():
|
101 |
date_gematria = date_data["date_gematria"]
|
102 |
+
for name, name_gematria in name_gematrias.items():
|
103 |
+
journal_sum = date_gematria + name_gematria
|
104 |
+
if journal_sum not in shared_sums:
|
105 |
+
shared_sums[journal_sum] = {} # Initialize as a dictionary
|
106 |
+
if name not in shared_sums[journal_sum]:
|
107 |
+
shared_sums[journal_sum][name] = [] # Initialize list for each name
|
108 |
+
shared_sums[journal_sum][name].append(date_str)
|
109 |
+
|
110 |
+
# Filter out sums not shared by at least two names and format output
|
111 |
+
result = {}
|
112 |
+
for journal_sum, data in shared_sums.items():
|
113 |
+
if len(data) >= 2: # Check if at least two names have this sum
|
114 |
+
result[journal_sum] = {}
|
115 |
+
for name, dates in data.items():
|
116 |
+
result[journal_sum][name] = dates
|
117 |
+
|
118 |
+
|
119 |
+
|
120 |
+
logger.debug(f"Shared Journal Sums: {result}")
|
121 |
+
return result
|
122 |
|
|
|
|
|
|
|
|
|
|
|
123 |
|
124 |
|
125 |
# --- Main Gradio App ---
|
|
|
128 |
start_date = Calendar(type="datetime", label="Start Date")
|
129 |
end_date = Calendar(type="datetime", label="End Date")
|
130 |
with gr.Row():
|
131 |
+
names_input = gr.Textbox(label="Names (one per line)", lines=5)
|
132 |
search_sum = gr.Number(label="Search Journal Sum", precision=0)
|
133 |
|
|
|
134 |
with gr.Row():
|
135 |
+
calculate_btn = gr.Button("Search Journal Sum")
|
136 |
+
shared_sums_btn = gr.Button("Find Shared Journal Sums") # new button
|
137 |
+
|
138 |
+
matching_dates_output = gr.JSON(label="Matching Dates")
|
139 |
+
shared_sums_output = gr.JSON(label="Shared Journal Sums")
|
140 |
+
|
141 |
|
142 |
|
143 |
calculate_btn.click(
|
144 |
+
lambda start_date, end_date, names_input, search_sum: calculate_and_find(start_date, end_date, names_input, int(search_sum), find_shared = False), # find_shared as input
|
145 |
inputs=[start_date, end_date, names_input, search_sum],
|
146 |
+
outputs=[matching_dates_output, shared_sums_output] # shared_sums_output included for consistency, even if empty
|
147 |
)
|
148 |
|
149 |
+
shared_sums_btn.click(
|
150 |
+
lambda start_date, end_date, names_input: calculate_and_find(start_date, end_date, names_input, 0, find_shared = True), # find_shared as input, search_sum is not used here.
|
151 |
+
inputs=[start_date, end_date, names_input], #search_sum is irrelevant here, can be omitted
|
152 |
+
outputs=[matching_dates_output, shared_sums_output]
|
153 |
+
)
|
154 |
+
|
155 |
+
def calculate_and_find(start_date, end_date, names_input, search_journal_sum, find_shared = False): # added find_shared parameter
|
156 |
+
names = [n.strip() for n in names_input.split("\n") if n.strip()]
|
157 |
+
date_gematrias = perform_gematria_calculation_for_date_range(start_date, end_date)
|
158 |
+
if find_shared:
|
159 |
+
shared_sums = find_shared_journal_sums(date_gematrias, names)
|
160 |
+
return None, json.dumps(shared_sums, indent=4, ensure_ascii=False) # outputs for consistency with 3 outputs
|
161 |
+
else:
|
162 |
+
matching_dates = find_matching_dates(date_gematrias, names, int(search_journal_sum))
|
163 |
+
return json.dumps(matching_dates, indent=4, ensure_ascii=False), None # shared sums are None when this button is pressed
|
164 |
+
|
165 |
+
|
166 |
if __name__ == "__main__":
|
167 |
app.launch(share=False)
|