m7mdal7aj commited on
Commit
356a130
1 Parent(s): db80e27

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +5 -7
app.py CHANGED
@@ -3,6 +3,7 @@ import torch
3
  import bitsandbytes
4
  import accelerate
5
  import scipy
 
6
  from PIL import Image
7
  import torch.nn as nn
8
  from my_model.object_detection import detect_and_draw_objects
@@ -64,10 +65,12 @@ def image_qa_app(kbvqa):
64
  cols = st.columns(len(sample_images))
65
  for idx, sample_image_path in enumerate(sample_images):
66
  with cols[idx]:
 
67
  image = Image.open(sample_image_path)
68
- # Use button for each image
69
- if st.button(f'Sample Image {idx + 1}', key=f'sample_{idx}'):
70
  st.session_state['current_image'] = image
 
71
  st.session_state['qa_history'] = []
72
 
73
  # Image uploader
@@ -77,7 +80,6 @@ def image_qa_app(kbvqa):
77
  st.session_state['current_image'] = image
78
  st.session_state['processed_image'] = copy.deepcopy(image)
79
  st.session_state['qa_history'] = []
80
- print("Image uploaded and processed image set.")
81
 
82
  # Display the current image (unaltered)
83
  if st.session_state.get('current_image') is not None:
@@ -88,17 +90,13 @@ def image_qa_app(kbvqa):
88
  if st.button('Get Answer'):
89
  processed_image = st.session_state.get('processed_image')
90
  if processed_image:
91
- print("Processing image for question:", question)
92
  answer = answer_question(processed_image, question, model=kbvqa)
93
  st.session_state['qa_history'].append((question, answer))
94
- print("Answer generated:", 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
- st.session_state['processed_image'] = processed_image
101
-
102
 
103
  # Main function
104
  def main():
 
3
  import bitsandbytes
4
  import accelerate
5
  import scipy
6
+ import copy
7
  from PIL import Image
8
  import torch.nn as nn
9
  from my_model.object_detection import detect_and_draw_objects
 
65
  cols = st.columns(len(sample_images))
66
  for idx, sample_image_path in enumerate(sample_images):
67
  with cols[idx]:
68
+ # Display each sample image with a button
69
  image = Image.open(sample_image_path)
70
+ st.image(image, use_column_width=True)
71
+ if st.button(f'Select Sample Image {idx + 1}', key=f'sample_{idx}'):
72
  st.session_state['current_image'] = image
73
+ st.session_state['processed_image'] = copy.deepcopy(image)
74
  st.session_state['qa_history'] = []
75
 
76
  # Image uploader
 
80
  st.session_state['current_image'] = image
81
  st.session_state['processed_image'] = copy.deepcopy(image)
82
  st.session_state['qa_history'] = []
 
83
 
84
  # Display the current image (unaltered)
85
  if st.session_state.get('current_image') is not None:
 
90
  if st.button('Get Answer'):
91
  processed_image = st.session_state.get('processed_image')
92
  if processed_image:
 
93
  answer = answer_question(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
 
101
  # Main function
102
  def main():