Spaces:
Running
Running
Upload folder using huggingface_hub
Browse files
app.py
CHANGED
|
@@ -52,31 +52,6 @@ def get_all_languages():
|
|
| 52 |
return sorted(set(languages)) # remove duplicates and sort alphabetically
|
| 53 |
|
| 54 |
|
| 55 |
-
def init():
|
| 56 |
-
load_dotenv(override=True)
|
| 57 |
-
try:
|
| 58 |
-
SanatanDatabase().test_sanity()
|
| 59 |
-
except Exception as e:
|
| 60 |
-
logger.warning("Sanity Test Failed - %s", e)
|
| 61 |
-
logger.info("Downloading database ...")
|
| 62 |
-
downloader = ZipDownloader(
|
| 63 |
-
service_account_json=os.getenv("GOOGLE_SERVICE_ACCOUNT_JSON")
|
| 64 |
-
)
|
| 65 |
-
zip_path = downloader.download_zip_from_drive(
|
| 66 |
-
file_id=os.getenv("CHROMADB_FILE_ID"),
|
| 67 |
-
output_path=SanatanConfig.dbStorePath,
|
| 68 |
-
)
|
| 69 |
-
downloader.unzip(zip_path, extract_to="./")
|
| 70 |
-
|
| 71 |
-
# add global index
|
| 72 |
-
# delete taniyan records
|
| 73 |
-
SanatanDatabase().delete_taniyans_in_divya_prabandham()
|
| 74 |
-
SanatanDatabase().build_global_index_for_all_scriptures()
|
| 75 |
-
# Launch the whole thing in a background thread
|
| 76 |
-
yt_init_thread = threading.Thread(target=initialize_youtube_metadata_and_poll, daemon=True)
|
| 77 |
-
yt_init_thread.start()
|
| 78 |
-
|
| 79 |
-
|
| 80 |
def render_message_with_tooltip(content: str, max_chars=200):
|
| 81 |
short = escape(content[:max_chars]) + ("…" if len(content) > max_chars else "")
|
| 82 |
return f"<div title='{escape(content)}'>{short}</div>"
|
|
@@ -93,8 +68,6 @@ supported_scriptures = "\n - ".join(
|
|
| 93 |
]
|
| 94 |
)
|
| 95 |
|
| 96 |
-
init()
|
| 97 |
-
|
| 98 |
message_textbox = gr.Textbox(
|
| 99 |
placeholder="Search the scriptures ...", submit_btn=True, stop_btn=True
|
| 100 |
)
|
|
|
|
| 52 |
return sorted(set(languages)) # remove duplicates and sort alphabetically
|
| 53 |
|
| 54 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 55 |
def render_message_with_tooltip(content: str, max_chars=200):
|
| 56 |
short = escape(content[:max_chars]) + ("…" if len(content) > max_chars else "")
|
| 57 |
return f"<div title='{escape(content)}'>{short}</div>"
|
|
|
|
| 68 |
]
|
| 69 |
)
|
| 70 |
|
|
|
|
|
|
|
| 71 |
message_textbox = gr.Textbox(
|
| 72 |
placeholder="Search the scriptures ...", submit_btn=True, stop_btn=True
|
| 73 |
)
|
main.py
CHANGED
|
@@ -1,12 +1,18 @@
|
|
| 1 |
import asyncio
|
| 2 |
from contextlib import asynccontextmanager
|
|
|
|
|
|
|
|
|
|
| 3 |
from fastapi.responses import RedirectResponse
|
|
|
|
|
|
|
|
|
|
| 4 |
from modules.firebase.listener import start_firestore_listener
|
| 5 |
import uvicorn
|
| 6 |
from fastapi import FastAPI
|
| 7 |
from modules.dropbox.audio import cleanup_audio_url_cache
|
| 8 |
# from modules.home.app import home_app
|
| 9 |
-
from modules.youtube_metadata.app import youtube_metadata_app
|
| 10 |
from server import router as mobile_router
|
| 11 |
# from app import gradio_app # your Blocks object
|
| 12 |
import gradio as gr
|
|
@@ -20,6 +26,35 @@ from slowapi.errors import RateLimitExceeded
|
|
| 20 |
from contextlib import asynccontextmanager
|
| 21 |
|
| 22 |
logging.basicConfig(level=logging.INFO)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 23 |
|
| 24 |
@asynccontextmanager
|
| 25 |
async def fn_lifespan(app: FastAPI):
|
|
@@ -28,6 +63,10 @@ async def fn_lifespan(app: FastAPI):
|
|
| 28 |
yield
|
| 29 |
logging.info("🛑 Firestore listener shutdown (no explicit cleanup needed).")
|
| 30 |
|
|
|
|
|
|
|
|
|
|
|
|
|
| 31 |
app = FastAPI(title="Sanatan AI Unified Server",lifespan=fn_lifespan)
|
| 32 |
limiter = Limiter(key_func=get_remote_address)
|
| 33 |
app.state.limiter = limiter
|
|
|
|
| 1 |
import asyncio
|
| 2 |
from contextlib import asynccontextmanager
|
| 3 |
+
import os
|
| 4 |
+
import threading
|
| 5 |
+
from dotenv import load_dotenv
|
| 6 |
from fastapi.responses import RedirectResponse
|
| 7 |
+
from config import SanatanConfig
|
| 8 |
+
from db import SanatanDatabase
|
| 9 |
+
from drive_downloader import ZipDownloader
|
| 10 |
from modules.firebase.listener import start_firestore_listener
|
| 11 |
import uvicorn
|
| 12 |
from fastapi import FastAPI
|
| 13 |
from modules.dropbox.audio import cleanup_audio_url_cache
|
| 14 |
# from modules.home.app import home_app
|
| 15 |
+
from modules.youtube_metadata.app import initialize_youtube_metadata_and_poll, youtube_metadata_app
|
| 16 |
from server import router as mobile_router
|
| 17 |
# from app import gradio_app # your Blocks object
|
| 18 |
import gradio as gr
|
|
|
|
| 26 |
from contextlib import asynccontextmanager
|
| 27 |
|
| 28 |
logging.basicConfig(level=logging.INFO)
|
| 29 |
+
logger = logging.getLogger()
|
| 30 |
+
|
| 31 |
+
logger.setLevel(logging.INFO)
|
| 32 |
+
|
| 33 |
+
|
| 34 |
+
def init():
|
| 35 |
+
load_dotenv(override=True)
|
| 36 |
+
try:
|
| 37 |
+
SanatanDatabase().test_sanity()
|
| 38 |
+
except Exception as e:
|
| 39 |
+
logger.warning("Sanity Test Failed - %s", e)
|
| 40 |
+
logger.info("Downloading database ...")
|
| 41 |
+
downloader = ZipDownloader(
|
| 42 |
+
service_account_json=os.getenv("GOOGLE_SERVICE_ACCOUNT_JSON")
|
| 43 |
+
)
|
| 44 |
+
zip_path = downloader.download_zip_from_drive(
|
| 45 |
+
file_id=os.getenv("CHROMADB_FILE_ID"),
|
| 46 |
+
output_path=SanatanConfig.dbStorePath,
|
| 47 |
+
)
|
| 48 |
+
downloader.unzip(zip_path, extract_to="./")
|
| 49 |
+
|
| 50 |
+
# add global index
|
| 51 |
+
# delete taniyan records
|
| 52 |
+
SanatanDatabase().delete_taniyans_in_divya_prabandham()
|
| 53 |
+
SanatanDatabase().build_global_index_for_all_scriptures()
|
| 54 |
+
# Launch the whole thing in a background thread
|
| 55 |
+
yt_init_thread = threading.Thread(target=initialize_youtube_metadata_and_poll, daemon=True)
|
| 56 |
+
yt_init_thread.start()
|
| 57 |
+
|
| 58 |
|
| 59 |
@asynccontextmanager
|
| 60 |
async def fn_lifespan(app: FastAPI):
|
|
|
|
| 63 |
yield
|
| 64 |
logging.info("🛑 Firestore listener shutdown (no explicit cleanup needed).")
|
| 65 |
|
| 66 |
+
###### Initialize the database ######
|
| 67 |
+
init()
|
| 68 |
+
###### Initialize the database ######
|
| 69 |
+
|
| 70 |
app = FastAPI(title="Sanatan AI Unified Server",lifespan=fn_lifespan)
|
| 71 |
limiter = Limiter(key_func=get_remote_address)
|
| 72 |
app.state.limiter = limiter
|