iSPICE-Metric / app.py
dnaveenr's picture
add iSPICE files.
d7c3bb9
raw
history blame
1.89 kB
import streamlit as st
from ispice import Spice
# Function to compute score
def preprocess_captions(generated_captions, reference_captions):
hypotheses = {'image'+str(i): [generated_captions[i]] for i in range(len(generated_captions))}
references = {'image'+str(i): [reference_captions[i]] for i in range(len(reference_captions))}
return hypotheses, references
# Streamlit app
def main():
st.title("iSPICE Metric Evaluation")
# Dropdown for comparison option
mode = st.selectbox("Mode:", ["ID", "Name"])
spice_scorer = Spice(mode=mode)
# Description
st.write("You can either input single caption or multiple captions separated by new line.")
# Input text boxes
generated_caption = st.text_area("Generated Caption:", "")
reference_caption = st.text_area("Reference Caption:", "")
# Compute score button
if st.button("Compute Score"):
generated_captions = generated_caption.split("\n")
reference_captions = reference_caption.split("\n")
print(generated_captions, len(generated_captions))
print(reference_captions, len(reference_captions))
hypotheses, references = preprocess_captions(generated_captions, reference_captions)
if generated_caption.strip() == "" or reference_caption.strip() == "":
st.error("Please provide both generated and reference captions.")
else:
average_spice_score, spice_scores, average_ispice_score, ispice_scores = spice_scorer.compute_score(references, hypotheses)
st.subheader("Scores :")
st.write("Average SPICE Score:", average_spice_score)
st.write("Average iSPICE Score:", average_ispice_score)
st.write("SPICE Scores:", spice_scores)
st.write("iSPICE Scores:", ispice_scores)
if __name__ == "__main__":
main()