Spaces:
				
			
			
	
			
			
		Sleeping
		
	
	
	
			
			
	
	
	
	
		
		
		Sleeping
		
	
		bartman081523
		
	commited on
		
		
					Commit 
							
							·
						
						14f19e7
	
1
								Parent(s):
							
							115ce47
								
populate db
Browse files- app.py +13 -9
- gematria.db-journal +2 -2
    	
        app.py
    CHANGED
    
    | @@ -156,18 +156,18 @@ def translate_and_store(phrase): | |
| 156 | 
             
                logging.error(f"Failed to translate phrase '{phrase}' after {max_retries} retries.")
         | 
| 157 | 
             
                return "[Translation Error]"
         | 
| 158 |  | 
| 159 | 
            -
            def search_gematria_in_db(gematria_sum):
         | 
| 160 | 
            -
                """Searches the database for phrases with a given Gematria value."""
         | 
| 161 | 
             
                global conn
         | 
| 162 | 
             
                cursor = conn.cursor()
         | 
| 163 | 
             
                cursor.execute('''
         | 
| 164 | 
            -
                SELECT words, book, chapter, verse FROM results WHERE gematria_sum = ?
         | 
| 165 | 
            -
                ''', (gematria_sum,))
         | 
| 166 | 
             
                results = cursor.fetchall()
         | 
| 167 | 
             
                logging.debug(f"Found {len(results)} matching phrases for Gematria: {gematria_sum}")
         | 
| 168 | 
             
                return results
         | 
| 169 |  | 
| 170 | 
            -
            def gematria_search_interface(phrase):
         | 
| 171 | 
             
                """The main function for the Gradio interface."""
         | 
| 172 | 
             
                if not phrase.strip():
         | 
| 173 | 
             
                    return "Please enter a phrase."
         | 
| @@ -184,7 +184,7 @@ def gematria_search_interface(phrase): | |
| 184 | 
             
                    matching_phrases = gematria_cache[phrase_gematria]
         | 
| 185 | 
             
                else:
         | 
| 186 | 
             
                    # Search in the database
         | 
| 187 | 
            -
                    matching_phrases = search_gematria_in_db(phrase_gematria)
         | 
| 188 | 
             
                    # Cache the results for future searches
         | 
| 189 | 
             
                    gematria_cache[phrase_gematria] = matching_phrases
         | 
| 190 |  | 
| @@ -205,7 +205,7 @@ def gematria_search_interface(phrase): | |
| 205 | 
             
                for book, phrases in results_by_book.items():
         | 
| 206 | 
             
                    results.append(f"<h4>Book: {book}</h4>")  # Directly display book name
         | 
| 207 | 
             
                    for words, chapter, verse in phrases:
         | 
| 208 | 
            -
                        translation = get_translation(words)
         | 
| 209 | 
             
                        link = f"https://www.biblegateway.com/passage/?search={quote_plus(book)}+{chapter}%3A{verse}&version=CJB"
         | 
