Spaces:
Runtime error
Runtime error
Deploy Vivekananda scriptures semantic search Gradio app
Browse files
app.py
CHANGED
|
@@ -2,6 +2,9 @@ import os
|
|
| 2 |
import json
|
| 3 |
import gradio as gr
|
| 4 |
import lancedb
|
|
|
|
|
|
|
|
|
|
| 5 |
from huggingface_hub import snapshot_download
|
| 6 |
from sentence_transformers import SentenceTransformer
|
| 7 |
|
|
@@ -31,17 +34,6 @@ print("Model loaded successfully.")
|
|
| 31 |
|
| 32 |
# Custom CSS for gorgeous aesthetics (dark mode, glassmorphism, responsive grid)
|
| 33 |
custom_css = """
|
| 34 |
-
body {
|
| 35 |
-
background-color: #0d0f12 !important;
|
| 36 |
-
color: #e2e8f0 !important;
|
| 37 |
-
font-family: 'Inter', sans-serif !important;
|
| 38 |
-
}
|
| 39 |
-
.gradio-container {
|
| 40 |
-
max-width: 1100px !important;
|
| 41 |
-
margin: 0 auto !important;
|
| 42 |
-
padding: 20px !important;
|
| 43 |
-
background-color: #0d0f12 !important;
|
| 44 |
-
}
|
| 45 |
.header-box {
|
| 46 |
text-align: center;
|
| 47 |
padding: 30px 20px;
|
|
@@ -230,17 +222,9 @@ def semantic_search(query: str, limit: int = 5, min_similarity: float = 0.5) ->
|
|
| 230 |
</div>
|
| 231 |
"""
|
| 232 |
|
| 233 |
-
# Format
|
| 234 |
-
|
| 235 |
-
|
| 236 |
-
# Clean out prepended shloka
|
| 237 |
-
parts = text_to_print.split("Commentary")
|
| 238 |
-
if len(parts) > 1:
|
| 239 |
-
text_to_print = "Commentary" + " ".join(parts[1:])
|
| 240 |
-
|
| 241 |
-
text_formatted = text_to_print.strip().replace("\n", "<br>")
|
| 242 |
-
|
| 243 |
-
comm_title = f"Commentary ({commentary_author})" if commentary_author else "Scripture Text"
|
| 244 |
|
| 245 |
html_output += f"""
|
| 246 |
<div class="result-card">
|
|
@@ -269,8 +253,8 @@ def semantic_search(query: str, limit: int = 5, min_similarity: float = 0.5) ->
|
|
| 269 |
except Exception as e:
|
| 270 |
return f"<div style='text-align: center; color: #ff6b6b; padding: 20px;'>Error during search: {e}</div>"
|
| 271 |
|
| 272 |
-
# 3. Create Gradio Interface Block
|
| 273 |
-
with gr.Blocks(css=custom_css, title="Vivekananda Scriptures Semantic Search") as demo:
|
| 274 |
# Header block
|
| 275 |
gr.HTML("""
|
| 276 |
<div class="header-box">
|
|
|
|
| 2 |
import json
|
| 3 |
import gradio as gr
|
| 4 |
import lancedb
|
| 5 |
+
import torch
|
| 6 |
+
# Limit PyTorch CPU threads to 1 to prevent system freezing
|
| 7 |
+
torch.set_num_threads(1)
|
| 8 |
from huggingface_hub import snapshot_download
|
| 9 |
from sentence_transformers import SentenceTransformer
|
| 10 |
|
|
|
|
| 34 |
|
| 35 |
# Custom CSS for gorgeous aesthetics (dark mode, glassmorphism, responsive grid)
|
| 36 |
custom_css = """
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 37 |
.header-box {
|
| 38 |
text-align: center;
|
| 39 |
padding: 30px 20px;
|
|
|
|
| 222 |
</div>
|
| 223 |
"""
|
| 224 |
|
| 225 |
+
# Format raw text chunk exactly as stored in database
|
| 226 |
+
text_formatted = raw_text.strip().replace("\n", "<br>")
|
| 227 |
+
comm_title = "Full Scripture & Commentary Chunk"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 228 |
|
| 229 |
html_output += f"""
|
| 230 |
<div class="result-card">
|
|
|
|
| 253 |
except Exception as e:
|
| 254 |
return f"<div style='text-align: center; color: #ff6b6b; padding: 20px;'>Error during search: {e}</div>"
|
| 255 |
|
| 256 |
+
# 3. Create Gradio Interface Block with stunning native dark theme
|
| 257 |
+
with gr.Blocks(theme=gr.themes.Default(primary_hue="amber", secondary_hue="orange", neutral_hue="slate", dark_mode=True), css=custom_css, title="Vivekananda Scriptures Semantic Search") as demo:
|
| 258 |
# Header block
|
| 259 |
gr.HTML("""
|
| 260 |
<div class="header-box">
|