| 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() |
|
|