Sea_Shanty / app.py
aksj's picture
Update app.py
c6c9636
import os
import numpy as np
import gradio as gr
from sklearn.feature_extraction.text import TfidfVectorizer
from sklearn.metrics.pairwise import cosine_similarity
shanty=os.environ.get('SHANTY')
def compute_cosine_similarity(text1, text2):
# Initialize the TfidfVectorizer
tfidf_vectorizer = TfidfVectorizer()
# Fit and transform the texts
tfidf_matrix = tfidf_vectorizer.fit_transform([text1, text2])
# Compute the cosine similarity
similarity_score = cosine_similarity(tfidf_matrix[0:1], tfidf_matrix[1:2])
return similarity_score[0][0]
def text_similarity(text):
score= compute_cosine_similarity(shanty,text)
return score*100
with gr.Blocks() as demo:
gr.Markdown("# Guess the lyrics of the sea shanty! \n ## Each two seconds of video represents a line")
video=gr.PlayableVideo("final_video.mp4")
inp=gr.Textbox(placeholder="Enter lyrics of sea shanty!",label="Prediction")
out=gr.Textbox(label="Your points")
inp.change(text_similarity,inp,out)
demo.launch(show_api=False)