libraxiong commited on
Commit
e0e6ed0
·
verified ·
1 Parent(s): 79e040a

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +45 -3
app.py CHANGED
@@ -1,6 +1,48 @@
 
1
  import evaluate
2
- from evaluate.utils import launch_gradio_widget
 
 
 
 
 
 
 
3
 
 
 
 
4
 
5
- module = evaluate.load("libraxiong/oppo_refuse_match")
6
- launch_gradio_widget(module)
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from evaluate.utils import launch_gradio_widget,parse_readme
2
  import evaluate
3
+ import os
4
+ # os.environ['http_proxy']='http://localhost:7890'
5
+ # os.environ['https_proxy']='http://localhost:7890'
6
+ import gradio as gr
7
+ from evaluate.utils.gradio import infer_gradio_input_types,json_to_string_type,parse_gradio_data
8
+ from pathlib import Path
9
+ from datasets import Value
10
+ import sys
11
 
12
+ def cal_oppo_refuse_match(predictions):
13
+ refuse=evaluate.load('libraxiong/oppo_refuse_match')
14
+ return refuse.compute(predictions=predictions)
15
 
16
+ def launch_gradio_widget(metric):
17
+ """Launches `metric` widget with Gradio."""
18
+ # del os.environ['http_proxy']
19
+ # del os.environ['https_proxy']
20
+ # os.environ['no_proxy']='localhost, 127.0.0.1, ::1'
21
+ try:
22
+ import gradio as gr
23
+ except ImportError as error:
24
+ # logger.error("To create a metric widget with Gradio make sure gradio is installed.")
25
+ raise error
26
+
27
+ local_path = Path(sys.path[0])
28
+ def compute(data):
29
+ print(data)
30
+ data=eval(data)
31
+ return metric.compute(predictions=data)
32
+
33
+ iface = gr.Interface(
34
+ fn=compute,
35
+ inputs=gr.Textbox(label=metric.name),
36
+ outputs=gr.Textbox(label=metric.name),
37
+ description=(
38
+ metric.info.description + "\nIf this is a text-based metric. Just input the predictions,the format is ['some','some']"
39
+ ),
40
+ title=f"Metric: {metric.name}",
41
+ article=parse_readme(local_path / "README.md"),
42
+ # TODO: load test cases and use them to populate examples
43
+ # examples=[parse_test_cases(test_cases, feature_names, gradio_input_types)]
44
+ )
45
+
46
+ iface.launch()
47
+ if __name__=='__main__':
48
+ launch_gradio_widget(evaluate.load('libraxiong/oppo_refuse_match'))