neuralworm commited on
Commit
f16f0ac
·
1 Parent(s): cd52d3a

english app

Browse files
Files changed (1) hide show
  1. app.py +23 -22
app.py CHANGED
@@ -10,7 +10,7 @@ from deep_translator import GoogleTranslator
10
  logging.basicConfig(level=logging.INFO, format='%(message)s')
11
 
12
  def flatten_text(text):
13
- """Hilfsfunktion, um verschachtelte Listen zu flachen Listen zu machen."""
14
  if isinstance(text, list):
15
  return " ".join(flatten_text(item) if isinstance(item, list) else item for item in text)
16
  return text
@@ -82,7 +82,7 @@ def translate_phrases(phrases):
82
  def db(tanach_texts, max_phrase_length=1):
83
  initialize_database()
84
  populate_database(tanach_texts, max_phrase_length)
85
- logging.info("Datenbank erfolgreich erstellt und gefüllt.")
86
 
87
  def gematria_search_interface(phrase):
88
  debug_output = []
@@ -92,24 +92,24 @@ def gematria_search_interface(phrase):
92
  logging.info(message)
93
 
94
  if not phrase.strip():
95
- return "Bitte geben Sie eine Phrase ein.", "\n".join(debug_output)
96
 
97
  phrase_gematria = calculate_gematria(phrase.replace(" ", ""))
98
- debug_callback(f"Debug: Gematria der Suchphrase '{phrase}' ist {phrase_gematria}")
99
 
100
  matching_phrases = search_gematria_in_db(phrase_gematria)
101
 
102
  if not matching_phrases:
103
- return "Keine passenden Phrasen gefunden.", "\n".join(debug_output)
104
 
105
  phrases = [match[0] for match in matching_phrases]
106
  translations = translate_phrases(phrases)
107
 
108
- result = "Passende Phrasen:\n"
109
  for match, translation in zip(matching_phrases, translations):
110
- result += f"Buch: {match[2]} ({match[3]})\nKapitel: {match[4]}, Vers: {match[5]}\nPhrase: {match[0]}\nÜbersetzung: {translation}\n\n"
111
 
112
- return result, "\n".join(debug_output)
113
 
114
  def run_test():
115
  debug_output = []
@@ -120,35 +120,36 @@ def run_test():
120
  debug_output.append(message)
121
  logging.info(message)
122
 
123
- # Lade die Test-JSON-Inhalte für 00.json
124
  test_texts_00 = process_json_files(0, 0)
125
  db(test_texts_00, max_phrase_length=22) # Populate the database with 1-word phrases
126
  matching_phrases_00 = search_gematria_in_db(expected_gematria)
127
- assert matching_phrases_00, "Keine passenden Phrasen gefunden in 00.json."
128
- assert matching_phrases_00[0][0].replace(" ", "") == test_phrase, f"Gefundene Phrase stimmt nicht überein: {matching_phrases_00[0][0]}"
129
- print("Test erfolgreich: Die Phrase wurde korrekt gefunden und die Gematria stimmt überein in 00.json.")
130
 
131
- # Lade die Test-JSON-Inhalte für 01.json
132
  test_texts_01 = process_json_files(1, 1)
133
  db(test_texts_01, max_phrase_length=2) # Populate the database with 1-word phrases
134
  search_phrase_01 = "אתקלך שמעתי"
135
  expected_gematria_01 = calculate_gematria(search_phrase_01.replace(" ", ""))
136
 
137
  matching_phrases_01 = search_gematria_in_db(expected_gematria_01)
138
- assert matching_phrases_01, "Keine passenden Phrasen gefunden in 01.json."
139
- assert matching_phrases_01[0][0].replace(" ", "") == search_phrase_01.replace(" ", ""), f"Gefundene Phrase stimmt nicht überein: {matching_phrases_01[0][0]}"
140
- print("Test erfolgreich: Die Phrase wurde korrekt gefunden und die Gematria stimmt überein in 01.json.")
141
  print("\n".join(debug_output))
142
 
