Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,3 +1,419 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
import subprocess
|
| 2 |
subprocess.check_call(["pip", "install", "transformers==4.34.0"])
|
| 3 |
subprocess.check_call(["pip", "install", "torch>=1.7.1"])
|
|
@@ -67,12 +483,9 @@ else:
|
|
| 67 |
raise ValueError("HF_TOKEN environment variable not set.")
|
| 68 |
|
| 69 |
|
| 70 |
-
#
|
| 71 |
-
|
| 72 |
-
|
| 73 |
-
"teacher": "teach2024",
|
| 74 |
-
"student": "learn2024"
|
| 75 |
-
}
|
| 76 |
|
| 77 |
import os
|
| 78 |
from youtube_transcript_api import YouTubeTranscriptApi, TranscriptsDisabled, NoTranscriptFound
|
|
@@ -111,29 +524,6 @@ courses_data = [
|
|
| 111 |
(5, "Mathematics", "Ms. Smith", "Intermediate")
|
| 112 |
]
|
| 113 |
|
| 114 |
-
def sanitize_text(text):
|
| 115 |
-
"""Remove invalid Unicode characters."""
|
| 116 |
-
return text.encode("utf-8", "replace").decode("utf-8")
|
| 117 |
-
|
| 118 |
-
def extract_video_id(url):
|
| 119 |
-
if not url:
|
| 120 |
-
return None
|
| 121 |
-
patterns = [
|
| 122 |
-
r'(?:v=|\/videos\/|embed\/|youtu.be\/|\/v\/|\/e\/|watch\?v=|\/watch\?v=)([^#\&\?]*)'
|
| 123 |
-
]
|
| 124 |
-
for pattern in patterns:
|
| 125 |
-
match = re.search(pattern, url)
|
| 126 |
-
if match:
|
| 127 |
-
return match.group(1)
|
| 128 |
-
return None
|
| 129 |
-
|
| 130 |
-
from textblob import TextBlob
|
| 131 |
-
from youtube_transcript_api import YouTubeTranscriptApi, TranscriptsDisabled, NoTranscriptFound
|
| 132 |
-
import re
|
| 133 |
-
from collections import Counter
|
| 134 |
-
from googleapiclient.discovery import build
|
| 135 |
-
|
| 136 |
-
|
| 137 |
def extract_video_id(url):
|
| 138 |
match = re.search(r"(?:v=|\/)([0-9A-Za-z_-]{11})", url)
|
| 139 |
return match.group(1) if match else None
|
|
@@ -158,17 +548,6 @@ def get_video_metadata(video_id):
|
|
| 158 |
def clean_text_for_analysis(text):
|
| 159 |
return " ".join(text.split())
|
| 160 |
|
| 161 |
-
def extract_subtitle_info(text):
|
| 162 |
-
try:
|
| 163 |
-
sentences = text.split(". ")
|
| 164 |
-
words = text.split()
|
| 165 |
-
common_words = Counter(words).most_common(10)
|
| 166 |
-
key_topics = ", ".join([word for word, count in common_words])
|
| 167 |
-
info = f"Key topics discussed: {key_topics}. \nNumber of sentences: {len(sentences)}. \nTotal words: {len(words)}."
|
| 168 |
-
return info
|
| 169 |
-
except Exception as e:
|
| 170 |
-
return f"Error extracting subtitle information: {str(e)}"
|
| 171 |
-
|
| 172 |
def get_recommendations(keywords, max_results=5):
|
| 173 |
if not keywords:
|
| 174 |
return "Please provide search keywords"
|
|
@@ -196,16 +575,15 @@ def get_recommendations(keywords, max_results=5):
|
|
| 196 |
except Exception as e:
|
| 197 |
return f"Error: {str(e)}"
|
| 198 |
|
| 199 |
-
def process_youtube_video(url
|
| 200 |
try:
|
| 201 |
thumbnail = None
|
| 202 |
summary = "No transcript available"
|
| 203 |
sentiment_label = "N/A"
|
| 204 |
-
recommendations = ""
|
| 205 |
|
| 206 |
video_id = extract_video_id(url)
|
| 207 |
if not video_id:
|
| 208 |
-
return None, "Invalid YouTube URL", "N/A"
|
| 209 |
|
| 210 |
thumbnail = f"https://img.youtube.com/vi/{video_id}/maxresdefault.jpg"
|
| 211 |
|
|
@@ -233,41 +611,10 @@ def process_youtube_video(url, keywords):
|
|
| 233 |
summary = metadata.get("description", "No subtitles available")
|
| 234 |
sentiment_label = "N/A"
|
| 235 |
|
| 236 |
-
|
| 237 |
-
recommendations = get_recommendations(keywords)
|
| 238 |
-
|
| 239 |
-
return thumbnail, summary, sentiment_label, recommendations
|
| 240 |
|
| 241 |
except Exception as e:
|
| 242 |
-
return None, f"Error: {str(e)}", "N/A"
|
| 243 |
-
|
| 244 |
-
|
| 245 |
-
# def get_recommendations(keywords, max_results=5):
|
| 246 |
-
# if not keywords:
|
| 247 |
-
# return "Please provide search keywords"
|
| 248 |
-
# try:
|
| 249 |
-
# response = requests.get(
|
| 250 |
-
# "https://www.googleapis.com/youtube/v3/search",
|
| 251 |
-
# params={
|
| 252 |
-
# "part": "snippet",
|
| 253 |
-
# "q": f"educational {keywords}",
|
| 254 |
-
# "type": "video",
|
| 255 |
-
# "maxResults": max_results,
|
| 256 |
-
# "relevanceLanguage": "en",
|
| 257 |
-
# "key": YOUTUBE_API_KEY
|
| 258 |
-
# }
|
| 259 |
-
# ).json()
|
| 260 |
-
|
| 261 |
-
# results = []
|
| 262 |
-
# for item in response.get("items", []):
|
| 263 |
-
# title = item["snippet"]["title"]
|
| 264 |
-
# channel = item["snippet"]["channelTitle"]
|
| 265 |
-
# video_id = item["id"]["videoId"]
|
| 266 |
-
# results.append(f"πΊ {title}\nπ€ {channel}\nπ https://youtube.com/watch?v={video_id}\n")
|
| 267 |
-
|
| 268 |
-
# return "\n".join(results) if results else "No recommendations found"
|
| 269 |
-
# except Exception as e:
|
| 270 |
-
# return f"Error: {str(e)}"
|
| 271 |
|
| 272 |
# Gradio Interface
|
| 273 |
with gr.Blocks(theme=gr.themes.Soft()) as app:
|
|
@@ -278,7 +625,7 @@ with gr.Blocks(theme=gr.themes.Soft()) as app:
|
|
| 278 |
password = gr.Textbox(label="Password", type="password")
|
| 279 |
login_btn = gr.Button("Login", variant="primary")
|
| 280 |
login_msg = gr.Markdown()
|
| 281 |
-
|
| 282 |
# Main Interface
|
| 283 |
with gr.Group(visible=False) as main_page:
|
| 284 |
with gr.Row():
|
|
@@ -290,7 +637,7 @@ with gr.Blocks(theme=gr.themes.Soft()) as app:
|
|
| 290 |
nav_courses = gr.Button("π Courses")
|
| 291 |
nav_youtube = gr.Button("π₯ YouTube Tool")
|
| 292 |
logout_btn = gr.Button("πͺ Logout", variant="stop")
|
| 293 |
-
|
| 294 |
with gr.Column(scale=3):
|
| 295 |
# Dashboard Content
|
| 296 |
dashboard_page = gr.Group()
|
|
@@ -301,13 +648,13 @@ with gr.Blocks(theme=gr.themes.Soft()) as app:
|
|
| 301 |
- π₯ Total Students: {len(students_data)}
|
| 302 |
- π¨βπ« Total Teachers: {len(teachers_data)}
|
| 303 |
- π Total Courses: {len(courses_data)}
|
| 304 |
-
|
| 305 |
### Quick Actions
|
| 306 |
- View student performance
|
| 307 |
- Access course materials
|
| 308 |
- Generate learning insights
|
| 309 |
""")
|
| 310 |
-
|
| 311 |
# Students Content
|
| 312 |
students_page = gr.Group(visible=False)
|
| 313 |
with students_page:
|
|
@@ -316,7 +663,7 @@ with gr.Blocks(theme=gr.themes.Soft()) as app:
|
|
| 316 |
value=students_data,
|
| 317 |
headers=["ID", "Name", "Grade", "Program"]
|
| 318 |
)
|
| 319 |
-
|
| 320 |
# Teachers Content
|
| 321 |
teachers_page = gr.Group(visible=False)
|
| 322 |
with teachers_page:
|
|
@@ -325,7 +672,7 @@ with gr.Blocks(theme=gr.themes.Soft()) as app:
|
|
| 325 |
value=teachers_data,
|
| 326 |
headers=["ID", "Name", "Subject", "Qualification"]
|
| 327 |
)
|
| 328 |
-
|
| 329 |
# Courses Content
|
| 330 |
courses_page = gr.Group(visible=False)
|
| 331 |
with courses_page:
|
|
@@ -334,7 +681,7 @@ with gr.Blocks(theme=gr.themes.Soft()) as app:
|
|
| 334 |
value=courses_data,
|
| 335 |
headers=["ID", "Name", "Instructor", "Level"]
|
| 336 |
)
|
| 337 |
-
|
| 338 |
# YouTube Tool Content
|
| 339 |
youtube_page = gr.Group(visible=False)
|
| 340 |
with youtube_page:
|
|
@@ -350,10 +697,11 @@ with gr.Blocks(theme=gr.themes.Soft()) as app:
|
|
| 350 |
placeholder="e.g., python programming, machine learning"
|
| 351 |
)
|
| 352 |
analyze_btn = gr.Button("π Analyze Video", variant="primary")
|
| 353 |
-
|
|
|
|
| 354 |
with gr.Column(scale=1):
|
| 355 |
video_thumbnail = gr.Image(label="Video Preview")
|
| 356 |
-
|
| 357 |
with gr.Row():
|
| 358 |
with gr.Column():
|
| 359 |
summary = gr.Textbox(label="π Summary", lines=8)
|
|
@@ -373,7 +721,7 @@ with gr.Blocks(theme=gr.themes.Soft()) as app:
|
|
| 373 |
main_page: gr.update(visible=False),
|
| 374 |
login_msg: "β Invalid credentials"
|
| 375 |
}
|
| 376 |
-
|
| 377 |
def show_page(page_name):
|
| 378 |
updates = {
|
| 379 |
dashboard_page: gr.update(visible=False),
|
|
@@ -384,26 +732,32 @@ with gr.Blocks(theme=gr.themes.Soft()) as app:
|
|
| 384 |
}
|
| 385 |
updates[page_name] = gr.update(visible=True)
|
| 386 |
return updates
|
| 387 |
-
|
| 388 |
# Event Handlers
|
| 389 |
login_btn.click(
|
| 390 |
login_check,
|
| 391 |
inputs=[username, password],
|
| 392 |
outputs=[login_page, main_page, login_msg]
|
| 393 |
)
|
| 394 |
-
|
| 395 |
nav_dashboard.click(lambda: show_page(dashboard_page), outputs=list(show_page(dashboard_page).keys()))
|
| 396 |
nav_students.click(lambda: show_page(students_page), outputs=list(show_page(students_page).keys()))
|
| 397 |
nav_teachers.click(lambda: show_page(teachers_page), outputs=list(show_page(teachers_page).keys()))
|
| 398 |
nav_courses.click(lambda: show_page(courses_page), outputs=list(show_page(courses_page).keys()))
|
| 399 |
nav_youtube.click(lambda: show_page(youtube_page), outputs=list(show_page(youtube_page).keys()))
|
| 400 |
-
|
| 401 |
analyze_btn.click(
|
| 402 |
process_youtube_video,
|
| 403 |
-
inputs=[video_url
|
| 404 |
-
outputs=[video_thumbnail, summary, sentiment
|
| 405 |
)
|
| 406 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 407 |
logout_btn.click(
|
| 408 |
lambda: {
|
| 409 |
login_page: gr.update(visible=True),
|
|
@@ -413,4 +767,4 @@ with gr.Blocks(theme=gr.themes.Soft()) as app:
|
|
| 413 |
)
|
| 414 |
|
| 415 |
if __name__ == "__main__":
|
| 416 |
-
app.launch()
|
|
|
|
| 1 |
+
# import subprocess
|
| 2 |
+
# subprocess.check_call(["pip", "install", "transformers==4.34.0"])
|
| 3 |
+
# subprocess.check_call(["pip", "install", "torch>=1.7.1"])
|
| 4 |
+
# subprocess.check_call(["pip", "install", "youtube_transcript_api>=0.6.3"])
|
| 5 |
+
# subprocess.check_call(["pip", "install", "pytube"])
|
| 6 |
+
# subprocess.check_call(["pip", "install", "huggingface_hub>=0.19.0"])
|
| 7 |
+
# subprocess.check_call(["pip", "install", "PyPDF2>=3.0.1"])
|
| 8 |
+
# subprocess.check_call(["pip", "install", "google-generativeai"])
|
| 9 |
+
# subprocess.check_call(["pip", "install", "textblob>=0.17.1"])
|
| 10 |
+
# subprocess.check_call(["pip", "install", "python-dotenv>=1.0.0"])
|
| 11 |
+
# subprocess.check_call(["pip", "install", "genai"])
|
| 12 |
+
# subprocess.check_call(["pip", "install", "google-cloud-aiplatform==1.34.0"])
|
| 13 |
+
# subprocess.check_call(["pip", "install", "google-api-python-client>=2.0.0"])
|
| 14 |
+
# import transformers
|
| 15 |
+
# import torch
|
| 16 |
+
# import os
|
| 17 |
+
# import youtube_transcript_api
|
| 18 |
+
# import pytube
|
| 19 |
+
# import gradio
|
| 20 |
+
# import PyPDF2
|
| 21 |
+
# import pathlib
|
| 22 |
+
# import pandas
|
| 23 |
+
# import numpy
|
| 24 |
+
# import textblob
|
| 25 |
+
# import gradio as gr
|
| 26 |
+
# from youtube_transcript_api import YouTubeTranscriptApi
|
| 27 |
+
# import google.generativeai as genai
|
| 28 |
+
# from googleapiclient.discovery import build
|
| 29 |
+
# import requests
|
| 30 |
+
# from textblob import TextBlob
|
| 31 |
+
# import re
|
| 32 |
+
# #from google.cloud import generativeai
|
| 33 |
+
# from googleapiclient.discovery import build
|
| 34 |
+
# from huggingface_hub import login
|
| 35 |
+
# from youtube_transcript_api import YouTubeTranscriptApi, TranscriptsDisabled, NoTranscriptFound
|
| 36 |
+
# def install_missing_packages():
|
| 37 |
+
# required_packages = {
|
| 38 |
+
# "torch":">=1.11.0",
|
| 39 |
+
# "transformers":">=4.34.0",
|
| 40 |
+
# "youtube_transcript_api" :">=0.6.3" ,
|
| 41 |
+
# "pytube":None,
|
| 42 |
+
# "huggingface_hub": ">=0.19.0",
|
| 43 |
+
# "PyPDF2": ">=3.0.1",
|
| 44 |
+
# "textblob":">=0.17.1",
|
| 45 |
+
# "python-dotenv":">=1.0.0",
|
| 46 |
+
# "genai":None,
|
| 47 |
+
# "google-generativeai": None,
|
| 48 |
+
# "google-cloud-aiplatform":"==1.34.0",
|
| 49 |
+
# "google-api-python-client": ">=2.0.0"
|
| 50 |
+
# }
|
| 51 |
+
|
| 52 |
+
|
| 53 |
+
# for package, version in required_packages.items():
|
| 54 |
+
# try:
|
| 55 |
+
# __import__(package)
|
| 56 |
+
# except ImportError:
|
| 57 |
+
# package_name = f"{package}{version}" if version else package
|
| 58 |
+
# subprocess.check_call(["pip", "install", package_name])
|
| 59 |
+
|
| 60 |
+
# install_missing_packages()
|
| 61 |
+
# # Configuration
|
| 62 |
+
|
| 63 |
+
# hf_token = os.getenv("HF_TOKEN")
|
| 64 |
+
# if hf_token:
|
| 65 |
+
# login(hf_token)
|
| 66 |
+
# else:
|
| 67 |
+
# raise ValueError("HF_TOKEN environment variable not set.")
|
| 68 |
+
|
| 69 |
+
|
| 70 |
+
# # Configuration
|
| 71 |
+
# USER_CREDENTIALS = {
|
| 72 |
+
# "admin": "password123",
|
| 73 |
+
# "teacher": "teach2024",
|
| 74 |
+
# "student": "learn2024"
|
| 75 |
+
# }
|
| 76 |
+
|
| 77 |
+
# import os
|
| 78 |
+
# from youtube_transcript_api import YouTubeTranscriptApi, TranscriptsDisabled, NoTranscriptFound
|
| 79 |
+
|
| 80 |
+
# # Use environment variables
|
| 81 |
+
# GOOGLE_API_KEY = os.getenv("GOOGLE_API_KEY")
|
| 82 |
+
# YOUTUBE_API_KEY = os.getenv("YOUTUBE_API_KEY")
|
| 83 |
+
|
| 84 |
+
# if not GOOGLE_API_KEY or not YOUTUBE_API_KEY:
|
| 85 |
+
# raise ValueError("Please set GOOGLE_API_KEY and YOUTUBE_API_KEY environment variables")
|
| 86 |
+
|
| 87 |
+
# genai.configure(api_key=GOOGLE_API_KEY)
|
| 88 |
+
|
| 89 |
+
# # Database
|
| 90 |
+
# students_data = [
|
| 91 |
+
# (1, "Alice", "A", "Computer Science"),
|
| 92 |
+
# (2, "Aliaa", "B", "Mathematics"),
|
| 93 |
+
# (3, "Charlie", "A", "Machine Learning"),
|
| 94 |
+
# (4, "Daan", "A", "Physics"),
|
| 95 |
+
# (5, "Jhon", "C", "Math"),
|
| 96 |
+
# (6, "Emma", "A+", "Computer Science")
|
| 97 |
+
# ]
|
| 98 |
+
|
| 99 |
+
# teachers_data = [
|
| 100 |
+
# (1, "Dr. Smith", "Math", "MS Mathematics"),
|
| 101 |
+
# (2, "Ms. Johnson", "Science", "MSc Physics"),
|
| 102 |
+
# (3, "Ms. Jack", "Artificial Intelligence Engineer", "MSc AI"),
|
| 103 |
+
# (4, "Ms. Evelyn", "Computer Science", "MSc Computer Science"),
|
| 104 |
+
# ]
|
| 105 |
+
|
| 106 |
+
# courses_data = [
|
| 107 |
+
# (1, "Algebra", "Dr. Smith", "Advanced"),
|
| 108 |
+
# (2, "Biology", "Ms. Mia", "Intermediate"),
|
| 109 |
+
# (3, "Machine Learning", "Ms. Jack", "Intermediate"),
|
| 110 |
+
# (4, "Computer Science", "Ms. Evelyn", "Intermediate"),
|
| 111 |
+
# (5, "Mathematics", "Ms. Smith", "Intermediate")
|
| 112 |
+
# ]
|
| 113 |
+
|
| 114 |
+
# def sanitize_text(text):
|
| 115 |
+
# """Remove invalid Unicode characters."""
|
| 116 |
+
# return text.encode("utf-8", "replace").decode("utf-8")
|
| 117 |
+
|
| 118 |
+
# def extract_video_id(url):
|
| 119 |
+
# if not url:
|
| 120 |
+
# return None
|
| 121 |
+
# patterns = [
|
| 122 |
+
# r'(?:v=|\/videos\/|embed\/|youtu.be\/|\/v\/|\/e\/|watch\?v=|\/watch\?v=)([^#\&\?]*)'
|
| 123 |
+
# ]
|
| 124 |
+
# for pattern in patterns:
|
| 125 |
+
# match = re.search(pattern, url)
|
| 126 |
+
# if match:
|
| 127 |
+
# return match.group(1)
|
| 128 |
+
# return None
|
| 129 |
+
|
| 130 |
+
# from textblob import TextBlob
|
| 131 |
+
# from youtube_transcript_api import YouTubeTranscriptApi, TranscriptsDisabled, NoTranscriptFound
|
| 132 |
+
# import re
|
| 133 |
+
# from collections import Counter
|
| 134 |
+
# from googleapiclient.discovery import build
|
| 135 |
+
|
| 136 |
+
|
| 137 |
+
# def extract_video_id(url):
|
| 138 |
+
# match = re.search(r"(?:v=|\/)([0-9A-Za-z_-]{11})", url)
|
| 139 |
+
# return match.group(1) if match else None
|
| 140 |
+
|
| 141 |
+
# def get_video_metadata(video_id):
|
| 142 |
+
# try:
|
| 143 |
+
# youtube = build("youtube", "v3", developerKey=YOUTUBE_API_KEY)
|
| 144 |
+
# request = youtube.videos().list(part="snippet", id=video_id)
|
| 145 |
+
# response = request.execute()
|
| 146 |
+
|
| 147 |
+
# if "items" in response and len(response["items"]) > 0:
|
| 148 |
+
# snippet = response["items"][0]["snippet"]
|
| 149 |
+
# return {
|
| 150 |
+
# "title": snippet.get("title", "No title available"),
|
| 151 |
+
# "description": snippet.get("description", "No description available"),
|
| 152 |
+
# }
|
| 153 |
+
# return {}
|
| 154 |
+
|
| 155 |
+
# except Exception as e:
|
| 156 |
+
# return {"title": "Error fetching metadata", "description": str(e)}
|
| 157 |
+
|
| 158 |
+
# def clean_text_for_analysis(text):
|
| 159 |
+
# return " ".join(text.split())
|
| 160 |
+
|
| 161 |
+
# def extract_subtitle_info(text):
|
| 162 |
+
# try:
|
| 163 |
+
# sentences = text.split(". ")
|
| 164 |
+
# words = text.split()
|
| 165 |
+
# common_words = Counter(words).most_common(10)
|
| 166 |
+
# key_topics = ", ".join([word for word, count in common_words])
|
| 167 |
+
# info = f"Key topics discussed: {key_topics}. \nNumber of sentences: {len(sentences)}. \nTotal words: {len(words)}."
|
| 168 |
+
# return info
|
| 169 |
+
# except Exception as e:
|
| 170 |
+
# return f"Error extracting subtitle information: {str(e)}"
|
| 171 |
+
|
| 172 |
+
# def get_recommendations(keywords, max_results=5):
|
| 173 |
+
# if not keywords:
|
| 174 |
+
# return "Please provide search keywords"
|
| 175 |
+
# try:
|
| 176 |
+
# response = requests.get(
|
| 177 |
+
# "https://www.googleapis.com/youtube/v3/search",
|
| 178 |
+
# params={
|
| 179 |
+
# "part": "snippet",
|
| 180 |
+
# "q": f"educational {keywords}",
|
| 181 |
+
# "type": "video",
|
| 182 |
+
# "maxResults": max_results,
|
| 183 |
+
# "relevanceLanguage": "en",
|
| 184 |
+
# "key": YOUTUBE_API_KEY
|
| 185 |
+
# }
|
| 186 |
+
# ).json()
|
| 187 |
+
|
| 188 |
+
# results = []
|
| 189 |
+
# for item in response.get("items", []):
|
| 190 |
+
# title = item["snippet"]["title"]
|
| 191 |
+
# channel = item["snippet"]["channelTitle"]
|
| 192 |
+
# video_id = item["id"]["videoId"]
|
| 193 |
+
# results.append(f"πΊ {title}\nπ€ {channel}\nπ https://youtube.com/watch?v={video_id}\n")
|
| 194 |
+
|
| 195 |
+
# return "\n".join(results) if results else "No recommendations found"
|
| 196 |
+
# except Exception as e:
|
| 197 |
+
# return f"Error: {str(e)}"
|
| 198 |
+
|
| 199 |
+
# def process_youtube_video(url, keywords):
|
| 200 |
+
# try:
|
| 201 |
+
# thumbnail = None
|
| 202 |
+
# summary = "No transcript available"
|
| 203 |
+
# sentiment_label = "N/A"
|
| 204 |
+
# recommendations = ""
|
| 205 |
+
|
| 206 |
+
# video_id = extract_video_id(url)
|
| 207 |
+
# if not video_id:
|
| 208 |
+
# return None, "Invalid YouTube URL", "N/A", "", ""
|
| 209 |
+
|
| 210 |
+
# thumbnail = f"https://img.youtube.com/vi/{video_id}/maxresdefault.jpg"
|
| 211 |
+
|
| 212 |
+
# try:
|
| 213 |
+
# transcript_list = YouTubeTranscriptApi.list_transcripts(video_id)
|
| 214 |
+
# transcript = None
|
| 215 |
+
# try:
|
| 216 |
+
# transcript = transcript_list.find_transcript(['en'])
|
| 217 |
+
# except:
|
| 218 |
+
# transcript = transcript_list.find_generated_transcript(['en'])
|
| 219 |
+
|
| 220 |
+
# text = " ".join([t['text'] for t in transcript.fetch()])
|
| 221 |
+
# if not text.strip():
|
| 222 |
+
# raise ValueError("Transcript is empty")
|
| 223 |
+
|
| 224 |
+
# cleaned_text = clean_text_for_analysis(text)
|
| 225 |
+
|
| 226 |
+
# sentiment = TextBlob(cleaned_text).sentiment
|
| 227 |
+
# sentiment_label = f"{'Positive' if sentiment.polarity > 0 else 'Negative' if sentiment.polarity < 0 else 'Neutral'} ({sentiment.polarity:.2f})"
|
| 228 |
+
|
| 229 |
+
# summary = f"Summary: {cleaned_text[:400]}..."
|
| 230 |
+
|
| 231 |
+
# except (TranscriptsDisabled, NoTranscriptFound):
|
| 232 |
+
# metadata = get_video_metadata(video_id)
|
| 233 |
+
# summary = metadata.get("description", "No subtitles available")
|
| 234 |
+
# sentiment_label = "N/A"
|
| 235 |
+
|
| 236 |
+
# if keywords.strip():
|
| 237 |
+
# recommendations = get_recommendations(keywords)
|
| 238 |
+
|
| 239 |
+
# return thumbnail, summary, sentiment_label, recommendations
|
| 240 |
+
|
| 241 |
+
# except Exception as e:
|
| 242 |
+
# return None, f"Error: {str(e)}", "N/A", ""
|
| 243 |
+
|
| 244 |
+
|
| 245 |
+
# # def get_recommendations(keywords, max_results=5):
|
| 246 |
+
# # if not keywords:
|
| 247 |
+
# # return "Please provide search keywords"
|
| 248 |
+
# # try:
|
| 249 |
+
# # response = requests.get(
|
| 250 |
+
# # "https://www.googleapis.com/youtube/v3/search",
|
| 251 |
+
# # params={
|
| 252 |
+
# # "part": "snippet",
|
| 253 |
+
# # "q": f"educational {keywords}",
|
| 254 |
+
# # "type": "video",
|
| 255 |
+
# # "maxResults": max_results,
|
| 256 |
+
# # "relevanceLanguage": "en",
|
| 257 |
+
# # "key": YOUTUBE_API_KEY
|
| 258 |
+
# # }
|
| 259 |
+
# # ).json()
|
| 260 |
+
|
| 261 |
+
# # results = []
|
| 262 |
+
# # for item in response.get("items", []):
|
| 263 |
+
# # title = item["snippet"]["title"]
|
| 264 |
+
# # channel = item["snippet"]["channelTitle"]
|
| 265 |
+
# # video_id = item["id"]["videoId"]
|
| 266 |
+
# # results.append(f"πΊ {title}\nπ€ {channel}\nπ https://youtube.com/watch?v={video_id}\n")
|
| 267 |
+
|
| 268 |
+
# # return "\n".join(results) if results else "No recommendations found"
|
| 269 |
+
# # except Exception as e:
|
| 270 |
+
# # return f"Error: {str(e)}"
|
| 271 |
+
|
| 272 |
+
# # Gradio Interface
|
| 273 |
+
# with gr.Blocks(theme=gr.themes.Soft()) as app:
|
| 274 |
+
# # Login Page
|
| 275 |
+
# with gr.Group() as login_page:
|
| 276 |
+
# gr.Markdown("# π Educational Learning Management System")
|
| 277 |
+
# username = gr.Textbox(label="Username")
|
| 278 |
+
# password = gr.Textbox(label="Password", type="password")
|
| 279 |
+
# login_btn = gr.Button("Login", variant="primary")
|
| 280 |
+
# login_msg = gr.Markdown()
|
| 281 |
+
|
| 282 |
+
# # Main Interface
|
| 283 |
+
# with gr.Group(visible=False) as main_page:
|
| 284 |
+
# with gr.Row():
|
| 285 |
+
# with gr.Column(scale=1):
|
| 286 |
+
# gr.Markdown("### π Navigation")
|
| 287 |
+
# nav_dashboard = gr.Button("π Dashboard", variant="primary")
|
| 288 |
+
# nav_students = gr.Button("π₯ Students")
|
| 289 |
+
# nav_teachers = gr.Button("π¨βπ« Teachers")
|
| 290 |
+
# nav_courses = gr.Button("π Courses")
|
| 291 |
+
# nav_youtube = gr.Button("π₯ YouTube Tool")
|
| 292 |
+
# logout_btn = gr.Button("πͺ Logout", variant="stop")
|
| 293 |
+
|
| 294 |
+
# with gr.Column(scale=3):
|
| 295 |
+
# # Dashboard Content
|
| 296 |
+
# dashboard_page = gr.Group()
|
| 297 |
+
# with dashboard_page:
|
| 298 |
+
# gr.Markdown("## π Dashboard")
|
| 299 |
+
# gr.Markdown(f"""
|
| 300 |
+
# ### System Overview
|
| 301 |
+
# - π₯ Total Students: {len(students_data)}
|
| 302 |
+
# - π¨βπ« Total Teachers: {len(teachers_data)}
|
| 303 |
+
# - π Total Courses: {len(courses_data)}
|
| 304 |
+
|
| 305 |
+
# ### Quick Actions
|
| 306 |
+
# - View student performance
|
| 307 |
+
# - Access course materials
|
| 308 |
+
# - Generate learning insights
|
| 309 |
+
# """)
|
| 310 |
+
|
| 311 |
+
# # Students Content
|
| 312 |
+
# students_page = gr.Group(visible=False)
|
| 313 |
+
# with students_page:
|
| 314 |
+
# gr.Markdown("## π₯ Students")
|
| 315 |
+
# gr.DataFrame(
|
| 316 |
+
# value=students_data,
|
| 317 |
+
# headers=["ID", "Name", "Grade", "Program"]
|
| 318 |
+
# )
|
| 319 |
+
|
| 320 |
+
# # Teachers Content
|
| 321 |
+
# teachers_page = gr.Group(visible=False)
|
| 322 |
+
# with teachers_page:
|
| 323 |
+
# gr.Markdown("## π¨βπ« Teachers")
|
| 324 |
+
# gr.DataFrame(
|
| 325 |
+
# value=teachers_data,
|
| 326 |
+
# headers=["ID", "Name", "Subject", "Qualification"]
|
| 327 |
+
# )
|
| 328 |
+
|
| 329 |
+
# # Courses Content
|
| 330 |
+
# courses_page = gr.Group(visible=False)
|
| 331 |
+
# with courses_page:
|
| 332 |
+
# gr.Markdown("## π Courses")
|
| 333 |
+
# gr.DataFrame(
|
| 334 |
+
# value=courses_data,
|
| 335 |
+
# headers=["ID", "Name", "Instructor", "Level"]
|
| 336 |
+
# )
|
| 337 |
+
|
| 338 |
+
# # YouTube Tool Content
|
| 339 |
+
# youtube_page = gr.Group(visible=False)
|
| 340 |
+
# with youtube_page:
|
| 341 |
+
# gr.Markdown("## Agent for YouTube Content Exploration")
|
| 342 |
+
# with gr.Row():
|
| 343 |
+
# with gr.Column(scale=2):
|
| 344 |
+
# video_url = gr.Textbox(
|
| 345 |
+
# label="YouTube URL",
|
| 346 |
+
# placeholder="https://youtube.com/watch?v=..."
|
| 347 |
+
# )
|
| 348 |
+
# keywords = gr.Textbox(
|
| 349 |
+
# label="Keywords for Recommendations",
|
| 350 |
+
# placeholder="e.g., python programming, machine learning"
|
| 351 |
+
# )
|
| 352 |
+
# analyze_btn = gr.Button("π Analyze Video", variant="primary")
|
| 353 |
+
|
| 354 |
+
# with gr.Column(scale=1):
|
| 355 |
+
# video_thumbnail = gr.Image(label="Video Preview")
|
| 356 |
+
|
| 357 |
+
# with gr.Row():
|
| 358 |
+
# with gr.Column():
|
| 359 |
+
# summary = gr.Textbox(label="π Summary", lines=8)
|
| 360 |
+
# sentiment = gr.Textbox(label="π Content Sentiment")
|
| 361 |
+
# with gr.Column():
|
| 362 |
+
# recommendations = gr.Textbox(label="π― Related Videos", lines=10)
|
| 363 |
+
|
| 364 |
+
# def login_check(user, pwd):
|
| 365 |
+
# if USER_CREDENTIALS.get(user) == pwd:
|
| 366 |
+
# return {
|
| 367 |
+
# login_page: gr.update(visible=False),
|
| 368 |
+
# main_page: gr.update(visible=True),
|
| 369 |
+
# login_msg: ""
|
| 370 |
+
# }
|
| 371 |
+
# return {
|
| 372 |
+
# login_page: gr.update(visible=True),
|
| 373 |
+
# main_page: gr.update(visible=False),
|
| 374 |
+
# login_msg: "β Invalid credentials"
|
| 375 |
+
# }
|
| 376 |
+
|
| 377 |
+
# def show_page(page_name):
|
| 378 |
+
# updates = {
|
| 379 |
+
# dashboard_page: gr.update(visible=False),
|
| 380 |
+
# students_page: gr.update(visible=False),
|
| 381 |
+
# teachers_page: gr.update(visible=False),
|
| 382 |
+
# courses_page: gr.update(visible=False),
|
| 383 |
+
# youtube_page: gr.update(visible=False)
|
| 384 |
+
# }
|
| 385 |
+
# updates[page_name] = gr.update(visible=True)
|
| 386 |
+
# return updates
|
| 387 |
+
|
| 388 |
+
# # Event Handlers
|
| 389 |
+
# login_btn.click(
|
| 390 |
+
# login_check,
|
| 391 |
+
# inputs=[username, password],
|
| 392 |
+
# outputs=[login_page, main_page, login_msg]
|
| 393 |
+
# )
|
| 394 |
+
|
| 395 |
+
# nav_dashboard.click(lambda: show_page(dashboard_page), outputs=list(show_page(dashboard_page).keys()))
|
| 396 |
+
# nav_students.click(lambda: show_page(students_page), outputs=list(show_page(students_page).keys()))
|
| 397 |
+
# nav_teachers.click(lambda: show_page(teachers_page), outputs=list(show_page(teachers_page).keys()))
|
| 398 |
+
# nav_courses.click(lambda: show_page(courses_page), outputs=list(show_page(courses_page).keys()))
|
| 399 |
+
# nav_youtube.click(lambda: show_page(youtube_page), outputs=list(show_page(youtube_page).keys()))
|
| 400 |
+
|
| 401 |
+
# analyze_btn.click(
|
| 402 |
+
# process_youtube_video,
|
| 403 |
+
# inputs=[video_url, keywords],
|
| 404 |
+
# outputs=[video_thumbnail, summary, sentiment, recommendations]
|
| 405 |
+
# )
|
| 406 |
+
|
| 407 |
+
# logout_btn.click(
|
| 408 |
+
# lambda: {
|
| 409 |
+
# login_page: gr.update(visible=True),
|
| 410 |
+
# main_page: gr.update(visible=False)
|
| 411 |
+
# },
|
| 412 |
+
# outputs=[login_page, main_page]
|
| 413 |
+
# )
|
| 414 |
+
|
| 415 |
+
# if __name__ == "__main__":
|
| 416 |
+
# app.launch()
|
| 417 |
import subprocess
|
| 418 |
subprocess.check_call(["pip", "install", "transformers==4.34.0"])
|
| 419 |
subprocess.check_call(["pip", "install", "torch>=1.7.1"])
|
|
|
|
| 483 |
raise ValueError("HF_TOKEN environment variable not set.")
|
| 484 |
|
| 485 |
|
| 486 |
+
YOUTUBE_API_KEY = "AIzaSyD_SDF4lC3vpHVAMnBOcN2ZCTz7dRjUc98" # Replace with your YouTube API Key
|
| 487 |
+
|
| 488 |
+
USER_CREDENTIALS = {"admin": "password"} # Example user credentials
|
|
|
|
|
|
|
|
|
|
| 489 |
|
| 490 |
import os
|
| 491 |
from youtube_transcript_api import YouTubeTranscriptApi, TranscriptsDisabled, NoTranscriptFound
|
|
|
|
| 524 |
(5, "Mathematics", "Ms. Smith", "Intermediate")
|
| 525 |
]
|
| 526 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 527 |
def extract_video_id(url):
|
| 528 |
match = re.search(r"(?:v=|\/)([0-9A-Za-z_-]{11})", url)
|
| 529 |
return match.group(1) if match else None
|
|
|
|
| 548 |
def clean_text_for_analysis(text):
|
| 549 |
return " ".join(text.split())
|
| 550 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 551 |
def get_recommendations(keywords, max_results=5):
|
| 552 |
if not keywords:
|
| 553 |
return "Please provide search keywords"
|
|
|
|
| 575 |
except Exception as e:
|
| 576 |
return f"Error: {str(e)}"
|
| 577 |
|
| 578 |
+
def process_youtube_video(url):
|
| 579 |
try:
|
| 580 |
thumbnail = None
|
| 581 |
summary = "No transcript available"
|
| 582 |
sentiment_label = "N/A"
|
|
|
|
| 583 |
|
| 584 |
video_id = extract_video_id(url)
|
| 585 |
if not video_id:
|
| 586 |
+
return None, "Invalid YouTube URL", "N/A"
|
| 587 |
|
| 588 |
thumbnail = f"https://img.youtube.com/vi/{video_id}/maxresdefault.jpg"
|
| 589 |
|
|
|
|
| 611 |
summary = metadata.get("description", "No subtitles available")
|
| 612 |
sentiment_label = "N/A"
|
| 613 |
|
| 614 |
+
return thumbnail, summary, sentiment_label
|
|
|
|
|
|
|
|
|
|
| 615 |
|
| 616 |
except Exception as e:
|
| 617 |
+
return None, f"Error: {str(e)}", "N/A"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 618 |
|
| 619 |
# Gradio Interface
|
| 620 |
with gr.Blocks(theme=gr.themes.Soft()) as app:
|
|
|
|
| 625 |
password = gr.Textbox(label="Password", type="password")
|
| 626 |
login_btn = gr.Button("Login", variant="primary")
|
| 627 |
login_msg = gr.Markdown()
|
| 628 |
+
|
| 629 |
# Main Interface
|
| 630 |
with gr.Group(visible=False) as main_page:
|
| 631 |
with gr.Row():
|
|
|
|
| 637 |
nav_courses = gr.Button("π Courses")
|
| 638 |
nav_youtube = gr.Button("π₯ YouTube Tool")
|
| 639 |
logout_btn = gr.Button("πͺ Logout", variant="stop")
|
| 640 |
+
|
| 641 |
with gr.Column(scale=3):
|
| 642 |
# Dashboard Content
|
| 643 |
dashboard_page = gr.Group()
|
|
|
|
| 648 |
- π₯ Total Students: {len(students_data)}
|
| 649 |
- π¨βπ« Total Teachers: {len(teachers_data)}
|
| 650 |
- π Total Courses: {len(courses_data)}
|
| 651 |
+
|
| 652 |
### Quick Actions
|
| 653 |
- View student performance
|
| 654 |
- Access course materials
|
| 655 |
- Generate learning insights
|
| 656 |
""")
|
| 657 |
+
|
| 658 |
# Students Content
|
| 659 |
students_page = gr.Group(visible=False)
|
| 660 |
with students_page:
|
|
|
|
| 663 |
value=students_data,
|
| 664 |
headers=["ID", "Name", "Grade", "Program"]
|
| 665 |
)
|
| 666 |
+
|
| 667 |
# Teachers Content
|
| 668 |
teachers_page = gr.Group(visible=False)
|
| 669 |
with teachers_page:
|
|
|
|
| 672 |
value=teachers_data,
|
| 673 |
headers=["ID", "Name", "Subject", "Qualification"]
|
| 674 |
)
|
| 675 |
+
|
| 676 |
# Courses Content
|
| 677 |
courses_page = gr.Group(visible=False)
|
| 678 |
with courses_page:
|
|
|
|
| 681 |
value=courses_data,
|
| 682 |
headers=["ID", "Name", "Instructor", "Level"]
|
| 683 |
)
|
| 684 |
+
|
| 685 |
# YouTube Tool Content
|
| 686 |
youtube_page = gr.Group(visible=False)
|
| 687 |
with youtube_page:
|
|
|
|
| 697 |
placeholder="e.g., python programming, machine learning"
|
| 698 |
)
|
| 699 |
analyze_btn = gr.Button("π Analyze Video", variant="primary")
|
| 700 |
+
recommend_btn = gr.Button("π Get Recommendations", variant="primary")
|
| 701 |
+
|
| 702 |
with gr.Column(scale=1):
|
| 703 |
video_thumbnail = gr.Image(label="Video Preview")
|
| 704 |
+
|
| 705 |
with gr.Row():
|
| 706 |
with gr.Column():
|
| 707 |
summary = gr.Textbox(label="π Summary", lines=8)
|
|
|
|
| 721 |
main_page: gr.update(visible=False),
|
| 722 |
login_msg: "β Invalid credentials"
|
| 723 |
}
|
| 724 |
+
|
| 725 |
def show_page(page_name):
|
| 726 |
updates = {
|
| 727 |
dashboard_page: gr.update(visible=False),
|
|
|
|
| 732 |
}
|
| 733 |
updates[page_name] = gr.update(visible=True)
|
| 734 |
return updates
|
| 735 |
+
|
| 736 |
# Event Handlers
|
| 737 |
login_btn.click(
|
| 738 |
login_check,
|
| 739 |
inputs=[username, password],
|
| 740 |
outputs=[login_page, main_page, login_msg]
|
| 741 |
)
|
| 742 |
+
|
| 743 |
nav_dashboard.click(lambda: show_page(dashboard_page), outputs=list(show_page(dashboard_page).keys()))
|
| 744 |
nav_students.click(lambda: show_page(students_page), outputs=list(show_page(students_page).keys()))
|
| 745 |
nav_teachers.click(lambda: show_page(teachers_page), outputs=list(show_page(teachers_page).keys()))
|
| 746 |
nav_courses.click(lambda: show_page(courses_page), outputs=list(show_page(courses_page).keys()))
|
| 747 |
nav_youtube.click(lambda: show_page(youtube_page), outputs=list(show_page(youtube_page).keys()))
|
| 748 |
+
|
| 749 |
analyze_btn.click(
|
| 750 |
process_youtube_video,
|
| 751 |
+
inputs=[video_url],
|
| 752 |
+
outputs=[video_thumbnail, summary, sentiment]
|
| 753 |
)
|
| 754 |
+
|
| 755 |
+
recommend_btn.click(
|
| 756 |
+
get_recommendations,
|
| 757 |
+
inputs=[keywords],
|
| 758 |
+
outputs=[recommendations]
|
| 759 |
+
)
|
| 760 |
+
|
| 761 |
logout_btn.click(
|
| 762 |
lambda: {
|
| 763 |
login_page: gr.update(visible=True),
|
|
|
|
| 767 |
)
|
| 768 |
|
| 769 |
if __name__ == "__main__":
|
| 770 |
+
app.launch()
|