Spaces:
Sleeping
Sleeping
neuralworm
commited on
Commit
•
e8bbf2e
1
Parent(s):
75d4ca3
initial commit
Browse files
app.py
CHANGED
@@ -9,9 +9,9 @@ from datetime import datetime, timedelta
|
|
9 |
import json
|
10 |
import inflect
|
11 |
|
12 |
-
# ---
|
13 |
def calculate_gematria_sum(text):
|
14 |
-
"""
|
15 |
if text:
|
16 |
text_gematria = calculate_gematria(strip_diacritics(text))
|
17 |
return text_gematria
|
@@ -33,12 +33,12 @@ def number_to_ordinal_word(number):
|
|
33 |
return ordinal_dict.get(number, "")
|
34 |
|
35 |
def date_to_words(date_string):
|
36 |
-
"""
|
37 |
inf_engine = inflect.engine()
|
38 |
date_obj = datetime.strptime(date_string, "%Y-%m-%d")
|
39 |
|
40 |
year = date_obj.year
|
41 |
-
if
|
42 |
year_words = f"{inf_engine.number_to_words(year // 100, andword='') } hundred"
|
43 |
if year % 100 != 0:
|
44 |
year_words += f" {inf_engine.number_to_words(year % 100, andword='')}"
|
@@ -54,19 +54,19 @@ def date_to_words(date_string):
|
|
54 |
return output_text
|
55 |
|
56 |
def perform_gematria_calculation_for_date_range(start_date, end_date):
|
57 |
-
"""
|
58 |
-
logger.info(f"
|
59 |
results = {}
|
60 |
delta = timedelta(days=1)
|
61 |
current_date = start_date
|
62 |
|
63 |
while current_date <= end_date:
|
64 |
-
#
|
65 |
date_string = current_date.strftime("%Y-%m-%d")
|
66 |
date_words = date_to_words(date_string)
|
67 |
-
logger.info(f"
|
68 |
gematria_sum = calculate_gematria_sum(date_words)
|
69 |
-
logger.info(f"Gematria
|
70 |
|
71 |
if gematria_sum not in results:
|
72 |
results[gematria_sum] = []
|
@@ -81,7 +81,7 @@ def perform_gematria_calculation_for_date_range(start_date, end_date):
|
|
81 |
return results
|
82 |
|
83 |
def generate_json_output(results, start_date, end_date):
|
84 |
-
"""
|
85 |
result = {
|
86 |
"DateRange": {
|
87 |
"StartDate": start_date.strftime("%Y-%m-%d"),
|
@@ -91,24 +91,24 @@ def generate_json_output(results, start_date, end_date):
|
|
91 |
}
|
92 |
return json.dumps(result, indent=4, ensure_ascii=False)
|
93 |
|
94 |
-
# ---
|
95 |
with gr.Blocks() as app:
|
96 |
with gr.Row():
|
97 |
-
start_date = Calendar(type="datetime", label="
|
98 |
-
end_date = Calendar(type="datetime", label="
|
99 |
|
100 |
-
calculate_btn = gr.Button("Gematria
|
101 |
-
json_output = gr.Textbox(label="JSON
|
102 |
|
103 |
-
# --- Event
|
104 |
def perform_calculation(start_date, end_date):
|
105 |
-
"""
|
106 |
-
logger.info(f"perform_calculation
|
107 |
results = perform_gematria_calculation_for_date_range(start_date, end_date)
|
108 |
json_result = generate_json_output(results, start_date, end_date)
|
109 |
return json_result
|
110 |
|
111 |
-
# --- Event
|
112 |
calculate_btn.click(
|
113 |
perform_calculation,
|
114 |
inputs=[start_date, end_date],
|
|
|
9 |
import json
|
10 |
import inflect
|
11 |
|
12 |
+
# --- Helper Functions ---
|
13 |
def calculate_gematria_sum(text):
|
14 |
+
"""Calculates the gematria sum of a given text."""
|
15 |
if text:
|
16 |
text_gematria = calculate_gematria(strip_diacritics(text))
|
17 |
return text_gematria
|
|
|
33 |
return ordinal_dict.get(number, "")
|
34 |
|
35 |
def date_to_words(date_string):
|
36 |
+
"""Converts a date in YYYY-MM-DD format to English words."""
|
37 |
inf_engine = inflect.engine()
|
38 |
date_obj = datetime.strptime(date_string, "%Y-%m-%d")
|
39 |
|
40 |
year = date_obj.year
|
41 |
+
if 1100 <= year <= 1999:
|
42 |
year_words = f"{inf_engine.number_to_words(year // 100, andword='') } hundred"
|
43 |
if year % 100 != 0:
|
44 |
year_words += f" {inf_engine.number_to_words(year % 100, andword='')}"
|
|
|
54 |
return output_text
|
55 |
|
56 |
def perform_gematria_calculation_for_date_range(start_date, end_date):
|
57 |
+
"""Performs gematria calculation for a date range and groups by sum."""
|
58 |
+
logger.info(f"Start Date: {start_date}, End Date: {end_date}")
|
59 |
results = {}
|
60 |
delta = timedelta(days=1)
|
61 |
current_date = start_date
|
62 |
|
63 |
while current_date <= end_date:
|
64 |
+
# Convert date to string
|
65 |
date_string = current_date.strftime("%Y-%m-%d")
|
66 |
date_words = date_to_words(date_string)
|
67 |
+
logger.info(f"Date: {current_date}, Day Name: {date_words}")
|
68 |
gematria_sum = calculate_gematria_sum(date_words)
|
69 |
+
logger.info(f"Gematria Sum: {gematria_sum}")
|
70 |
|
71 |
if gematria_sum not in results:
|
72 |
results[gematria_sum] = []
|
|
|
81 |
return results
|
82 |
|
83 |
def generate_json_output(results, start_date, end_date):
|
84 |
+
"""Generates the JSON output with the date range and results."""
|
85 |
result = {
|
86 |
"DateRange": {
|
87 |
"StartDate": start_date.strftime("%Y-%m-%d"),
|
|
|
91 |
}
|
92 |
return json.dumps(result, indent=4, ensure_ascii=False)
|
93 |
|
94 |
+
# --- Main Gradio App ---
|
95 |
with gr.Blocks() as app:
|
96 |
with gr.Row():
|
97 |
+
start_date = Calendar(type="datetime", label="Start Date")
|
98 |
+
end_date = Calendar(type="datetime", label="End Date")
|
99 |
|
100 |
+
calculate_btn = gr.Button("Calculate Gematria for Date Range")
|
101 |
+
json_output = gr.Textbox(label="JSON Output")
|
102 |
|
103 |
+
# --- Event Handlers ---
|
104 |
def perform_calculation(start_date, end_date):
|
105 |
+
"""Performs the calculation and generates the JSON output."""
|
106 |
+
logger.info(f"perform_calculation called with: start_date={start_date}, end_date={end_date}")
|
107 |
results = perform_gematria_calculation_for_date_range(start_date, end_date)
|
108 |
json_result = generate_json_output(results, start_date, end_date)
|
109 |
return json_result
|
110 |
|
111 |
+
# --- Event Triggers ---
|
112 |
calculate_btn.click(
|
113 |
perform_calculation,
|
114 |
inputs=[start_date, end_date],
|