Spaces:
Sleeping
Sleeping
File size: 2,397 Bytes
8802df4 4b4bebd 8802df4 4b4bebd 8802df4 4b4bebd 8802df4 4b4bebd 8802df4 4b4bebd 8802df4 4b4bebd 8802df4 |
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 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 |
import os
import warnings
import gradio as gr
from transformers import pipeline
import re
# Initialize the speech recognition pipeline and transliterator
#p1 = pipeline(task="automatic-speech-recognition", model="cdactvm/w2v-bert-2.0-odia_v1")
#p2 = pipeline(task="automatic-speech-recognition", model="cdactvm/w2v-bert-2.0-hindi_v1")
HF_TOKEN = os.getenv('HW_TOKEN')
hf_writer = gr.HuggingFaceDatasetSaver(HF_TOKEN, "save_audio")
cur_line=0
def readFile():
f=open('prompt.txt')
line_num=0
lines=f.readlines()
line_num = len(lines)
return line_num,lines
totlines,file_content=readFile()
callback = gr.CSVLogger()
def readPromt():
global cur_line
cur_line+=1
global file_content
print (cur_line)
return file_content[cur_line]
def readNext():
global totlines
print(totlines)
global cur_line
if cur_line<totlines-1:
cur_line+=1
global file_content
print (cur_line)
return [file_content[cur_line],None]
def readPrevious():
global cur_line
if cur_line>=0:
cur_line-=1
#cur_line=current_line
global file_content
print (cur_line)
return [file_content[cur_line],None]
demo = gr.Blocks()
with demo:
#dr=gr.Dropdown(["Hindi","Odiya"],value="Odiya",label="Select Language")
#audio_file = gr.Audio(sources=["microphone","upload"],type="filepath")
text = gr.Textbox(readPromt())
upfile = gr.Audio(
sources=["microphone","upload"], type="filepath", label="Record"
)
#upfile = gr.inputs.Audio(source="upload", type="filepath", label="Upload")
with gr.Row():
b1 = gr.Button("Save")
b2 = gr.Button("Next")
b3 = gr.Button("Previous")
#b4=gr.Button("Clear")
b2.click(readNext,inputs=None,outputs=[text,upfile])
b3.click(readPrevious,inputs=None,outputs=[text,upfile])
#b4.click(lambda: None, outputs=upfile)
# b1.click(sel_lng, inputs=[dr,mic,upfile], outputs=text)
#b2.click(text_to_sentiment, inputs=text, outputs=label)
#callback.setup([text, upfile], "flagged_data_points")
#callback.setup([text, upfile], hf_writer)
#b1.click(lambda *args: callback.flag(args), [text, upfile], None, preprocess=False)
flagging_callback=hf_writer
b1.click(lambda *args: flagging_callback, [text, upfile], None, preprocess=False)
demo.launch()
|