Spaces:
Runtime error
Runtime error
orionweller
commited on
Commit
•
84e0a22
1
Parent(s):
ef64719
finished
Browse files
app.py
CHANGED
@@ -6,8 +6,8 @@ import random
|
|
6 |
random.seed(42)
|
7 |
|
8 |
raw_datasets = load_dataset("eli5")
|
9 |
-
validation_len = len(raw_datasets["
|
10 |
-
random_insts = [random.randint(validation_len)]
|
11 |
questions = []
|
12 |
q2ref = {}
|
13 |
for inst in random_insts:
|
@@ -17,14 +17,15 @@ for inst in random_insts:
|
|
17 |
q2ref[question] = ref
|
18 |
|
19 |
def calc_rouge_score(og_question, pred):
|
20 |
-
preds = gem_metrics.texts.Predictions(pred)
|
21 |
gold = q2ref[og_question]
|
22 |
-
refs = gem_metrics.texts.References(gold)
|
23 |
result = gem_metrics.compute(preds, refs, metrics_list=['bleu', 'rouge'])
|
24 |
return result
|
25 |
|
26 |
iface = gr.Interface(
|
27 |
fn=calc_rouge_score,
|
28 |
inputs=[gr.Dropdown(questions), "text"],
|
29 |
-
outputs=["text"]
|
|
|
30 |
iface.launch()
|
|
|
6 |
random.seed(42)
|
7 |
|
8 |
raw_datasets = load_dataset("eli5")
|
9 |
+
validation_len = len(raw_datasets["validation_eli5"])
|
10 |
+
random_insts = [random.randint(0, validation_len) for _ in range(10)]
|
11 |
questions = []
|
12 |
q2ref = {}
|
13 |
for inst in random_insts:
|
|
|
17 |
q2ref[question] = ref
|
18 |
|
19 |
def calc_rouge_score(og_question, pred):
|
20 |
+
preds = gem_metrics.texts.Predictions([pred])
|
21 |
gold = q2ref[og_question]
|
22 |
+
refs = gem_metrics.texts.References([gold])
|
23 |
result = gem_metrics.compute(preds, refs, metrics_list=['bleu', 'rouge'])
|
24 |
return result
|
25 |
|
26 |
iface = gr.Interface(
|
27 |
fn=calc_rouge_score,
|
28 |
inputs=[gr.Dropdown(questions), "text"],
|
29 |
+
outputs=["text"],
|
30 |
+
examples=[[item] for item in questions])
|
31 |
iface.launch()
|