CoolFace
Apppublic

HarshulNanda/HARM_ML_App_ludwig

sourceHugging Faceupdated 3y agoView on Hugging Face
1likes
eduContentPredictor.py31 linesDownload Raw Back to root
1from youtubesearchpython import Transcript, Video, ResultMode2import pickle3from stqdm import stqdm4import pandas as pd5 6def eduContentPrediction(url):7    segments = Transcript.get(url)["segments"]8    E = 09    NonE = 010    # education_model = pickle.load(open("./models/educated_model.pkl", "rb"))11    12    education_classifier = pickle.load(open("./models/ludwig_edu.pkl", "rb"))13 14    timer = stqdm(segments)15 16    for segment in timer:17        timer.set_description("☕️ Have a coffee, while we apply our model on the video transcript.  ")18        text_to_predict = pd.DataFrame({19            "text": [20                str(segment["text"]),21            ]22        })23        edu_pred, _ = education_classifier.predict(text_to_predict)24        text_prediction = list(edu_pred.category_predictions)[0]25        # text_prediction = education_model.predict(text)[0]26        if text_prediction == "Education":27            E += 128        else:29            NonE += 130 31    return "The {:.2f}% portion of this video is educational.".format(E*100/(E+NonE))