Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,76 +1,29 @@
|
|
| 1 |
import os
|
| 2 |
import gradio as gr
|
|
|
|
| 3 |
HF_TOKEN = os.getenv('HW_TOKEN')
|
| 4 |
#print (HF_TOKEN)
|
| 5 |
hf_writer = gr.HuggingFaceDatasetSaver(HF_TOKEN, "save_audio")
|
| 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 |
-
global totlines
|
| 31 |
-
print(totlines)
|
| 32 |
-
global cur_line
|
| 33 |
-
if cur_line<totlines-1:
|
| 34 |
-
cur_line+=1
|
| 35 |
-
global file_content
|
| 36 |
-
print (cur_line)
|
| 37 |
-
return [file_content[cur_line],None]
|
| 38 |
-
|
| 39 |
-
def readPrevious():
|
| 40 |
-
global cur_line
|
| 41 |
-
if cur_line>=0:
|
| 42 |
-
cur_line-=1
|
| 43 |
-
#cur_line=current_line
|
| 44 |
-
global file_content
|
| 45 |
-
print (cur_line)
|
| 46 |
-
return [file_content[cur_line],None]
|
| 47 |
-
|
| 48 |
-
demo = gr.Blocks()
|
| 49 |
-
|
| 50 |
-
with demo:
|
| 51 |
-
#dr=gr.Dropdown(["Hindi","Odiya"],value="Odiya",label="Select Language")
|
| 52 |
-
#audio_file = gr.Audio(sources=["microphone","upload"],type="filepath")
|
| 53 |
-
text = gr.Textbox(readPromt())
|
| 54 |
-
#allow_flagging="manual",
|
| 55 |
-
#flagging_callback=hf_writer
|
| 56 |
-
upfile = gr.Audio(
|
| 57 |
-
sources=["microphone","upload"], type="filepath", label="Record"
|
| 58 |
-
)
|
| 59 |
-
#upfile = gr.inputs.Audio(source="upload", type="filepath", label="Upload")
|
| 60 |
-
|
| 61 |
-
with gr.Row():
|
| 62 |
-
b1 = gr.Button("Save")
|
| 63 |
-
b2 = gr.Button("Next")
|
| 64 |
-
b3 = gr.Button("Previous")
|
| 65 |
-
#b4=gr.Button("Clear")
|
| 66 |
-
b2.click(readNext,inputs=None,outputs=[text,upfile])
|
| 67 |
-
b3.click(readPrevious,inputs=None,outputs=[text,upfile])
|
| 68 |
-
#b4.click(lambda: None, outputs=upfile)
|
| 69 |
-
# b1.click(sel_lng, inputs=[dr,mic,upfile], outputs=text)
|
| 70 |
-
#b2.click(text_to_sentiment, inputs=text, outputs=label)
|
| 71 |
-
#callback.setup([text, upfile], "flagged_data_points")
|
| 72 |
-
#callback.setup([text, upfile], hf_writer)
|
| 73 |
-
#b1.click(lambda *args: callback.flag(args), [text, upfile], None, preprocess=False)
|
| 74 |
-
#flagging_callback=hf_writer
|
| 75 |
-
b1.click(lambda *args: hf_writer, [text, upfile], None, preprocess=False)
|
| 76 |
-
demo.launch()
|
|
|
|
| 1 |
import os
|
| 2 |
import gradio as gr
|
| 3 |
+
|
| 4 |
HF_TOKEN = os.getenv('HW_TOKEN')
|
| 5 |
#print (HF_TOKEN)
|
| 6 |
hf_writer = gr.HuggingFaceDatasetSaver(HF_TOKEN, "save_audio")
|
| 7 |
|
| 8 |
+
def calculator(num1, operation, num2):
|
| 9 |
+
if operation == "add":
|
| 10 |
+
return num1 + num2
|
| 11 |
+
elif operation == "subtract":
|
| 12 |
+
return num1 - num2
|
| 13 |
+
elif operation == "multiply":
|
| 14 |
+
return num1 * num2
|
| 15 |
+
elif operation == "divide":
|
| 16 |
+
return num1 / num2
|
| 17 |
+
|
| 18 |
+
|
| 19 |
+
iface = gr.Interface(
|
| 20 |
+
calculator,
|
| 21 |
+
["number", gr.Radio(["add", "subtract", "multiply", "divide"]), "number"],
|
| 22 |
+
"number",
|
| 23 |
+
#description="Check out the crowd-sourced dataset at: [https://huggingface.co/datasets/aliabd/crowdsourced-calculator-demo](https://huggingface.co/datasets/aliabd/crowdsourced-calculator-demo)",
|
| 24 |
+
allow_flagging="manual",
|
| 25 |
+
flagging_options=["wrong sign", "off by one", "other"],
|
| 26 |
+
flagging_callback=hf_writer
|
| 27 |
+
)
|
| 28 |
+
|
| 29 |
+
iface.launch()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|