m7mdal7aj commited on
Commit
7391509
·
verified ·
1 Parent(s): d40826b

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +15 -5
app.py CHANGED
@@ -48,6 +48,8 @@ def image_qa_app(kbvqa):
48
  st.session_state['qa_history'] = []
49
  if 'analysis_done' not in st.session_state:
50
  st.session_state['analysis_done'] = False
 
 
51
 
52
  # Display sample images as clickable thumbnails
53
  st.write("Choose from sample images:")
@@ -60,6 +62,7 @@ def image_qa_app(kbvqa):
60
  st.session_state['current_image'] = image
61
  st.session_state['qa_history'] = []
62
  st.session_state['analysis_done'] = False
 
63
 
64
  # Image uploader
65
  uploaded_image = st.file_uploader("Or upload an Image", type=["png", "jpg", "jpeg"])
@@ -68,6 +71,7 @@ def image_qa_app(kbvqa):
68
  st.session_state['current_image'] = image
69
  st.session_state['qa_history'] = []
70
  st.session_state['analysis_done'] = False
 
71
 
72
  # Analyze Image button
73
  if st.session_state.get('current_image') and not st.session_state['analysis_done']:
@@ -75,21 +79,27 @@ def image_qa_app(kbvqa):
75
  # Perform analysis on the image
76
  analyze_image(st.session_state['current_image'], kbvqa)
77
  st.session_state['analysis_done'] = True
 
78
 
79
  # Display the current image (unaltered)
80
  if st.session_state.get('current_image'):
81
  st.image(st.session_state['current_image'], caption='Uploaded Image.', use_column_width=True)
82
 
83
  # Get Answer button
84
- if st.session_state['analysis_done']:
85
  question = st.text_input("Ask a question about this image:")
86
  if st.button('Get Answer'):
87
- answer = answer_question(st.session_state['current_image'], question, model=kbvqa)
 
88
  st.session_state['qa_history'].append((question, answer))
89
 
90
- # Display all Q&A
91
- for q, a in st.session_state['qa_history']:
92
- st.text(f"Q: {q}\nA: {a}\n")
 
 
 
 
93
 
94
  def run_inference():
95
  st.title("Run Inference")
 
48
  st.session_state['qa_history'] = []
49
  if 'analysis_done' not in st.session_state:
50
  st.session_state['analysis_done'] = False
51
+ if 'answer_in_progress' not in st.session_state:
52
+ st.session_state['answer_in_progress'] = False
53
 
54
  # Display sample images as clickable thumbnails
55
  st.write("Choose from sample images:")
 
62
  st.session_state['current_image'] = image
63
  st.session_state['qa_history'] = []
64
  st.session_state['analysis_done'] = False
65
+ st.session_state['answer_in_progress'] = False
66
 
67
  # Image uploader
68
  uploaded_image = st.file_uploader("Or upload an Image", type=["png", "jpg", "jpeg"])
 
71
  st.session_state['current_image'] = image
72
  st.session_state['qa_history'] = []
73
  st.session_state['analysis_done'] = False
74
+ st.session_state['answer_in_progress'] = False
75
 
76
  # Analyze Image button
77
  if st.session_state.get('current_image') and not st.session_state['analysis_done']:
 
79
  # Perform analysis on the image
80
  analyze_image(st.session_state['current_image'], kbvqa)
81
  st.session_state['analysis_done'] = True
82
+ st.session_state['processed_image'] = copy.deepcopy(st.session_state['current_image'])
83
 
84
  # Display the current image (unaltered)
85
  if st.session_state.get('current_image'):
86
  st.image(st.session_state['current_image'], caption='Uploaded Image.', use_column_width=True)
87
 
88
  # Get Answer button
89
+ if st.session_state['analysis_done'] and not st.session_state['answer_in_progress']:
90
  question = st.text_input("Ask a question about this image:")
91
  if st.button('Get Answer'):
92
+ st.session_state['answer_in_progress'] = True
93
+ answer = answer_question(st.session_state['processed_image'], question, model=kbvqa)
94
  st.session_state['qa_history'].append((question, answer))
95
 
96
+ # Display all Q&A
97
+ for q, a in st.session_state['qa_history']:
98
+ st.text(f"Q: {q}\nA: {a}\n")
99
+
100
+ # Reset the answer_in_progress flag after displaying the answer
101
+ if st.session_state['answer_in_progress']:
102
+ st.session_state['answer_in_progress'] = False
103
 
104
  def run_inference():
105
  st.title("Run Inference")