| 210 | 
             
                        results.append(f"""
         | 
| 211 | 
             
                        <div class='result-item'>
         | 
| @@ -265,7 +265,7 @@ def run_app(): | |
| 265 | 
             
                # Pre-populate the database
         | 
| 266 | 
             
                logging.info("Starting database population...")
         | 
| 267 | 
             
                phrases_to_insert = []  # Collect phrases before inserting in bulk
         | 
| 268 | 
            -
                for gematria_sum, phrase, book, chapter, verse in tqdm(populate_database(1, 39, max_phrase_length= | 
| 269 | 
             
                    phrases_to_insert.append((gematria_sum, phrase, book, chapter, verse))
         | 
| 270 | 
             
                    if len(phrases_to_insert) >= 1000:  # Insert in batches of 1000 for efficiency
         | 
| 271 | 
             
                        insert_phrases_to_db(phrases_to_insert)
         | 
| @@ -276,7 +276,11 @@ def run_app(): | |
| 276 |  | 
| 277 | 
             
                iface = gr.Interface(
         | 
| 278 | 
             
                    fn=gematria_search_interface,
         | 
| 279 | 
            -
                    inputs= | 
|  | |
|  | |
|  | |
|  | |
| 280 | 
             
                    outputs=gr.HTML(label="Results"),
         | 
| 281 | 
             
                    title="Gematria Search in Tanach",
         | 
| 282 | 
             
                    description="Search for phrases in the Tanach that have the same Gematria value.",
         | 
|  | |
| 156 | 
             
                logging.error(f"Failed to translate phrase '{phrase}' after {max_retries} retries.")
         | 
| 157 | 
             
                return "[Translation Error]"
         | 
| 158 |  | 
| 159 | 
            +
            def search_gematria_in_db(gematria_sum, max_words):
         | 
| 160 | 
            +
                """Searches the database for phrases with a given Gematria value and word count."""
         | 
| 161 | 
             
                global conn
         | 
| 162 | 
             
                cursor = conn.cursor()
         | 
| 163 | 
             
                cursor.execute('''
         | 
| 164 | 
            +
                SELECT words, book, chapter, verse FROM results WHERE gematria_sum = ? AND words LIKE '% %'
         | 
| 165 | 
            +
                ''', (gematria_sum,))  # Add condition for phrases with at least 2 words
         | 
| 166 | 
             
                results = cursor.fetchall()
         | 
| 167 | 
             
                logging.debug(f"Found {len(results)} matching phrases for Gematria: {gematria_sum}")
         | 
| 168 | 
             
                return results
         | 
| 169 |  | 
| 170 | 
            +
            def gematria_search_interface(phrase, max_words, show_translation):
         | 
| 171 | 
             
                """The main function for the Gradio interface."""
         | 
| 172 | 
             
                if not phrase.strip():
         | 
| 173 | 
             
                    return "Please enter a phrase."
         | 
|  | |
| 184 | 
             
                    matching_phrases = gematria_cache[phrase_gematria]
         | 
| 185 | 
             
                else:
         | 
| 186 | 
             
                    # Search in the database
         | 
| 187 | 
            +
                    matching_phrases = search_gematria_in_db(phrase_gematria, max_words)
         | 
| 188 | 
             
                    # Cache the results for future searches
         | 
| 189 | 
             
                    gematria_cache[phrase_gematria] = matching_phrases
         | 
| 190 |  | 
|  | |
| 205 | 
             
                for book, phrases in results_by_book.items():
         | 
| 206 | 
             
                    results.append(f"<h4>Book: {book}</h4>")  # Directly display book name
         | 
| 207 | 
             
                    for words, chapter, verse in phrases:
         | 
| 208 | 
            +
                        translation = get_translation(words) if show_translation else ""
         | 
| 209 | 
             
                        link = f"https://www.biblegateway.com/passage/?search={quote_plus(book)}+{chapter}%3A{verse}&version=CJB"
         | 
| 210 | 
             
                        results.append(f"""
         | 
| 211 | 
             
                        <div class='result-item'>
         | 
|  | |
| 265 | 
             
                # Pre-populate the database
         | 
| 266 | 
             
                logging.info("Starting database population...")
         | 
| 267 | 
             
                phrases_to_insert = []  # Collect phrases before inserting in bulk
         | 
| 268 | 
            +
                for gematria_sum, phrase, book, chapter, verse in tqdm(populate_database(1, 39, max_phrase_length=3), desc="Populating Database"):  # Books 1 to 39
         | 
| 269 | 
             
                    phrases_to_insert.append((gematria_sum, phrase, book, chapter, verse))
         | 
| 270 | 
             
                    if len(phrases_to_insert) >= 1000:  # Insert in batches of 1000 for efficiency
         | 
| 271 | 
             
                        insert_phrases_to_db(phrases_to_insert)
         | 
|  | |
| 276 |  | 
| 277 | 
             
                iface = gr.Interface(
         | 
| 278 | 
             
                    fn=gematria_search_interface,
         | 
| 279 | 
            +
                    inputs=[
         | 
| 280 | 
            +
                        gr.Textbox(label="Enter phrase"),
         | 
| 281 | 
            +
                        gr.Number(label="Max Word Count", value=2, minimum=1, maximum=10),
         | 
| 282 | 
            +
                        gr.Checkbox(label="Show Translation", value=True)
         | 
| 283 | 
            +
                    ],
         | 
| 284 | 
             
                    outputs=gr.HTML(label="Results"),
         | 
| 285 | 
             
                    title="Gematria Search in Tanach",
         | 
| 286 | 
             
                    description="Search for phrases in the Tanach that have the same Gematria value.",
         | 
    	
        gematria.db-journal
    CHANGED
    
    | @@ -1,3 +1,3 @@ | |
| 1 | 
             
            version https://git-lfs.github.com/spec/v1
         | 
| 2 | 
            -
            oid sha256: | 
| 3 | 
            -
            size  | 
|  | |
| 1 | 
             
            version https://git-lfs.github.com/spec/v1
         | 
| 2 | 
            +
            oid sha256:df20400802de5bf6a4cb7e49dd564de73907a76b093ce7e9c523114544c2a325
         | 
| 3 | 
            +
            size 443744
         |