spice / app.py
sunhill's picture
add jdk11 dependency
633bd30
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()