Spaces:
Sleeping
Sleeping
File size: 2,222 Bytes
ba4f5fa 895148c ba4f5fa 353a82a a92a67c 3ff7897 a92a67c 353a82a a92a67c 353a82a 446ddfb 353a82a 4827549 353a82a 446ddfb 353a82a 2c20c7f 353a82a |
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 |
import os
import warnings
import gradio as gr
import re
HF_TOKEN = os.getenv('HW_TOKEN')
hf_writer = gr.HuggingFaceDatasetSaver(HF_TOKEN, "save_audio")
cur_line=-1
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 = hf_writer
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())
#allow_flagging="manual",
#flagging_callback=hf_writer
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_audio_files")
#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: hf_writer, [text, upfile], None, preprocess=False)
#b1.click(lambda *args: hf_writer, [text, upfile])
demo.launch()
|