Sajjo commited on
Commit
f44e8ad
·
verified ·
1 Parent(s): 47e7cfd

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +79 -0
app.py CHANGED
@@ -0,0 +1,79 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import os
2
+ import warnings
3
+ import gradio as gr
4
+ import re
5
+
6
+ HF_TOKEN = os.getenv('HF_TOKEN')
7
+ hf_writer = gr.HuggingFaceDatasetSaver(HF_TOKEN, "save_audio_kannada_numbers")
8
+
9
+
10
+ cur_line=-1
11
+
12
+ def readFile():
13
+ f=open('kannada_numbers.txt')
14
+ line_num=0
15
+ lines=f.readlines()
16
+ line_num = len(lines)
17
+ return line_num,lines
18
+
19
+ totlines,file_content=readFile()
20
+
21
+ callback = hf_writer
22
+
23
+ def readPromt():
24
+ global cur_line
25
+ cur_line+=1
26
+ global file_content
27
+ print (cur_line)
28
+ return file_content[cur_line]
29
+
30
+ def readNext():
31
+
32
+ global totlines
33
+ print(totlines)
34
+ global cur_line
35
+ if cur_line<totlines-1:
36
+ cur_line+=1
37
+ global file_content
38
+ print (cur_line)
39
+ return [file_content[cur_line],None]
40
+
41
+ def readPrevious():
42
+ global cur_line
43
+ if cur_line>=0:
44
+ cur_line-=1
45
+ #cur_line=current_line
46
+ global file_content
47
+ print (cur_line)
48
+ return [file_content[cur_line],None]
49
+
50
+ demo = gr.Blocks()
51
+
52
+ with demo:
53
+ #dr=gr.Dropdown(["Hindi","Odiya"],value="Odiya",label="Select Language")
54
+ #audio_file = gr.Audio(sources=["microphone","upload"],type="filepath")
55
+ text = gr.Textbox(readPromt())
56
+ #allow_flagging="manual",
57
+ #flagging_callback=hf_writer
58
+ upfile = gr.Audio(
59
+ sources=["microphone","upload"], type="filepath", label="Record"
60
+ )
61
+ #upfile = gr.inputs.Audio(source="upload", type="filepath", label="Upload")
62
+
63
+ with gr.Row():
64
+ b1 = gr.Button("Save")
65
+ b2 = gr.Button("Next")
66
+ b3 = gr.Button("Previous")
67
+ #b4=gr.Button("Clear")
68
+ b2.click(readNext,inputs=None,outputs=[text,upfile])
69
+ b3.click(readPrevious,inputs=None,outputs=[text,upfile])
70
+ #b4.click(lambda: None, outputs=upfile)
71
+ # b1.click(sel_lng, inputs=[dr,mic,upfile], outputs=text)
72
+ #b2.click(text_to_sentiment, inputs=text, outputs=label)
73
+ callback.setup([text, upfile], "flagged_audio_files")
74
+ #callback.setup([text, upfile], hf_writer)
75
+ b1.click(lambda *args: callback.flag(args), [text, upfile], None, preprocess=False)
76
+ #flagging_callback=hf_writer
77
+ #b1.click(lambda *args: hf_writer, [text, upfile], None, preprocess=False)
78
+ ##b1.click(lambda *args: hf_writer, [text, upfile])
79
+ demo.launch()