File size: 1,497 Bytes
611706a 25133b6 611706a 25133b6 611706a 633bd30 611706a 633bd30 611706a 633bd30 611706a 633bd30 611706a |
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/spice")
def compute_spice(references, predictions):
predictions = [[predictions]]
references = [[ref.strip() for ref in references.split(";") if ref.strip()]]
return module.compute(predictions=predictions, references=references)[0]
iface = gr.Interface(
fn=compute_spice,
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.JSON(label="SPICE Score"),
title="SPICE Score Evaluator",
description="Evaluate the alignment between an image and a text using SPICE 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()
|