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
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import os
|
| 2 |
+
import gradio as gr
|
| 3 |
+
import time
|
| 4 |
+
|
| 5 |
+
list_stack=[]
|
| 6 |
+
api_url='http://b25a-34-125-207-233.ngrok.io/upload'
|
| 7 |
+
|
| 8 |
+
def get_transcription_whissper_api(audio,api_url=api_url):
|
| 9 |
+
audio_file = open(audio, 'rb')
|
| 10 |
+
files = {'audio': ('audio.wav', audio_file)}
|
| 11 |
+
|
| 12 |
+
response = requests.post(api_url, files=files)
|
| 13 |
+
json_response = response.json()
|
| 14 |
+
|
| 15 |
+
if response.status_code == 200:
|
| 16 |
+
print("Audio file uploaded successfully.")
|
| 17 |
+
return(json_response['message'])
|
| 18 |
+
else:
|
| 19 |
+
return("Error uploading the audio file.")
|
| 20 |
+
|
| 21 |
+
def empty_list():
|
| 22 |
+
list_stack.clear()
|
| 23 |
+
|
| 24 |
+
def inference_upload(audio,state=""):
|
| 25 |
+
state+= get_transcription_whissper_api(audio)+" "
|
| 26 |
+
return (state,state)
|
| 27 |
+
|
| 28 |
+
def inference(audio,state=""):
|
| 29 |
+
state += get_transcription_whissper_api(audio) + " "
|
| 30 |
+
delimiter=" "
|
| 31 |
+
list_stack.append(state)
|
| 32 |
+
all_transcriptions=(delimiter.join(list_stack))
|
| 33 |
+
return (state,all_transcriptions)
|
| 34 |
+
|
| 35 |
+
|
| 36 |
+
css = """
|
| 37 |
+
.gradio-container {
|
| 38 |
+
font-family: 'IBM Plex Sans', sans-serif;
|
| 39 |
+
}
|
| 40 |
+
.gr-button {
|
| 41 |
+
color: white;
|
| 42 |
+
border-color: black;
|
| 43 |
+
background: black;
|
| 44 |
+
}
|
| 45 |
+
input[type='range'] {
|
| 46 |
+
accent-color: black;
|
| 47 |
+
}
|
| 48 |
+
.dark input[type='range'] {
|
| 49 |
+
accent-color: #dfdfdf;
|
| 50 |
+
}
|
| 51 |
+
.container {
|
| 52 |
+
max-width: 1030px;
|
| 53 |
+
margin: auto;
|
| 54 |
+
padding-top: 1.5rem;
|
| 55 |
+
}
|
| 56 |
+
|
| 57 |
+
.details:hover {
|
| 58 |
+
text-decoration: underline;
|
| 59 |
+
}
|
| 60 |
+
.gr-button {
|
| 61 |
+
white-space: nowrap;
|
| 62 |
+
}
|
| 63 |
+
.gr-button:focus {
|
| 64 |
+
border-color: rgb(147 197 253 / var(--tw-border-opacity));
|
| 65 |
+
outline: none;
|
| 66 |
+
box-shadow: var(--tw-ring-offset-shadow), var(--tw-ring-shadow), var(--tw-shadow, 0 0 #0000);
|
| 67 |
+
--tw-border-opacity: 1;
|
| 68 |
+
--tw-ring-offset-shadow: var(--tw-ring-inset) 0 0 0 var(--tw-ring-offset-width) var(--tw-ring-offset-color);
|
| 69 |
+
--tw-ring-shadow: var(--tw-ring-inset) 0 0 0 calc(3px var(--tw-ring-offset-width)) var(--tw-ring-color);
|
| 70 |
+
--tw-ring-color: rgb(191 219 254 / var(--tw-ring-opacity));
|
| 71 |
+
--tw-ring-opacity: .5;
|
| 72 |
+
}
|
| 73 |
+
.footer {
|
| 74 |
+
margin-bottom: 45px;
|
| 75 |
+
margin-top: 35px;
|
| 76 |
+
text-align: center;
|
| 77 |
+
border-bottom: 1px solid #e5e5e5;
|
| 78 |
+
}
|
| 79 |
+
.footer>p {
|
| 80 |
+
font-size: .8rem;
|
| 81 |
+
display: inline-block;
|
| 82 |
+
padding: 0 10px;
|
| 83 |
+
transform: translateY(10px);
|
| 84 |
+
background: white;
|
| 85 |
+
}
|
| 86 |
+
.dark .footer {
|
| 87 |
+
border-color: #303030;
|
| 88 |
+
}
|
| 89 |
+
.dark .footer>p {
|
| 90 |
+
background: #0b0f19;
|
| 91 |
+
}
|
| 92 |
+
.prompt h4{
|
| 93 |
+
margin: 1.25em 0 .25em 0;
|
| 94 |
+
font-weight: bold;
|
| 95 |
+
font-size: 115%;
|
| 96 |
+
}
|
| 97 |
+
.animate-spin {
|
| 98 |
+
animation: spin 1s linear infinite;
|
| 99 |
+
}
|
| 100 |
+
@keyframes spin {
|
| 101 |
+
from {
|
| 102 |
+
transform: rotate(0deg);
|
| 103 |
+
}
|
| 104 |
+
to {
|
| 105 |
+
transform: rotate(360deg);
|
| 106 |
+
}
|
| 107 |
+
}
|
| 108 |
+
#share-btn-container {
|
| 109 |
+
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;
|
| 110 |
+
}
|
| 111 |
+
#share-btn {
|
| 112 |
+
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;
|
| 113 |
+
}
|
| 114 |
+
#share-btn * {
|
| 115 |
+
all: unset;
|
| 116 |
+
}
|
| 117 |
+
"""
|
| 118 |
+
|
| 119 |
+
block = gr.Blocks(css=css)
|
| 120 |
+
|
| 121 |
+
with block:
|
| 122 |
+
gr.HTML(
|
| 123 |
+
"""
|
| 124 |
+
<div style="text-align: center; max-width: 1050px; margin: 0 auto;">
|
| 125 |
+
<div
|
| 126 |
+
style="
|
| 127 |
+
display: inline-flex;
|
| 128 |
+
align-items: center;
|
| 129 |
+
gap: 0.8rem;
|
| 130 |
+
font-size: 1.75rem;
|
| 131 |
+
"
|
| 132 |
+
>
|
| 133 |
+
<svg
|
| 134 |
+
width="0.65em"
|
| 135 |
+
height="0.65em"
|
| 136 |
+
viewBox="0 0 115 115"
|
| 137 |
+
fill="none"
|
| 138 |
+
xmlns="http://www.w3.org/2000/svg"
|
| 139 |
+
>
|
| 140 |
+
<rect width="23" height="23" fill="white"></rect>
|
| 141 |
+
<rect y="69" width="23" height="23" fill="white"></rect>
|
| 142 |
+
<rect x="23" width="23" height="23" fill="#AEAEAE"></rect>
|
| 143 |
+
<rect x="23" y="69" width="23" height="23" fill="#AEAEAE"></rect>
|
| 144 |
+
<rect x="46" width="23" height="23" fill="white"></rect>
|
| 145 |
+
<rect x="46" y="69" width="23" height="23" fill="white"></rect>
|
| 146 |
+
<rect x="69" width="23" height="23" fill="black"></rect>
|
| 147 |
+
<rect x="69" y="69" width="23" height="23" fill="black"></rect>
|
| 148 |
+
<rect x="92" width="23" height="23" fill="#D9D9D9"></rect>
|
| 149 |
+
<rect x="92" y="69" width="23" height="23" fill="#AEAEAE"></rect>
|
| 150 |
+
<rect x="115" y="46" width="23" height="23" fill="white"></rect>
|
| 151 |
+
<rect x="115" y="115" width="23" height="23" fill="white"></rect>
|
| 152 |
+
<rect x="115" y="69" width="23" height="23" fill="#D9D9D9"></rect>
|
| 153 |
+
<rect x="92" y="46" width="23" height="23" fill="#AEAEAE"></rect>
|
| 154 |
+
<rect x="92" y="115" width="23" height="23" fill="#AEAEAE"></rect>
|
| 155 |
+
<rect x="92" y="69" width="23" height="23" fill="white"></rect>
|
| 156 |
+
<rect x="69" y="46" width="23" height="23" fill="white"></rect>
|
| 157 |
+
<rect x="69" y="115" width="23" height="23" fill="white"></rect>
|
| 158 |
+
<rect x="69" y="69" width="23" height="23" fill="#D9D9D9"></rect>
|
| 159 |
+
<rect x="46" y="46" width="23" height="23" fill="black"></rect>
|
| 160 |
+
<rect x="46" y="115" width="23" height="23" fill="black"></rect>
|
| 161 |
+
<rect x="46" y="69" width="23" height="23" fill="black"></rect>
|
| 162 |
+
<rect x="23" y="46" width="23" height="23" fill="#D9D9D9"></rect>
|
| 163 |
+
<rect x="23" y="115" width="23" height="23" fill="#AEAEAE"></rect>
|
| 164 |
+
<rect x="23" y="69" width="23" height="23" fill="black"></rect>
|
| 165 |
+
</svg>
|
| 166 |
+
<h1 style="font-weight: 900; margin-bottom: 7px;">
|
| 167 |
+
Experiment Whisper via API
|
| 168 |
+
</h1>
|
| 169 |
+
</div>
|
| 170 |
+
<p style="margin-bottom: 10px; font-size: 94%">
|
| 171 |
+
This page can be used to simply try out the capabilities of tagaloc + english transcription. The model used is the smallest because this process only runs with small computations. Speed and accuracy can be improved with more powerful computing.</p>
|
| 172 |
+
</div>
|
| 173 |
+
|
| 174 |
+
"""
|
| 175 |
+
)
|
| 176 |
+
|
| 177 |
+
with gr.Group():
|
| 178 |
+
with gr.Box():
|
| 179 |
+
with gr.Row().style(mobile_collapse=False, equal_height=True):
|
| 180 |
+
audio = gr.Audio(
|
| 181 |
+
label="Input voice",
|
| 182 |
+
source="microphone",
|
| 183 |
+
type="filepath",
|
| 184 |
+
streaming=True
|
| 185 |
+
)
|
| 186 |
+
audio_file_upload = gr.Audio(
|
| 187 |
+
label="Input From Example",
|
| 188 |
+
source="upload",
|
| 189 |
+
type="filepath",
|
| 190 |
+
)
|
| 191 |
+
btn_clear = gr.Button("Clear")
|
| 192 |
+
btn_trnscribe = gr.Button("Transcribe")
|
| 193 |
+
text = gr.Textbox(label="Transcriptions Now", elem_id="result-textarea")
|
| 194 |
+
text_all = gr.Textbox(label="All Transcriptions", elem_id="result-textarea")
|
| 195 |
+
btn_clear.click(empty_list)
|
| 196 |
+
btn_trnscribe.click(inference_upload,inputs=audio_file_upload,outputs=[text,text_all],show_progress="minimal")
|
| 197 |
+
audio.stream(inference,inputs=audio,outputs=[text,text_all],show_progress="minimal")
|
| 198 |
+
gr.HTML("""
|
| 199 |
+
<h2 style="font-weight: 900; margin: 7px;">
|
| 200 |
+
Tagaloc audio
|
| 201 |
+
</h2>
|
| 202 |
+
""")
|
| 203 |
+
example_gr_bark = gr.Examples(
|
| 204 |
+
examples=[
|
| 205 |
+
["#1 Akan ada berkat yang selalu baru setiap hari Ps Jonjset.mp3"],
|
| 206 |
+
["#2 Jangan lagi kecewa Ps Jonjset.mp3"],
|
| 207 |
+
["#3 Tetaplah kuat di dalam TUHAN Pdt Jonatan Jap Setiawan.mp3"]
|
| 208 |
+
],
|
| 209 |
+
inputs = audio_file_upload
|
| 210 |
+
)
|
| 211 |
+
|
| 212 |
+
gr.HTML('''
|
| 213 |
+
<div class="footer">
|
| 214 |
+
<p>Model by openAI</a> - Gradio Demo by 🤗 Hugging Face
|
| 215 |
+
</p>
|
| 216 |
+
</div>
|
| 217 |
+
''')
|
| 218 |
+
|
| 219 |
+
if __name__ == "__main__":
|
| 220 |
+
block.launch(debug=True)
|