Spaces:
Sleeping
Sleeping
Commit
·
78317d1
1
Parent(s):
0c9314d
initial commit
Browse files
app.py
CHANGED
@@ -4,12 +4,12 @@ logging.basicConfig(level=logging.INFO)
|
|
4 |
|
5 |
import gradio as gr
|
6 |
from gradio_calendar import Calendar
|
7 |
-
from utils import 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))
|
@@ -18,16 +18,16 @@ def calculate_gematria_sum(text):
|
|
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 |
date_words = date_to_words(current_date)
|
28 |
-
logger.info(f"
|
29 |
gematria_sum = calculate_gematria_sum(date_words)
|
30 |
-
logger.info(f"Gematria
|
31 |
|
32 |
if gematria_sum not in results:
|
33 |
results[gematria_sum] = []
|
@@ -51,23 +51,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="
|
58 |
-
end_date = Calendar(type="datetime", label="
|
59 |
|
60 |
-
calculate_btn = gr.Button("
|
61 |
-
json_output = gr.Textbox(label="JSON
|
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 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 |
+
# --- Fonctions auxiliaires ---
|
13 |
def calculate_gematria_sum(text):
|
14 |
if text:
|
15 |
text_gematria = calculate_gematria(strip_diacritics(text))
|
|
|
18 |
return None
|
19 |
|
20 |
def perform_gematria_calculation_for_date_range(start_date, end_date):
|
21 |
+
logger.info(f"Date de début : {start_date}, Date de fin : {end_date}") # Sortie de débogage
|
22 |
results = {}
|
23 |
delta = timedelta(days=1)
|
24 |
current_date = start_date
|
25 |
|
26 |
while current_date <= end_date:
|
27 |
date_words = date_to_words(current_date)
|
28 |
+
logger.info(f"Date : {current_date}, Noms de jours : {date_words}") # Sortie de débogage
|
29 |
gematria_sum = calculate_gematria_sum(date_words)
|
30 |
+
logger.info(f"Somme Gematria : {gematria_sum}") # Sortie de débogage
|
31 |
|
32 |
if gematria_sum not in results:
|
33 |
results[gematria_sum] = []
|
|
|
51 |
}
|
52 |
return json.dumps(result, indent=4, ensure_ascii=False)
|
53 |
|
54 |
+
# --- Application principale Gradio ---
|
55 |
with gr.Blocks() as app:
|
56 |
with gr.Row():
|
57 |
+
start_date = Calendar(type="datetime", label="Date de début") # Retour à "datetime"
|
58 |
+
end_date = Calendar(type="datetime", label="Date de fin") # Retour à "datetime"
|
59 |
|
60 |
+
calculate_btn = gr.Button("Calculer la Gematria pour la période")
|
61 |
+
json_output = gr.Textbox(label="Sortie JSON")
|
62 |
|
63 |
+
# --- Gestionnaires d'événements ---
|
64 |
+
def perform_calculation(start_date, end_date): # Recevoir les objets datetime
|
65 |
+
logger.info(f"perform_calculation appelé avec : start_date={start_date}, end_date={end_date}")
|
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 |
+
# --- Déclencheurs d'événements ---
|
71 |
calculate_btn.click(
|
72 |
perform_calculation,
|
73 |
inputs=[start_date, end_date],
|