Spaces:
Sleeping
Sleeping
Commit
·
7a778e3
1
Parent(s):
78317d1
initial commit
Browse files
app.py
CHANGED
@@ -4,12 +4,11 @@ logging.basicConfig(level=logging.INFO)
|
|
4 |
|
5 |
import gradio as gr
|
6 |
from gradio_calendar import Calendar
|
7 |
-
from utils import date_to_words # Hypothèse : utils.py contient la fonction date_to_words
|
8 |
from gematria import calculate_gematria, strip_diacritics
|
9 |
from datetime import datetime, timedelta
|
10 |
import json
|
11 |
|
12 |
-
# ---
|
13 |
def calculate_gematria_sum(text):
|
14 |
if text:
|
15 |
text_gematria = calculate_gematria(strip_diacritics(text))
|
@@ -17,17 +16,32 @@ def calculate_gematria_sum(text):
|
|
17 |
else:
|
18 |
return None
|
19 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
20 |
def perform_gematria_calculation_for_date_range(start_date, end_date):
|
21 |
-
logger.info(f"
|
22 |
results = {}
|
23 |
delta = timedelta(days=1)
|
24 |
current_date = start_date
|
25 |
|
26 |
while current_date <= end_date:
|
27 |
-
|
28 |
-
|
|
|
|
|
29 |
gematria_sum = calculate_gematria_sum(date_words)
|
30 |
-
logger.info(f"
|
31 |
|
32 |
if gematria_sum not in results:
|
33 |
results[gematria_sum] = []
|
@@ -51,23 +65,23 @@ def generate_json_output(results, start_date, end_date):
|
|
51 |
}
|
52 |
return json.dumps(result, indent=4, ensure_ascii=False)
|
53 |
|
54 |
-
# ---
|
55 |
with gr.Blocks() as app:
|
56 |
with gr.Row():
|
57 |
-
start_date = Calendar(type="datetime", label="Date
|
58 |
-
end_date = Calendar(type="datetime", label="Date
|
59 |
|
60 |
-
calculate_btn = gr.Button("
|
61 |
-
json_output = gr.Textbox(label="
|
62 |
|
63 |
-
# ---
|
64 |
-
def perform_calculation(start_date, end_date):
|
65 |
-
logger.info(f"perform_calculation
|
66 |
results = perform_gematria_calculation_for_date_range(start_date, end_date)
|
67 |
json_result = generate_json_output(results, start_date, end_date)
|
68 |
return json_result
|
69 |
|
70 |
-
# ---
|
71 |
calculate_btn.click(
|
72 |
perform_calculation,
|
73 |
inputs=[start_date, end_date],
|
|
|
4 |
|
5 |
import gradio as gr
|
6 |
from gradio_calendar import Calendar
|
|
|
7 |
from gematria import calculate_gematria, strip_diacritics
|
8 |
from datetime import datetime, timedelta
|
9 |
import json
|
10 |
|
11 |
+
# --- Helper Functions ---
|
12 |
def calculate_gematria_sum(text):
|
13 |
if text:
|
14 |
text_gematria = calculate_gematria(strip_diacritics(text))
|
|
|
16 |
else:
|
17 |
return None
|
18 |
|
19 |
+
def date_to_words(date_string):
|
20 |
+
"""
|
21 |
+
Konvertiert ein Datum im Format YYYY-MM-DD in die englische Schreibweise.
|
22 |
+
|
23 |
+
Args:
|
24 |
+
date_string: Ein Datum im Format YYYY-MM-DD.
|
25 |
+
|
26 |
+
Returns:
|
27 |
+
Einen String mit der englischen Schreibweise des Datums.
|
28 |
+
"""
|
29 |
+
date_obj = datetime.strptime(date_string, "%Y-%m-%d")
|
30 |
+
return date_obj.strftime("%A")
|
31 |
+
|
32 |
def perform_gematria_calculation_for_date_range(start_date, end_date):
|
33 |
+
logger.info(f"Startdatum: {start_date}, Enddatum: {end_date}") # Debugging-Ausgabe
|
34 |
results = {}
|
35 |
delta = timedelta(days=1)
|
36 |
current_date = start_date
|
37 |
|
38 |
while current_date <= end_date:
|
39 |
+
# Datum in String umwandeln
|
40 |
+
date_string = current_date.strftime("%Y-%m-%d")
|
41 |
+
date_words = date_to_words(date_string)
|
42 |
+
logger.info(f"Datum: {current_date}, Tagesnamen: {date_words}") # Debugging-Ausgabe
|
43 |
gematria_sum = calculate_gematria_sum(date_words)
|
44 |
+
logger.info(f"Gematria-Summe: {gematria_sum}") # Debugging-Ausgabe
|
45 |
|
46 |
if gematria_sum not in results:
|
47 |
results[gematria_sum] = []
|
|
|
65 |
}
|
66 |
return json.dumps(result, indent=4, ensure_ascii=False)
|
67 |
|
68 |
+
# --- Main Gradio App ---
|
69 |
with gr.Blocks() as app:
|
70 |
with gr.Row():
|
71 |
+
start_date = Calendar(type="datetime", label="Start Date")
|
72 |
+
end_date = Calendar(type="datetime", label="End Date")
|
73 |
|
74 |
+
calculate_btn = gr.Button("Calculate Gematria for Date Range")
|
75 |
+
json_output = gr.Textbox(label="JSON Output")
|
76 |
|
77 |
+
# --- Event Handlers ---
|
78 |
+
def perform_calculation(start_date, end_date):
|
79 |
+
logger.info(f"perform_calculation aufgerufen mit: start_date={start_date}, end_date={end_date}")
|
80 |
results = perform_gematria_calculation_for_date_range(start_date, end_date)
|
81 |
json_result = generate_json_output(results, start_date, end_date)
|
82 |
return json_result
|
83 |
|
84 |
+
# --- Event Triggers ---
|
85 |
calculate_btn.click(
|
86 |
perform_calculation,
|
87 |
inputs=[start_date, end_date],
|