File size: 1,509 Bytes
ecd5dc6
 
 
9fa3156
ecd5dc6
 
9fa3156
 
 
ecd5dc6
 
 
f8b4416
e3fd79c
ecd5dc6
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
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
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
import sys
from pathlib import Path

import evaluate
import gradio as gr
from evaluate import parse_readme


module = evaluate.load("sunhill/cider")


def compute_cider(references, predictions):
    predictions = [predictions]
    references = [[ref.strip() for ref in references.split(";") if ref.strip()]]
    return module.compute(predictions=predictions, references=references)["cider_score"]


iface = gr.Interface(
    fn=compute_cider,
    inputs=[
        gr.Textbox(
            label="References",
            placeholder="Enter reference texts here, separated by semicolon... (e.g. ref1; ref2; ref3)",
        ),
        gr.Textbox(
            label="Predictions",
            placeholder="Enter prediction text here, Only one prediction is allowed...",
        ),
    ],
    outputs=gr.Number(label="CIDEr Score"),
    title="CIDEr Score Evaluator",
    description="Evaluate the alignment between an image and a text using CIDEr Score.",
    examples=[
        [
            (
                "a train traveling down tracks next to lights; "
                "a blue and silver train next to train station and trees; "
                "a blue train is next to a sidewalk on the rails; "
                "a passenger train pulls into a train station; "
                "a train coming down the tracks arriving at a station;"
            ),
            "train traveling down a track in front of a road",
        ]
    ],
    article=parse_readme(Path(sys.path[0]) / "README.md"),
)

iface.launch()