Spaces:
Runtime error
Runtime error
Commit
·
146c2ba
1
Parent(s):
b33a8ce
Create app.py
Browse files
app.py
ADDED
@@ -0,0 +1,192 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import os
|
2 |
+
os.system("pip install git+https://github.com/openai/whisper.git")
|
3 |
+
os.system("pip install sentence_transformers")
|
4 |
+
import gradio as gr
|
5 |
+
import whisper
|
6 |
+
from sentence_transformers import SentenceTransformer, util
|
7 |
+
|
8 |
+
|
9 |
+
# from share_btn import community_icon_html, loading_icon_html, share_js
|
10 |
+
|
11 |
+
model = whisper.load_model("medium.en")
|
12 |
+
nlp = SentenceTransformer('multi-qa-mpnet-base-dot-v1')
|
13 |
+
|
14 |
+
|
15 |
+
def transcribe(file):
|
16 |
+
options = dict(task="transcribe", best_of=5)
|
17 |
+
text = model.transcribe(file, **options)["text"]
|
18 |
+
return text.strip()
|
19 |
+
|
20 |
+
|
21 |
+
def similarity:
|
22 |
+
query_embedding = nlp.encode('what is your aadhaar number')
|
23 |
+
passage_embedding = nlp.encode(transcribe)
|
24 |
+
sim_score = util.cos_sim(query_embedding, passage_embedding)
|
25 |
+
return sim_score()
|
26 |
+
|
27 |
+
css = """
|
28 |
+
.gradio-container {
|
29 |
+
font-family: 'IBM Plex Sans', sans-serif;
|
30 |
+
}
|
31 |
+
.gr-button {
|
32 |
+
color: white;
|
33 |
+
border-color: black;
|
34 |
+
background: black;
|
35 |
+
}
|
36 |
+
input[type='range'] {
|
37 |
+
accent-color: black;
|
38 |
+
}
|
39 |
+
.dark input[type='range'] {
|
40 |
+
accent-color: #dfdfdf;
|
41 |
+
}
|
42 |
+
.container {
|
43 |
+
max-width: 730px;
|
44 |
+
margin: auto;
|
45 |
+
padding-top: 1.5rem;
|
46 |
+
}
|
47 |
+
|
48 |
+
.details:hover {
|
49 |
+
text-decoration: underline;
|
50 |
+
}
|
51 |
+
.gr-button {
|
52 |
+
white-space: nowrap;
|
53 |
+
}
|
54 |
+
.gr-button:focus {
|
55 |
+
border-color: rgb(147 197 253 / var(--tw-border-opacity));
|
56 |
+
outline: none;
|
57 |
+
box-shadow: var(--tw-ring-offset-shadow), var(--tw-ring-shadow), var(--tw-shadow, 0 0 #0000);
|
58 |
+
--tw-border-opacity: 1;
|
59 |
+
--tw-ring-offset-shadow: var(--tw-ring-inset) 0 0 0 var(--tw-ring-offset-width) var(--tw-ring-offset-color);
|
60 |
+
--tw-ring-shadow: var(--tw-ring-inset) 0 0 0 calc(3px var(--tw-ring-offset-width)) var(--tw-ring-color);
|
61 |
+
--tw-ring-color: rgb(191 219 254 / var(--tw-ring-opacity));
|
62 |
+
--tw-ring-opacity: .5;
|
63 |
+
}
|
64 |
+
.footer {
|
65 |
+
margin-bottom: 45px;
|
66 |
+
margin-top: 35px;
|
67 |
+
text-align: center;
|
68 |
+
border-bottom: 1px solid #e5e5e5;
|
69 |
+
}
|
70 |
+
.footer>p {
|
71 |
+
font-size: .8rem;
|
72 |
+
display: inline-block;
|
73 |
+
padding: 0 10px;
|
74 |
+
transform: translateY(10px);
|
75 |
+
background: white;
|
76 |
+
}
|
77 |
+
.dark .footer {
|
78 |
+
border-color: #303030;
|
79 |
+
}
|
80 |
+
.dark .footer>p {
|
81 |
+
background: #0b0f19;
|
82 |
+
}
|
83 |
+
.prompt h4{
|
84 |
+
margin: 1.25em 0 .25em 0;
|
85 |
+
font-weight: bold;
|
86 |
+
font-size: 115%;
|
87 |
+
}
|
88 |
+
.animate-spin {
|
89 |
+
animation: spin 1s linear infinite;
|
90 |
+
}
|
91 |
+
@keyframes spin {
|
92 |
+
from {
|
93 |
+
transform: rotate(0deg);
|
94 |
+
}
|
95 |
+
to {
|
96 |
+
transform: rotate(360deg);
|
97 |
+
}
|
98 |
+
}
|
99 |
+
#share-btn-container {
|
100 |
+
display: flex; margin-top: 1.5rem !important; padding-left: 0.5rem !important; padding-right: 0.5rem !important; background-color: #000000; justify-content: center; align-items: center; border-radius: 9999px !important; width: 13rem;
|
101 |
+
}
|
102 |
+
#share-btn {
|
103 |
+
all: initial; color: #ffffff;font-weight: 600; cursor:pointer; font-family: 'IBM Plex Sans', sans-serif; margin-left: 0.5rem !important; padding-top: 0.25rem !important; padding-bottom: 0.25rem !important;
|
104 |
+
}
|
105 |
+
#share-btn * {
|
106 |
+
all: unset;
|
107 |
+
}
|
108 |
+
"""
|
109 |
+
|
110 |
+
block = gr.Blocks(css=css)
|
111 |
+
|
112 |
+
|
113 |
+
|
114 |
+
with block:
|
115 |
+
gr.HTML(
|
116 |
+
"""
|
117 |
+
<div style="text-align: center; max-width: 650px; margin: 0 auto;">
|
118 |
+
<div
|
119 |
+
style="
|
120 |
+
display: inline-flex;
|
121 |
+
align-items: center;
|
122 |
+
gap: 0.8rem;
|
123 |
+
font-size: 1.75rem;
|
124 |
+
"
|
125 |
+
>
|
126 |
+
<svg
|
127 |
+
width="0.65em"
|
128 |
+
height="0.65em"
|
129 |
+
viewBox="0 0 115 115"
|
130 |
+
fill="none"
|
131 |
+
xmlns="http://www.w3.org/2000/svg"
|
132 |
+
>
|
133 |
+
<rect width="23" height="23" fill="white"></rect>
|
134 |
+
<rect y="69" width="23" height="23" fill="white"></rect>
|
135 |
+
<rect x="23" width="23" height="23" fill="#AEAEAE"></rect>
|
136 |
+
<rect x="23" y="69" width="23" height="23" fill="#AEAEAE"></rect>
|
137 |
+
<rect x="46" width="23" height="23" fill="white"></rect>
|
138 |
+
<rect x="46" y="69" width="23" height="23" fill="white"></rect>
|
139 |
+
<rect x="69" width="23" height="23" fill="black"></rect>
|
140 |
+
<rect x="69" y="69" width="23" height="23" fill="black"></rect>
|
141 |
+
<rect x="92" width="23" height="23" fill="#D9D9D9"></rect>
|
142 |
+
<rect x="92" y="69" width="23" height="23" fill="#AEAEAE"></rect>
|
143 |
+
<rect x="115" y="46" width="23" height="23" fill="white"></rect>
|
144 |
+
<rect x="115" y="115" width="23" height="23" fill="white"></rect>
|
145 |
+
<rect x="115" y="69" width="23" height="23" fill="#D9D9D9"></rect>
|
146 |
+
<rect x="92" y="46" width="23" height="23" fill="#AEAEAE"></rect>
|
147 |
+
<rect x="92" y="115" width="23" height="23" fill="#AEAEAE"></rect>
|
148 |
+
<rect x="92" y="69" width="23" height="23" fill="white"></rect>
|
149 |
+
<rect x="69" y="46" width="23" height="23" fill="white"></rect>
|
150 |
+
<rect x="69" y="115" width="23" height="23" fill="white"></rect>
|
151 |
+
<rect x="69" y="69" width="23" height="23" fill="#D9D9D9"></rect>
|
152 |
+
<rect x="46" y="46" width="23" height="23" fill="black"></rect>
|
153 |
+
<rect x="46" y="115" width="23" height="23" fill="black"></rect>
|
154 |
+
<rect x="46" y="69" width="23" height="23" fill="black"></rect>
|
155 |
+
<rect x="23" y="46" width="23" height="23" fill="#D9D9D9"></rect>
|
156 |
+
<rect x="23" y="115" width="23" height="23" fill="#AEAEAE"></rect>
|
157 |
+
<rect x="23" y="69" width="23" height="23" fill="black"></rect>
|
158 |
+
</svg>
|
159 |
+
<h1 style="font-weight: 900; margin-bottom: 7px;">
|
160 |
+
Talking Yak
|
161 |
+
</h1>
|
162 |
+
</div>
|
163 |
+
<p style="margin-bottom: 10px; font-size: 94%">
|
164 |
+
Speech to Text Engine [Testing V2]
|
165 |
+
</p>
|
166 |
+
</div>
|
167 |
+
"""
|
168 |
+
)
|
169 |
+
|
170 |
+
with gr.Group():
|
171 |
+
audio = gr.Audio(
|
172 |
+
show_label=False,
|
173 |
+
source="microphone",
|
174 |
+
type="filepath"
|
175 |
+
)
|
176 |
+
with gr.Box():
|
177 |
+
with gr.Row().style(equal_height=True):
|
178 |
+
transcribe_button = gr.Button("Transcribe")
|
179 |
+
sim-score-b = gr.Button("Transcribe")
|
180 |
+
|
181 |
+
|
182 |
+
textbox1 = gr.Textbox(label="Transcription")
|
183 |
+
textbox2 = gr.Textbox()
|
184 |
+
label = gr.Label()
|
185 |
+
|
186 |
+
text = gr.Textbox()
|
187 |
+
|
188 |
+
transcribe_button.click(transcribe, inputs=[audio], outputs=[textbox1])
|
189 |
+
sim-score-b.click(similarity, inputs=textbox2, outputs=label)
|
190 |
+
|
191 |
+
|
192 |
+
block.launch()
|