themechanism commited on
Commit
f73471d
·
verified ·
1 Parent(s): fa3603e

Fix Gradio app runtime

Browse files
Files changed (2) hide show
  1. app.py +55 -4
  2. requirements.txt +1 -0
app.py CHANGED
@@ -1,6 +1,57 @@
1
- import evaluate
2
- from evaluate.utils import launch_gradio_widget
3
 
 
4
 
5
- module = evaluate.load("themechanism/script_fidelity_rate", module_type="metric")
6
- launch_gradio_widget(module)
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import gradio as gr
 
2
 
3
+ from script_fidelity import compute_corpus_sfr, list_languages
4
 
5
+
6
+ EXAMPLE_TEXT = "کابل کې ښه هوا ده\nromanized output"
7
+
8
+
9
+ def _score(predictions_text: str, language: str, digit_policy: str) -> dict:
10
+ predictions = [
11
+ line.strip()
12
+ for line in (predictions_text or "").splitlines()
13
+ if line.strip()
14
+ ]
15
+ if not predictions:
16
+ return {"error": "Enter at least one prediction."}
17
+
18
+ return compute_corpus_sfr(
19
+ predictions,
20
+ language=language,
21
+ digit_policy=digit_policy,
22
+ return_details=True,
23
+ )
24
+
25
+
26
+ with gr.Blocks(title="Script Fidelity Rate") as demo:
27
+ gr.Markdown(
28
+ "# Script Fidelity Rate\n"
29
+ "Reference-free script check for multilingual ASR. "
30
+ "Enter one prediction per line."
31
+ )
32
+ with gr.Row():
33
+ language = gr.Dropdown(
34
+ choices=list_languages(),
35
+ value="ps_af",
36
+ label="FLEURS language",
37
+ )
38
+ digit_policy = gr.Radio(
39
+ choices=["count", "ignore"],
40
+ value="count",
41
+ label="Digit policy",
42
+ )
43
+
44
+ predictions = gr.Textbox(
45
+ value=EXAMPLE_TEXT,
46
+ lines=6,
47
+ label="Predictions",
48
+ )
49
+ button = gr.Button("Compute SFR")
50
+ output = gr.JSON(label="Result")
51
+
52
+ button.click(_score, [predictions, language, digit_policy], output)
53
+ predictions.submit(_score, [predictions, language, digit_policy], output)
54
+
55
+
56
+ if __name__ == "__main__":
57
+ demo.launch()
requirements.txt CHANGED
@@ -1,2 +1,3 @@
1
  evaluate>=0.4.0,<1.0
 
2
  script-fidelity>=0.1.1
 
1
  evaluate>=0.4.0,<1.0
2
+ gradio>=4.44,<6
3
  script-fidelity>=0.1.1