aksj commited on
Commit
ac4da5e
·
1 Parent(s): 2318389

Upload 2 files

Browse files
Files changed (2) hide show
  1. app.py +32 -0
  2. requirements.txt +2 -0
app.py ADDED
@@ -0,0 +1,32 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import os
2
+
3
+ import numpy as np
4
+ import gradio as gr
5
+ from sklearn.feature_extraction.text import TfidfVectorizer
6
+ from sklearn.metrics.pairwise import cosine_similarity
7
+
8
+ shanty=os.environ.get('SHANTY')
9
+ def compute_cosine_similarity(text1, text2):
10
+ # Initialize the TfidfVectorizer
11
+ tfidf_vectorizer = TfidfVectorizer()
12
+
13
+ # Fit and transform the texts
14
+ tfidf_matrix = tfidf_vectorizer.fit_transform([text1, text2])
15
+
16
+ # Compute the cosine similarity
17
+ similarity_score = cosine_similarity(tfidf_matrix[0:1], tfidf_matrix[1:2])
18
+
19
+ return similarity_score[0][0]
20
+
21
+ def text_similarity(text):
22
+ score= compute_cosine_similarity(shanty,text)
23
+ return score
24
+
25
+ with gr.Blocks() as demo:
26
+ gr.Markdown("# Guess the lyrics of the sea shanty! \n ## Each two seconds of video represents a line")
27
+ video=gr.PlayableVideo("final_video.mp4")
28
+ inp=gr.Textbox(placeholder="Enter lyrics of sea shanty!")
29
+
30
+ out=gr.Textbox()
31
+ inp.change(text_similarity,inp,out)
32
+ demo.launch(show_api=False,share=True)
requirements.txt ADDED
@@ -0,0 +1,2 @@
 
 
 
1
+ numpy
2
+ sklearn