Update app.py with Gradio interface
Browse files
app.py
CHANGED
@@ -1,6 +1,41 @@
|
|
1 |
-
import evaluate
|
2 |
-
from evaluate.utils import launch_gradio_widget
|
|
|
3 |
|
|
|
|
|
4 |
|
|
|
|
|
|
|
|
|
5 |
module = evaluate.load("danieldux/metric_template_1")
|
6 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
# import evaluate
|
2 |
+
# from evaluate.utils import launch_gradio_widget
|
3 |
+
|
4 |
|
5 |
+
# module = evaluate.load("danieldux/metric_template_1")
|
6 |
+
# launch_gradio_widget(module)
|
7 |
|
8 |
+
import evaluate
|
9 |
+
import gradio as gr
|
10 |
+
|
11 |
+
# Load your metric module
|
12 |
module = evaluate.load("danieldux/metric_template_1")
|
13 |
+
|
14 |
+
# Define pre-populated examples
|
15 |
+
examples = [
|
16 |
+
{
|
17 |
+
"references": ["1111", "1112", "1113", "1114"],
|
18 |
+
"predictions": ["1111", "1113", "1120", "1211"],
|
19 |
+
}
|
20 |
+
# {"references": ["It is a sunny day."], "predictions": ["The day is sunny."]}
|
21 |
+
]
|
22 |
+
|
23 |
+
|
24 |
+
# Use the modules "compute" function that takes references and predictions
|
25 |
+
def compute_metric(references, predictions):
|
26 |
+
return module.compute(references=[references], predictions=[predictions])
|
27 |
+
|
28 |
+
|
29 |
+
# Create a Gradio interface
|
30 |
+
iface = gr.Interface(
|
31 |
+
fn=compute_metric,
|
32 |
+
inputs=[
|
33 |
+
gr.inputs.Textbox(lines=2, label="References"),
|
34 |
+
gr.inputs.Textbox(lines=2, label="Predictions"),
|
35 |
+
],
|
36 |
+
outputs="text",
|
37 |
+
examples=examples, # Pass the pre-populated examples here
|
38 |
+
)
|
39 |
+
|
40 |
+
# Launch the interface
|
41 |
+
iface.launch()
|