File size: 1,891 Bytes
d7c3bb9
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
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()