ilsa15 commited on
Commit
f7475f2
Β·
verified Β·
1 Parent(s): 1861402

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +57 -9
app.py CHANGED
@@ -269,6 +269,50 @@ def ask_groq(context, question):
269
  )
270
  return chat_completion.choices[0].message.content.strip()
271
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
272
  # --- STREAMLIT APP ---
273
  def main():
274
  st.set_page_config(page_title="EduBot for iCodeGuru", layout="wide")
@@ -283,10 +327,18 @@ def main():
283
 
284
  yt_context = ""
285
  relevant_links = []
 
 
286
  for vid in transcripts:
 
287
  yt_context += f"\n\n[Video: {vid['title']}]({vid['link']}):\n{vid['transcript'][:1500]}"
288
- if question.lower() in vid['transcript'].lower():
289
- relevant_links.append(vid['link'])
 
 
 
 
 
290
 
291
  with st.spinner("🌐 Scraping icode.guru..."):
292
  site_blocks = scrape_icodeguru(BASE_URL, max_pages=5)
@@ -300,13 +352,9 @@ def main():
300
  st.success(answer)
301
 
302
  if relevant_links:
303
- st.markdown("### πŸ”— Related YouTube Links")
304
- for link in relevant_links:
305
- st.markdown(f"- [Watch Video]({link})")
306
 
307
  st.markdown("---")
308
  st.caption("Powered by YouTube, iCodeGuru, and Groq")
309
-
310
- if __name__ == "__main__":
311
- main()
312
-
 
269
  )
270
  return chat_completion.choices[0].message.content.strip()
271
 
272
+ # --- STREAMLIT APP ---
273
+ # def main():
274
+ # st.set_page_config(page_title="EduBot for iCodeGuru", layout="wide")
275
+ # st.title("πŸŽ“ EduBot for @icodeguru0")
276
+ # st.markdown("Ask anything based on the latest YouTube videos and website content of [icode.guru](https://icode.guru).")
277
+
278
+ # question = st.text_input("πŸ’¬ Ask your question:")
279
+ # if question:
280
+ # with st.spinner("πŸ“Ί Fetching YouTube videos..."):
281
+ # video_info = get_latest_video_ids(channel_id, max_results=5)
282
+ # transcripts = get_video_transcripts(video_info)
283
+
284
+ # yt_context = ""
285
+ # relevant_links = []
286
+ # for vid in transcripts:
287
+ # yt_context += f"\n\n[Video: {vid['title']}]({vid['link']}):\n{vid['transcript'][:1500]}"
288
+ # if question.lower() in vid['transcript'].lower():
289
+ # relevant_links.append(vid['link'])
290
+
291
+ # with st.spinner("🌐 Scraping icode.guru..."):
292
+ # site_blocks = scrape_icodeguru(BASE_URL, max_pages=5)
293
+ # site_context = "\n\n".join(site_blocks)
294
+
295
+ # full_context = yt_context + "\n\n" + site_context
296
+
297
+ # with st.spinner("🧠 Thinking..."):
298
+ # answer = ask_groq(full_context, question)
299
+
300
+ # st.success(answer)
301
+
302
+ # if relevant_links:
303
+ # st.markdown("### πŸ”— Related YouTube Links")
304
+ # for link in relevant_links:
305
+ # st.markdown(f"- [Watch Video]({link})")
306
+
307
+ # st.markdown("---")
308
+ # st.caption("Powered by YouTube, iCodeGuru, and Groq")
309
+
310
+ # if __name__ == "__main__":
311
+ # main()
312
+
313
+
314
+
315
+
316
  # --- STREAMLIT APP ---
317
  def main():
318
  st.set_page_config(page_title="EduBot for iCodeGuru", layout="wide")
 
327
 
328
  yt_context = ""
329
  relevant_links = []
330
+ question_keywords = question.lower().split()
331
+
332
  for vid in transcripts:
333
+ content = f"{vid['title']} {vid['transcript']}".lower()
334
  yt_context += f"\n\n[Video: {vid['title']}]({vid['link']}):\n{vid['transcript'][:1500]}"
335
+
336
+ # Match based on presence of question keywords
337
+ if any(kw in content for kw in question_keywords):
338
+ relevant_links.append({
339
+ "title": vid["title"],
340
+ "link": vid["link"]
341
+ })
342
 
343
  with st.spinner("🌐 Scraping icode.guru..."):
344
  site_blocks = scrape_icodeguru(BASE_URL, max_pages=5)
 
352
  st.success(answer)
353
 
354
  if relevant_links:
355
+ st.markdown("### πŸ”— Relevant iCodeGuru YouTube Videos")
356
+ for item in relevant_links:
357
+ st.markdown(f"- [{item['title']}]({item['link']})")
358
 
359
  st.markdown("---")
360
  st.caption("Powered by YouTube, iCodeGuru, and Groq")