dnaveenr commited on
Commit
ba6c139
·
verified ·
1 Parent(s): 284b63b

Update app.py - add sample example

Browse files
Files changed (1) hide show
  1. app.py +27 -4
app.py CHANGED
@@ -1,6 +1,16 @@
1
  import streamlit as st
2
  from ispice import Spice
3
 
 
 
 
 
 
 
 
 
 
 
4
  # Function to compute score
5
  def preprocess_captions(generated_captions, reference_captions):
6
  hypotheses = {'image'+str(i): [generated_captions[i]] for i in range(len(generated_captions))}
@@ -16,16 +26,29 @@ def main():
16
 
17
  spice_scorer = Spice(mode=mode)
18
 
 
 
 
 
 
 
 
 
 
 
 
 
19
  # Description
20
  st.write("You can either input single caption or multiple captions separated by new line.")
21
  # Input text boxes
22
- generated_caption = st.text_area("Generated Caption:", "")
23
- reference_caption = st.text_area("Reference Caption:", "")
 
24
 
25
  # Compute score button
26
  if st.button("Compute Score"):
27
- generated_captions = generated_caption.split("\n")
28
- reference_captions = reference_caption.split("\n")
29
 
30
  print(generated_captions, len(generated_captions))
31
  print(reference_captions, len(reference_captions))
 
1
  import streamlit as st
2
  from ispice import Spice
3
 
4
+
5
+ # Sample example captions
6
+ sample_examples = {
7
+ "ID - Example 1": {
8
+ "generated": "P1 sits on the couch. P1 puts her hands on the couch and sits up. P2 sits beside her.",
9
+ "reference": "P1 straightens her posture. P1 sits up. P2 sits beside her on the couch."
10
+ }
11
+ }
12
+
13
+
14
  # Function to compute score
15
  def preprocess_captions(generated_captions, reference_captions):
16
  hypotheses = {'image'+str(i): [generated_captions[i]] for i in range(len(generated_captions))}
 
26
 
27
  spice_scorer = Spice(mode=mode)
28
 
29
+ # Sample examples dropdown
30
+ st.sidebar.subheader("Choose Sample Example:")
31
+ example_choice = st.sidebar.selectbox("Select Example", [""] + list(sample_examples.keys()), index=0)
32
+
33
+ # Initialize with empty strings
34
+ generated_caption = ""
35
+ reference_caption = ""
36
+
37
+ if example_choice:
38
+ generated_caption = sample_examples[example_choice]["generated"]
39
+ reference_caption = sample_examples[example_choice]["reference"]
40
+
41
  # Description
42
  st.write("You can either input single caption or multiple captions separated by new line.")
43
  # Input text boxes
44
+ generated_caption_input = st.text_area("Generated Caption:", value=generated_caption)
45
+ reference_caption_input = st.text_area("Reference Caption:", value=reference_caption)
46
+
47
 
48
  # Compute score button
49
  if st.button("Compute Score"):
50
+ generated_captions = generated_caption_input.split("\n")
51
+ reference_captions = reference_caption_input.split("\n")
52
 
53
  print(generated_captions, len(generated_captions))
54
  print(reference_captions, len(reference_captions))