bartman081523 commited on
Commit
bcf7e9f
·
1 Parent(s): 612ea81
Files changed (3) hide show
  1. app.py +7 -5
  2. date_ordinal.py +31 -33
  3. torah.py +8 -4
app.py CHANGED
@@ -1,18 +1,20 @@
 
 
 
 
1
  import gradio as gr
2
  import torah
 
3
  from gematria import calculate_gematria, strip_diacritics
 
4
  import pandas as pd
5
  from deep_translator import GoogleTranslator
6
  from gradio_calendar import Calendar
7
- from date_ordinal import number_to_ordinal_word, date_to_words
8
  import inflect
9
  from datetime import datetime
10
- import logging
11
  import math
12
  import json
13
 
14
- logger = logging.getLogger(__name__)
15
- logging.basicConfig(level=logging.INFO)
16
 
17
  # --- Helper Functions ---
18
 
@@ -22,7 +24,7 @@ def translate_date_to_words(date, lang='en'):
22
  return "No date selected"
23
  date_string = date.strftime("%Y-%m-%d")
24
  logger.info(f"Date string: {date_string}")
25
- date_in_words = date_to_words(date_string)
26
  logger.info(f"Date in words: {date_in_words}")
27
  translator = GoogleTranslator(source='auto', target=lang)
28
  translated_date_words = translator.translate(date_in_words)
 
1
+ import logging
2
+ logger = logging.getLogger(__name__)
3
+ logging.basicConfig(level=logging.INFO)
4
+
5
  import gradio as gr
6
  import torah
7
+ import date_ordinal
8
  from gematria import calculate_gematria, strip_diacritics
9
+
10
  import pandas as pd
11
  from deep_translator import GoogleTranslator
12
  from gradio_calendar import Calendar
 
13
  import inflect
14
  from datetime import datetime
 
15
  import math
16
  import json
17
 
 
 
18
 
19
  # --- Helper Functions ---
20
 
 
24
  return "No date selected"
25
  date_string = date.strftime("%Y-%m-%d")
26
  logger.info(f"Date string: {date_string}")
27
+ date_in_words = date_ordinal.date_to_words(date_string)
28
  logger.info(f"Date in words: {date_in_words}")
29
  translator = GoogleTranslator(source='auto', target=lang)
30
  translated_date_words = translator.translate(date_in_words)
date_ordinal.py CHANGED
@@ -1,41 +1,39 @@
1
  import inflect
2
  from datetime import datetime
3
 
4
-
5
-
6
  # Custom function to convert number to ordinal words
7
  def number_to_ordinal_word(number):
8
- ordinal_dict = {
9
- 1: "first", 2: "second", 3: "third", 4: "fourth", 5: "fifth",
10
- 6: "sixth", 7: "seventh", 8: "eighth", 9: "ninth", 10: "tenth",
11
- 11: "eleventh", 12: "twelfth", 13: "thirteenth", 14: "fourteenth",
12
- 15: "fifteenth", 16: "sixteenth", 17: "seventeenth", 18: "eighteenth",
13
- 19: "nineteenth", 20: "twentieth", 21: "twentyfirst", 22: "twentysecond",
14
- 23: "twentythird", 24: "twentyfourth", 25: "twentyfifth",
15
- 26: "twentysixth", 27: "twentyseventh", 28: "twentyeighth",
16
- 29: "twentyninth", 30: "thirtieth", 31: "thirtyfirst"
17
- }
18
- return ordinal_dict.get(number, "")
19
 
20
  # Convert a numerical date to words with an ordinal day
21
  def date_to_words(date_string):
22
-
23
- # Create an inflect engine
24
- inf_engine = inflect.engine()
25
-
26
- date_obj = datetime.strptime(date_string, "%Y-%m-%d")
27
-
28
- # Get year in the desired format
29
- year_words = inf_engine.number_to_words(date_obj.year, andword='')
30
- year_formatted = year_words.replace(',', '') # Remove commas
31
-
32
- month = date_obj.strftime("%B") # Full month name
33
- day = date_obj.day
34
- day_ordinal = number_to_ordinal_word(day) # Get ordinal word for the day
35
-
36
- return f"{day_ordinal} {month} {year_formatted}"
37
-
38
- # Example usage:
39
- #date_string = "2024-05-10"
40
- #date_in_words = date_to_words(date_string)
41
- #print(date_in_words) # Outputs: "tenth May two thousand twenty-four"
 
