HarshulNanda/HARM_ML_App_ludwig
1
1import os2from pytube import YouTube3import pytube4from stqdm import stqdm5import pandas as pd6from youtubesearchpython import Video, ResultMode7import streamlit as st8import scrapetube9from categoryPredictor import predictCategoryFor10import pandas as pd11 12@st.experimental_memo13def convert_df(df):14 return df.to_csv(index=False).encode('utf-8')15 16def generate_channel_video_data(of_channel, with_number_of_videos):17 video_urls = []18 c_id = Video.get(of_channel, mode=ResultMode.json, get_upload_date=True)["channel"]["id"]19 videos = scrapetube.get_channel(c_id)20 i = 021 for video in videos:22 video_urls.append("https://www.youtube.com/watch?v="+str(video['videoId']))23 i += 124 if i == with_number_of_videos:25 break26 27 data = {28 "Title": [],29 "Description": [],30 "Category": [],31 "Is Educational?": [],32 "Beyond Exams Category": [],33 }34 35 timer = stqdm(video_urls)36 37 for video in timer:38 timer.set_description("☕️ Have a coffee, while we are generating your dataset. ")39 try:40 v = Video.get(video, mode = ResultMode.json, get_upload_date=True)41 t = v["title"]42 d = v["description"]43 c = v["category"]44 isEdu, isCat, cat_array, sub_array = predictCategoryFor(video)45 data["Description"].append(d)46 data["Category"].append(c)47 data["Title"].append(t)48 data["Is Educational?"].append(isEdu)49 data["Beyond Exams Category"].append(isCat)50 except Exception as e:51 print(e)52 continue53 54 df = pd.DataFrame(data)55 st.dataframe(df)56 csv = convert_df(df)57 58 st.download_button(59 "Download this dataframe",60 csv,61 "file.csv",62 "text/csv",63 key='download-csv'64 )