Sayiqa commited on
Commit
c45fc11
·
verified ·
1 Parent(s): 12d5eb5

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +34 -0
app.py CHANGED
@@ -506,6 +506,40 @@ def process_youtube_video(url="", keywords=""):
506
  except Exception as e:
507
  return None, f"Error: {str(e)}", "N/A", "", ""
508
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
509
  # Gradio Interface
510
  with gr.Blocks(theme=gr.themes.Soft()) as app:
511
  # Login Page
 
506
  except Exception as e:
507
  return None, f"Error: {str(e)}", "N/A", "", ""
508
 
509
+ def get_recommendations(keywords, max_results=5):
510
+ """
511
+ Fetches related video recommendations based on the provided keywords.
512
+ """
513
+ YOUTUBE_API_KEY = "AIzaSyD_SDF4lC3vpHVAMnBOcN2ZCTz7dRjUc98" # Replace with your YouTube Data API key
514
+ if not keywords.strip():
515
+ return "Please provide search keywords"
516
+ try:
517
+ response = requests.get(
518
+ "https://www.googleapis.com/youtube/v3/search",
519
+ params={
520
+ "part": "snippet",
521
+ "q": f"educational {keywords}",
522
+ "type": "video",
523
+ "maxResults": max_results,
524
+ "relevanceLanguage": "en",
525
+ "key": YOUTUBE_API_KEY
526
+ }
527
+ ).json()
528
+
529
+ results = []
530
+ for item in response.get("items", []):
531
+ title = item["snippet"]["title"]
532
+ channel = item["snippet"]["channelTitle"]
533
+ video_id = item["id"]["videoId"]
534
+ results.append(f"📺 {title}\n👤 {channel}\n🔗 https://youtube.com/watch?v={video_id}\n")
535
+
536
+ return "\n".join(results) if results else "No recommendations found"
537
+ except Exception as e:
538
+ return f"Error: {str(e)}"
539
+
540
+
541
+
542
+
543
  # Gradio Interface
544
  with gr.Blocks(theme=gr.themes.Soft()) as app:
545
  # Login Page