Spaces:
Sleeping
Sleeping
File size: 1,031 Bytes
ac4da5e c8d110e ac4da5e c6c9636 ac4da5e c8d110e ac4da5e eb2c45c |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 |
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) |