143
  iface = gr.Interface(
144
  fn=gematria_search_interface,
145
- inputs="text",
146
- outputs=["text", "text"],
147
- title="Gematria-Suche im Tanach",
148
- description="Suche nach Phrasen im Tanach, die denselben Gematria-Wert haben wie die eingegebene Phrase.",
149
- live=True # Aktiviert das Live-Update
 
150
  )
151
 
152
  if __name__ == "__main__":
153
- run_test() # Test ausführen
154
  iface.launch()
 
10
  logging.basicConfig(level=logging.INFO, format='%(message)s')
11
 
12
  def flatten_text(text):
13
+ """Helper function to flatten nested lists into a single list."""
14
  if isinstance(text, list):
15
  return " ".join(flatten_text(item) if isinstance(item, list) else item for item in text)
16
  return text
 
82
  def db(tanach_texts, max_phrase_length=1):
83
  initialize_database()
84
  populate_database(tanach_texts, max_phrase_length)
85
+ logging.info("Database successfully created and populated.")
86
 
87
  def gematria_search_interface(phrase):
88
  debug_output = []
 
92
  logging.info(message)
93
 
94
  if not phrase.strip():
95
+ return "Please enter a phrase.", "\n".join(debug_output)
96
 
97
  phrase_gematria = calculate_gematria(phrase.replace(" ", ""))
98
+ debug_callback(f"Debug: Gematria of the search phrase '{phrase}' is {phrase_gematria}")
99
 
100
  matching_phrases = search_gematria_in_db(phrase_gematria)
101
 
102
  if not matching_phrases:
103
+ return "No matching phrases found.", "\n".join(debug_output)
104
 
105
  phrases = [match[0] for match in matching_phrases]
106
  translations = translate_phrases(phrases)
107
 
108
+ result = "Matching phrases:\n"
109
  for match, translation in zip(matching_phrases, translations):
110
+ result += f"Book: {match[2]} ({match[3]})\nChapter: {match[4]}, Verse: {match[5]}\nPhrase: {match[0]}\nTranslation: {translation}\n\n"
111
 
112
+ return result, "\n".join(debug_callback)
113
 
114
  def run_test():
115
  debug_output = []
 
120
  debug_output.append(message)
121
  logging.info(message)
122
 
123
+ # Load the test JSON contents for 00.json
124
  test_texts_00 = process_json_files(0, 0)
125
  db(test_texts_00, max_phrase_length=22) # Populate the database with 1-word phrases
126
  matching_phrases_00 = search_gematria_in_db(expected_gematria)
127
+ assert matching_phrases_00, "No matching phrases found in 00.json."
128
+ assert matching_phrases_00[0][0].replace(" ", "") == test_phrase, f"Found phrase does not match: {matching_phrases_00[0][0]}"
129
+ print("Test successful: The phrase was correctly found and the gematria matches in 00.json.")
130
 
131
+ # Load the test JSON contents for 01.json
132
  test_texts_01 = process_json_files(1, 1)
133
  db(test_texts_01, max_phrase_length=2) # Populate the database with 1-word phrases
134
  search_phrase_01 = "אתקלך שמעתי"
135
  expected_gematria_01 = calculate_gematria(search_phrase_01.replace(" ", ""))
136
 
137
  matching_phrases_01 = search_gematria_in_db(expected_gematria_01)
138
+ assert matching_phrases_01, "No matching phrases found in 01.json."
139
+ assert matching_phrases_01[0][0].replace(" ", "") == search_phrase_01.replace(" ", ""), f"Found phrase does not match: {matching_phrases_01[0][0]}"
140
+ print("Test successful: The phrase was correctly found and the gematria matches in 01.json.")
141
  print("\n".join(debug_output))
142
 
143
  iface = gr.Interface(
144
  fn=gematria_search_interface,
145
+ inputs=gr.inputs.Textbox(label="Enter phrase"),
146
+ outputs=[gr.outputs.Textbox(label="Results"), gr.outputs.Textbox(label="Debug Output")],
147
+ title="Gematria Search in Tanach",
148
+ description="Search for phrases in Tanach that have the same gematria value as the entered phrase.",
149
+ live=False, # Disable live update
150
+ allow_flagging=False, # Disable flagging for simplicity
151
  )
152
 
153
  if __name__ == "__main__":
154
+ run_test() # Run tests
155
  iface.launch()