Upload folder using huggingface_hub
Browse files- app.py +23 -35
- modules/answerer.py +1 -1
app.py
CHANGED
@@ -24,6 +24,10 @@ load_dotenv()
|
|
24 |
# -------------------------------
|
25 |
# Utility functions
|
26 |
# -------------------------------
|
|
|
|
|
|
|
|
|
27 |
def show_component():
|
28 |
return gr.update(visible=True)
|
29 |
|
@@ -52,8 +56,8 @@ def clear_component():
|
|
52 |
return gr.update(value="")
|
53 |
|
54 |
|
55 |
-
def show_loading():
|
56 |
-
return gr.update(value="⏳Fetching ...")
|
57 |
|
58 |
|
59 |
def enable_if_not_none(question):
|
@@ -78,13 +82,14 @@ def index_channels(channel_urls: str):
|
|
78 |
# final UI update
|
79 |
yield (
|
80 |
f"✅ Indexed {total_videos} videos from {len(urls)} channels.",
|
81 |
-
|
82 |
list_channels_radio(),
|
83 |
)
|
84 |
|
|
|
85 |
def init(progress: gr.Progress = None):
|
86 |
channels = "https://www.youtube.com/@onedayonepasuram6126,https://www.youtube.com/@srisookthi,https://www.youtube.com/@learn-aksharam,https://www.youtube.com/@SriYadugiriYathirajaMutt,https://www.youtube.com/@akivasudev"
|
87 |
-
for
|
88 |
# print(resp)
|
89 |
yield msg
|
90 |
|
@@ -94,7 +99,7 @@ def refresh_all_channels():
|
|
94 |
channels = get_indexed_channels(get_collection())
|
95 |
|
96 |
if not channels:
|
97 |
-
return "⚠️ No channels available to refresh.",
|
98 |
|
99 |
# build list of URLs
|
100 |
urls = []
|
@@ -108,7 +113,7 @@ def refresh_all_channels():
|
|
108 |
|
109 |
return (
|
110 |
f"🔄 Refreshed {len(urls)} channels, re-indexed {total_videos} videos.",
|
111 |
-
|
112 |
)
|
113 |
|
114 |
|
@@ -201,7 +206,7 @@ def fetch_channel_html(channel_id: str, page: int = 1, page_size: int = 10):
|
|
201 |
def delete_channel(channel_url: str):
|
202 |
delete_channel_from_collection(channel_url)
|
203 |
# Return updated radio choices
|
204 |
-
return
|
205 |
|
206 |
|
207 |
# -------------------------------
|
@@ -361,9 +366,6 @@ with gr.Blocks() as demo:
|
|
361 |
outputs=[refresh_status, channel_radio],
|
362 |
)
|
363 |
|
364 |
-
def refresh_channel_list():
|
365 |
-
return gr.update(choices=list_channels_radio())
|
366 |
-
|
367 |
refresh_btn.click(fn=refresh_channel_list, outputs=[channel_radio]).then(
|
368 |
fn=list_channels_radio, outputs=[channel_list_state]
|
369 |
)
|
@@ -437,16 +439,9 @@ with gr.Blocks() as demo:
|
|
437 |
question = gr.Textbox(
|
438 |
label="Ask a Question",
|
439 |
placeholder="e.g., What topics did they cover on AI ethics?",
|
|
|
440 |
)
|
441 |
-
|
442 |
-
ask_btn = gr.Button(
|
443 |
-
"💡 Get Answer",
|
444 |
-
size="sm",
|
445 |
-
scale=0,
|
446 |
-
variant="primary",
|
447 |
-
interactive=False,
|
448 |
-
)
|
449 |
-
ask_status = gr.Markdown()
|
450 |
|
451 |
gr.Examples(
|
452 |
[
|
@@ -459,30 +454,23 @@ with gr.Blocks() as demo:
|
|
459 |
inputs=question,
|
460 |
)
|
461 |
|
|
|
|
|
462 |
answer = gr.Markdown()
|
463 |
video_embed = gr.HTML() # iframe embeds
|
464 |
|
465 |
-
|
466 |
-
|
467 |
-
).then(
|
468 |
-
handle_query,
|
469 |
-
inputs=[question, search_channel],
|
470 |
-
outputs=[answer, video_embed],
|
471 |
-
).then(
|
472 |
-
enable_component, outputs=[ask_btn]
|
473 |
-
).then(
|
474 |
-
clear_component, outputs=[ask_status]
|
475 |
-
)
|
476 |
|
477 |
-
question.change(enable_if_not_none, inputs=[question], outputs=[
|
478 |
-
question.submit(show_loading, outputs=[ask_status]).then(
|
479 |
-
|
480 |
-
).then(
|
481 |
handle_query,
|
482 |
inputs=[question, search_channel],
|
483 |
outputs=[answer, video_embed],
|
484 |
).then(
|
485 |
-
enable_component, outputs=[
|
486 |
).then(
|
487 |
clear_component, outputs=[ask_status]
|
488 |
)
|
|
|
24 |
# -------------------------------
|
25 |
# Utility functions
|
26 |
# -------------------------------
|
27 |
+
def refresh_channel_list():
|
28 |
+
return gr.update(choices=list_channels_radio())
|
29 |
+
|
30 |
+
|
31 |
def show_component():
|
32 |
return gr.update(visible=True)
|
33 |
|
|
|
56 |
return gr.update(value="")
|
57 |
|
58 |
|
59 |
+
def show_loading(question):
|
60 |
+
return gr.update(value=f"⏳Fetching details on [{question}]...")
|
61 |
|
62 |
|
63 |
def enable_if_not_none(question):
|
|
|
82 |
# final UI update
|
83 |
yield (
|
84 |
f"✅ Indexed {total_videos} videos from {len(urls)} channels.",
|
85 |
+
refresh_channel_list(),
|
86 |
list_channels_radio(),
|
87 |
)
|
88 |
|
89 |
+
|
90 |
def init(progress: gr.Progress = None):
|
91 |
channels = "https://www.youtube.com/@onedayonepasuram6126,https://www.youtube.com/@srisookthi,https://www.youtube.com/@learn-aksharam,https://www.youtube.com/@SriYadugiriYathirajaMutt,https://www.youtube.com/@akivasudev"
|
92 |
+
for msg, upd, upd in index_channels(channels):
|
93 |
# print(resp)
|
94 |
yield msg
|
95 |
|
|
|
99 |
channels = get_indexed_channels(get_collection())
|
100 |
|
101 |
if not channels:
|
102 |
+
return "⚠️ No channels available to refresh.", refresh_channel_list()
|
103 |
|
104 |
# build list of URLs
|
105 |
urls = []
|
|
|
113 |
|
114 |
return (
|
115 |
f"🔄 Refreshed {len(urls)} channels, re-indexed {total_videos} videos.",
|
116 |
+
refresh_channel_list(),
|
117 |
)
|
118 |
|
119 |
|
|
|
206 |
def delete_channel(channel_url: str):
|
207 |
delete_channel_from_collection(channel_url)
|
208 |
# Return updated radio choices
|
209 |
+
return refresh_channel_list()
|
210 |
|
211 |
|
212 |
# -------------------------------
|
|
|
366 |
outputs=[refresh_status, channel_radio],
|
367 |
)
|
368 |
|
|
|
|
|
|
|
369 |
refresh_btn.click(fn=refresh_channel_list, outputs=[channel_radio]).then(
|
370 |
fn=list_channels_radio, outputs=[channel_list_state]
|
371 |
)
|
|
|
439 |
question = gr.Textbox(
|
440 |
label="Ask a Question",
|
441 |
placeholder="e.g., What topics did they cover on AI ethics?",
|
442 |
+
submit_btn=True,
|
443 |
)
|
444 |
+
gr.Column(scale=2)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
445 |
|
446 |
gr.Examples(
|
447 |
[
|
|
|
454 |
inputs=question,
|
455 |
)
|
456 |
|
457 |
+
submitted_question = gr.Markdown()
|
458 |
+
ask_status = gr.Markdown()
|
459 |
answer = gr.Markdown()
|
460 |
video_embed = gr.HTML() # iframe embeds
|
461 |
|
462 |
+
def get_question(q):
|
463 |
+
return f"## You asked : {q}\n---"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
464 |
|
465 |
+
# question.change(enable_if_not_none, inputs=[question], outputs=[question])
|
466 |
+
question.submit(show_loading, inputs=[question], outputs=[ask_status]).then(
|
467 |
+
get_question, inputs=[question], outputs=[submitted_question]
|
468 |
+
).then(disable_component, outputs=[question]).then(
|
469 |
handle_query,
|
470 |
inputs=[question, search_channel],
|
471 |
outputs=[answer, video_embed],
|
472 |
).then(
|
473 |
+
enable_component, outputs=[question]
|
474 |
).then(
|
475 |
clear_component, outputs=[ask_status]
|
476 |
)
|
modules/answerer.py
CHANGED
@@ -76,7 +76,7 @@ def answer_query(
|
|
76 |
)
|
77 |
|
78 |
llm_answer = response.choices[0].message.parsed
|
79 |
-
answer_text = llm_answer.answer_text
|
80 |
video_html = build_video_html(llm_answer.top_videos)
|
81 |
return answer_text, video_html
|
82 |
|
|
|
76 |
)
|
77 |
|
78 |
llm_answer = response.choices[0].message.parsed
|
79 |
+
answer_text = "\n## Answer : \n" + llm_answer.answer_text
|
80 |
video_html = build_video_html(llm_answer.top_videos)
|
81 |
return answer_text, video_html
|
82 |
|