vikramvasudevan commited on
Commit
2cfcf56
Β·
verified Β·
1 Parent(s): a9d9abb

Upload folder using huggingface_hub

Browse files
main.py CHANGED
@@ -20,9 +20,9 @@ app = FastAPI(title="Sanatan AI Unified Server")
20
  app.include_router(mobile_router, prefix="/api")
21
 
22
  # Convert Gradio Blocks to ASGI app
23
- app = gr.mount_gradio_app(app, gradio_app,"/sanatan_ai_web")
24
 
25
- app = gr.mount_gradio_app(app, youtube_metadata_app,"/yt_web")
26
 
27
  app = gr.mount_gradio_app(app, home_app,"/home")
28
 
 
20
  app.include_router(mobile_router, prefix="/api")
21
 
22
  # Convert Gradio Blocks to ASGI app
23
+ # app = gr.mount_gradio_app(app, gradio_app,"/sanatan_ai_web")
24
 
25
+ # app = gr.mount_gradio_app(app, youtube_metadata_app,"/yt_web")
26
 
27
  app = gr.mount_gradio_app(app, home_app,"/home")
28
 
modules/home/app.py CHANGED
@@ -1,7 +1,46 @@
 
1
  import gradio as gr
 
2
 
3
  with gr.Blocks(title="Sanatana AI - Home") as home_app:
4
- gr.Markdown("## Welcome to Sanatan AI!")
5
- with gr.Row():
6
- gr.Button("Go to Sanatan AI", link="/sanatan_ai_web", variant="primary") # link to /web
7
- gr.Button("Manage Youtube Metadata", link="/yt_web", variant="huggingface") # link to /yt_web
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from app import gradio_app
2
  import gradio as gr
3
+ from modules.youtube_metadata.app import youtube_metadata_app
4
 
5
  with gr.Blocks(title="Sanatana AI - Home") as home_app:
6
+
7
+ with gr.Tab("Home"):
8
+ gr.Markdown("""
9
+ ## πŸ‘‹ Welcome to **Sanatan AI**!
10
+
11
+ Sanatan AI is your personal companion for exploring various scriptures in Sri Vaishnava Sampradayam such as **Divya Prabandham** and sanskrit scriptures such as **Bhagavat Gita**, **Vishnu Puranam** and more β€” all in one place.
12
+
13
+ ---
14
+
15
+ ### πŸš€ What you can do here:
16
+
17
+ 1. **Sanatan AI Web**
18
+ Dive into our interactive tools for semantic search and exploration of Prabandhams.
19
+ πŸ”Ή Search by **verse, keyword, or author**
20
+ πŸ”Ή Read **translations and transliterations**
21
+ πŸ”Ή Explore **related pasurams**
22
+
23
+ 2. **YouTube Metadata**
24
+ Manage and monitor your YouTube channels and videos.
25
+ πŸ”Ή Add or remove channels
26
+ πŸ”Ή Fetch latest video details
27
+ πŸ”Ή Track video updates in real-time
28
+
29
+ ---
30
+
31
+ ### πŸ’‘ Tips:
32
+
33
+ - Use the tabs above to navigate between tools.
34
+ - All data and searches are processed **locally or in your Space**, keeping it fast and private.
35
+ - Hover over buttons for quick hints!
36
+
37
+ ---
38
+
39
+ Enjoy your journey with **Sanatan AI**! πŸ™
40
+ """)
41
+
42
+ with gr.Tab("Chat"):
43
+ gradio_app.render()
44
+
45
+ with gr.Tab("Manage YouTube Metadata"):
46
+ youtube_metadata_app.render()
modules/youtube_metadata/youtube_poller.py CHANGED
@@ -1,3 +1,6 @@
 
 
 
1
  from chromadb import Collection
2
  import feedparser
3
  from modules.youtube_metadata.db import get_youtube_metadata_collection, get_indexed_channels
@@ -66,9 +69,12 @@ def add_to_chroma(collection: Collection, new_videos):
66
  if not new_videos:
67
  return
68
  count = collection.count()
 
 
 
69
  collection.add(
70
- documents=[f"{v['title']} - v['description']" for v in new_videos],
71
- embeddings=[get_embedding(v["title"]) for v in new_videos],
72
  metadatas=[
73
  {**v, "_global_index": i}
74
  for i, v in enumerate(new_videos, start=count)
@@ -91,14 +97,37 @@ def incremental_update(channel_id):
91
  else:
92
  logger.info(f"youtube_poller: incremental_uddate: No new videos for {channel_id}")
93
 
 
94
 
95
- def start_poll():
96
  import time
 
97
 
98
  configured_channels = get_indexed_channels().keys()
99
 
100
- while True:
101
  for channel_id in configured_channels:
102
  incremental_update(channel_id)
103
  logger.info("youtube_poller: Sleeping for 10 minutes")
104
  time.sleep(600) # 10 minutes
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import signal
2
+ import sys
3
+ import threading
4
  from chromadb import Collection
5
  import feedparser
6
  from modules.youtube_metadata.db import get_youtube_metadata_collection, get_indexed_channels
 
69
  if not new_videos:
70
  return
71
  count = collection.count()
72
+ logger.info("new_videos = %s", new_videos)
73
+ documents = [f"{v['video_title']} - v['description']" for v in new_videos]
74
+ embeddings = [get_embedding(doc) for doc in documents]
75
  collection.add(
76
+ documents=documents,
77
+ embeddings=embeddings,
78
  metadatas=[
79
  {**v, "_global_index": i}
80
  for i, v in enumerate(new_videos, start=count)
 
97
  else:
98
  logger.info(f"youtube_poller: incremental_uddate: No new videos for {channel_id}")
99
 
100
+ stop_flag = False
101
 
102
+ def poll_loop():
103
  import time
104
+ global stop_flag
105
 
106
  configured_channels = get_indexed_channels().keys()
107
 
108
+ while not stop_flag:
109
  for channel_id in configured_channels:
110
  incremental_update(channel_id)
111
  logger.info("youtube_poller: Sleeping for 10 minutes")
112
  time.sleep(600) # 10 minutes
113
+
114
+ poll_thread = None
115
+ def start_poll():
116
+ global poll_thread
117
+ poll_thread = threading.Thread(target=poll_loop)
118
+ poll_thread.start()
119
+
120
+ def stop_poll():
121
+ global stop_flag
122
+ stop_flag = True
123
+
124
+
125
+ def youtube_poll_shutdown_handler(sig, frame):
126
+ global poll_thread
127
+ print("Shutting down...")
128
+ stop_poll()
129
+ poll_thread.join()
130
+ sys.exit(0)
131
+
132
+ signal.signal(signal.SIGINT, youtube_poll_shutdown_handler)
133
+ signal.signal(signal.SIGTERM, youtube_poll_shutdown_handler)