1
  import inflect
2
  from datetime import datetime
3
 
 
 
4
  # Custom function to convert number to ordinal words
5
  def number_to_ordinal_word(number):
6
+ ordinal_dict = {
7
+ 1: "first", 2: "second", 3: "third", 4: "fourth", 5: "fifth",
8
+ 6: "sixth", 7: "seventh", 8: "eighth", 9: "ninth", 10: "tenth",
9
+ 11: "eleventh", 12: "twelfth", 13: "thirteenth", 14: "fourteenth",
10
+ 15: "fifteenth", 16: "sixteenth", 17: "seventeenth", 18: "eighteenth",
11
+ 19: "nineteenth", 20: "twentieth", 21: "twentyfirst", 22: "twentysecond",
12
+ 23: "twentythird", 24: "twentyfourth", 25: "twentyfifth",
13
+ 26: "twentysixth", 27: "twentyseventh", 28: "twentyeighth",
14
+ 29: "twentyninth", 30: "thirtieth", 31: "thirtyfirst"
15
+ }
16
+ return ordinal_dict.get(number, "")
17
 
18
  # Convert a numerical date to words with an ordinal day
19
  def date_to_words(date_string):
20
+ # Create an inflect engine
21
+ inf_engine = inflect.engine()
22
+
23
+ date_obj = datetime.strptime(date_string, "%Y-%m-%d")
24
+
25
+ # Get year in the desired format
26
+ year = date_obj.year
27
+ if 1900 <= year <= 1999:
28
+ year_words = f"{inf_engine.number_to_words(year // 100, andword='') } hundred"
29
+ if year % 100 != 0:
30
+ year_words += f" {inf_engine.number_to_words(year % 100, andword='')}"
31
+ else:
32
+ year_words = inf_engine.number_to_words(year, andword='')
33
+ year_formatted = year_words.replace(',', '') # Remove commas
34
+
35
+ month = date_obj.strftime("%B") # Full month name
36
+ day = date_obj.day
37
+ day_ordinal = number_to_ordinal_word(day) # Get ordinal word for the day
38
+
39
+ return f"{day_ordinal} {month} {year_formatted}"
torah.py CHANGED
@@ -1,3 +1,7 @@
 
 
 
 
1
  import json
2
  import os
3
  import re
@@ -85,16 +89,16 @@ all_tests_passed = True
85
  for result, expected in test_results:
86
  if expected is None: # Prüfe, ob kein Ergebnis erwartet wird
87
  if not result:
88
- print(f"Test passed: Expected no results, got no results.")
89
  else:
90
- print(f"Test failed: Expected no results, but got: {result}")
91
  all_tests_passed = False
92
  else:
93
  els_result_text = result[0]['els_result_text']
94
  if els_result_text == expected:
95
- print(f"Test passed: Expected '{expected}', got '{els_result_text}'")
96
  else:
97
- print(f"Test failed: Expected '{expected}', but got '{els_result_text}'")
98
  all_tests_passed = False
99
 
100
  if all_tests_passed:
 
1
+ import logging
2
+ logger = logging.getLogger(__name__)
3
+ logging.basicConfig(level=logging.INFO)
4
+
5
  import json
6
  import os
7
  import re
 
89
  for result, expected in test_results:
90
  if expected is None: # Prüfe, ob kein Ergebnis erwartet wird
91
  if not result:
92
+ logger.info(f"Test passed: Expected no results, got no results.")
93
  else:
94
+ logger.info(f"Test failed: Expected no results, but got: {result}")
95
  all_tests_passed = False
96
  else:
97
  els_result_text = result[0]['els_result_text']
98
  if els_result_text == expected:
99
+ logger.info(f"Test passed: Expected '{expected}', got '{els_result_text}'")
100
  else:
101
+ logger.info(f"Test failed: Expected '{expected}', but got '{els_result_text}'")
102
  all_tests_passed = False
103
 
104
  if all_tests_passed: