Spaces:
Sleeping
Sleeping
Commit
·
702dd9c
1
Parent(s):
f794015
beautify results
Browse files- app.py +66 -16
- gematria.db +3 -0
app.py
CHANGED
|
@@ -134,16 +134,22 @@ def get_translation(phrase):
|
|
| 134 |
|
| 135 |
|
| 136 |
def translate_and_store(phrase):
|
| 137 |
-
"""Translates a phrase using Google Translate."""
|
| 138 |
global translator
|
| 139 |
-
|
| 140 |
-
|
| 141 |
-
|
| 142 |
-
|
| 143 |
-
|
| 144 |
-
|
| 145 |
-
|
| 146 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 147 |
|
| 148 |
def search_gematria_in_db(gematria_sum):
|
| 149 |
"""Searches the database for phrases with a given Gematria value."""
|
|
@@ -175,15 +181,59 @@ def gematria_search_interface(phrase):
|
|
| 175 |
|
| 176 |
# Format results for display
|
| 177 |
results = []
|
| 178 |
-
|
| 179 |
-
|
| 180 |
-
|
| 181 |
-
|
| 182 |
-
|
| 183 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 184 |
|
| 185 |
conn.close()
|
| 186 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 187 |
|
| 188 |
def run_app():
|
| 189 |
"""Initializes and launches the Gradio app."""
|
|
|
|
| 134 |
|
| 135 |
|
| 136 |
def translate_and_store(phrase):
|
|
|
|
| 137 |
global translator
|
| 138 |
+
max_retries = 3 # You can adjust the number of retries
|
| 139 |
+
retries = 0
|
| 140 |
+
|
| 141 |
+
while retries < max_retries:
|
| 142 |
+
try:
|
| 143 |
+
translation = translator.translate(phrase)
|
| 144 |
+
logging.debug(f"Translated phrase: {translation}")
|
| 145 |
+
return translation
|
| 146 |
+
except (exceptions.TranslationNotFound, exceptions.NotValidPayload,
|
| 147 |
+
exceptions.ServerException, exceptions.RequestError, requests.exceptions.ConnectionError) as e: # Add ConnectionError
|
| 148 |
+
retries += 1
|
| 149 |
+
logging.warning(f"Error translating phrase '{phrase}': {e}. Retrying... ({retries}/{max_retries})")
|
| 150 |
+
|
| 151 |
+
logging.error(f"Failed to translate phrase '{phrase}' after {max_retries} retries.")
|
| 152 |
+
return "[Translation Error]"
|
| 153 |
|
| 154 |
def search_gematria_in_db(gematria_sum):
|
| 155 |
"""Searches the database for phrases with a given Gematria value."""
|
|
|
|
| 181 |
|
| 182 |
# Format results for display
|
| 183 |
results = []
|
| 184 |
+
if not matching_phrases:
|
| 185 |
+
return "No matching phrases found."
|
| 186 |
+
else:
|
| 187 |
+
results.append("<div class='results-container'>")
|
| 188 |
+
for words, book, chapter, verse in matching_phrases:
|
| 189 |
+
translation = get_translation(words)
|
| 190 |
+
book_name_english = book_names.get(book, 'Unknown') # Get book name
|
| 191 |
+
link = f"https://www.biblegateway.com/passage/?search={quote_plus(book_name_english)}+{chapter}%3A{verse}"
|
| 192 |
+
|
| 193 |
+
results.append(f"""
|
| 194 |
+
<div class='result-item'>
|
| 195 |
+
<h3>Book: {book_name_english}</h3>
|
| 196 |
+
<p>Chapter: {chapter}, Verse: {verse}</p>
|
| 197 |
+
<p class='hebrew-phrase'>Hebrew Phrase: {words}</p>
|
| 198 |
+
<p>Translation: {translation}</p>
|
| 199 |
+
<a href='{link}' target='_blank' class='bible-link'>[See on Bible Gateway]</a>
|
| 200 |
+
</div>
|
| 201 |
+
""")
|
| 202 |
+
results.append("</div>") # Close results-container div
|
| 203 |
|
| 204 |
conn.close()
|
| 205 |
+
|
| 206 |
+
# Add CSS styling (within a <style> tag)
|
| 207 |
+
style = """
|
| 208 |
+
<style>
|
| 209 |
+
.results-container {
|
| 210 |
+
display: grid;
|
| 211 |
+
grid-template-columns: repeat(auto-fit, minmax(300px, 1fr)); /* Responsive columns */
|
| 212 |
+
gap: 20px;
|
| 213 |
+
}
|
| 214 |
+
|
| 215 |
+
.result-item {
|
| 216 |
+
border: 1px solid #ccc;
|
| 217 |
+
padding: 15px;
|
| 218 |
+
border-radius: 5px;
|
| 219 |
+
box-shadow: 2px 2px 5px rgba(0, 0, 0, 0.1);
|
| 220 |
+
}
|
| 221 |
+
|
| 222 |
+
.hebrew-phrase {
|
| 223 |
+
font-family: 'SBL Hebrew', 'Ezra SIL', serif; /* Use Hebrew fonts */
|
| 224 |
+
direction: rtl; /* Right-to-left text direction */
|
| 225 |
+
}
|
| 226 |
+
|
| 227 |
+
.bible-link {
|
| 228 |
+
display: block;
|
| 229 |
+
margin-top: 10px;
|
| 230 |
+
color: #007bff; /* Blue link color */
|
| 231 |
+
text-decoration: none;
|
| 232 |
+
}
|
| 233 |
+
</style>
|
| 234 |
+
"""
|
| 235 |
+
|
| 236 |
+
return style + "\n".join(results) # Concatenate style and results
|
| 237 |
|
| 238 |
def run_app():
|
| 239 |
"""Initializes and launches the Gradio app."""
|
gematria.db
CHANGED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:c3c0f9e104950f5bcd97285d6114c6b6a398b4fff2137317cff2d9584d4206fb
|
| 3 |
+
size 11456512
|