asigalov61 commited on
Commit
652002d
·
verified ·
1 Parent(s): 2feefcc

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +54 -4
app.py CHANGED
@@ -1,7 +1,57 @@
 
 
1
  import gradio as gr
2
 
3
- def greet(name):
4
- return "Hello " + name + "!!"
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
5
 
6
- iface = gr.Interface(fn=greet, inputs="text", outputs="text")
7
- iface.launch()
 
1
+ import pickle
2
+
3
  import gradio as gr
4
 
5
+ def classify_lyrics(lyric):
6
+
7
+ search_query = lyric
8
+
9
+ text_search_query = [at.split(chr(32)) for at in search_query.lower().split(chr(10))]
10
+
11
+ tsq = []
12
+ for t in text_search_query:
13
+ for tt in t:
14
+ tsq.append(''.join(filter(str.isalpha, tt.lower())))
15
+ clean_text_search_query = list(dict.fromkeys(tsq))
16
+
17
+ clean_text_search_query_set = set(clean_text_search_query)
18
+
19
+ random.shuffle(lyrics_set_final)
20
+
21
+ texts_match_ratios = []
22
+
23
+ for l in tqdm.tqdm(lyrics_set_final):
24
+
25
+ text_set = set(l[2])
26
+
27
+ word_match_count = len(clean_text_search_query_set & text_set)
28
+
29
+ match_ratio = word_match_count / len(min(clean_text_search_query_set, text_set))
30
+
31
+ words_match_consequtive_ratio = sum([1 if a == b else 0 for a, b in zip(clean_text_search_query, l[2])]) / len(min(clean_text_search_query, l[2]))
32
+
33
+ texts_match_ratios.append((match_ratio + words_match_consequtive_ratio) / 2)
34
+
35
+ sorted_texts_match_ratios = sorted(set(texts_match_ratios), reverse=True)
36
+
37
+ result = lyrics_set_final[texts_match_ratios.index(sorted_texts_match_ratios[0])][:2]
38
+
39
+ print(result, texts_match_ratios.index(sorted_texts_match_ratios[0]), texts_match_ratios.count(sorted_texts_match_ratios[0]))
40
+
41
+ return texts_match_ratios.index(sorted_texts_match_ratios[0]), result[0], result[1]
42
+
43
+ demo = gr.Interface(
44
+ fn=classify_lyrics,
45
+ inputs=["text"],
46
+ outputs=["number", "text", "text"],
47
+ )
48
+
49
+ if __name__ == "__main__":
50
+
51
+ print('Loading data...')
52
+ with open('English_Lyrics_Ordered_Sets_Small_1358353.pickle', 'rb') as f:
53
+ lyrics_set_final = pickle.load(f)
54
+ print('Done!')
55
 
56
+
57
+ demo.launch()