Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -30,6 +30,8 @@ class ImageHandler:
|
|
| 30 |
# Implementation for freeing GPU resources
|
| 31 |
free_gpu_resources()
|
| 32 |
|
|
|
|
|
|
|
| 33 |
class QuestionAnswering:
|
| 34 |
@staticmethod
|
| 35 |
def answer_question(image, question, caption, detected_objects_str, model):
|
|
@@ -54,6 +56,10 @@ class UIComponents:
|
|
| 54 |
st.session_state['analysis_done'] = False
|
| 55 |
st.session_state['answer_in_progress'] = False
|
| 56 |
|
|
|
|
|
|
|
|
|
|
|
|
|
| 57 |
def load_kbvqa_model(detection_model):
|
| 58 |
"""Load KBVQA Model based on the selected detection model."""
|
| 59 |
if st.session_state.get('kbvqa') is not None:
|
|
@@ -83,6 +89,7 @@ def image_qa_app(kbvqa_model):
|
|
| 83 |
UIComponents.display_image_selection(sample_images)
|
| 84 |
|
| 85 |
uploaded_image = st.file_uploader("Or upload an Image", type=["png", "jpg", "jpeg"])
|
|
|
|
| 86 |
if uploaded_image is not None:
|
| 87 |
st.session_state['current_image'] = Image.open(uploaded_image)
|
| 88 |
st.session_state['qa_history'] = []
|
|
@@ -131,11 +138,11 @@ def run_inference():
|
|
| 131 |
if 'kbvqa' not in st.session_state or st.session_state['detection_model'] != detection_model:
|
| 132 |
st.session_state['detection_model'] = detection_model
|
| 133 |
if 'model' not in st.session_state:
|
| 134 |
-
|
| 135 |
|
| 136 |
-
|
| 137 |
-
|
| 138 |
-
|
| 139 |
|
| 140 |
|
| 141 |
|
|
|
|
| 30 |
# Implementation for freeing GPU resources
|
| 31 |
free_gpu_resources()
|
| 32 |
|
| 33 |
+
|
| 34 |
+
|
| 35 |
class QuestionAnswering:
|
| 36 |
@staticmethod
|
| 37 |
def answer_question(image, question, caption, detected_objects_str, model):
|
|
|
|
| 56 |
st.session_state['analysis_done'] = False
|
| 57 |
st.session_state['answer_in_progress'] = False
|
| 58 |
|
| 59 |
+
@staticmethod
|
| 60 |
+
def display_image(img):
|
| 61 |
+
st.image(img)
|
| 62 |
+
|
| 63 |
def load_kbvqa_model(detection_model):
|
| 64 |
"""Load KBVQA Model based on the selected detection model."""
|
| 65 |
if st.session_state.get('kbvqa') is not None:
|
|
|
|
| 89 |
UIComponents.display_image_selection(sample_images)
|
| 90 |
|
| 91 |
uploaded_image = st.file_uploader("Or upload an Image", type=["png", "jpg", "jpeg"])
|
| 92 |
+
UIComponents.display_image(uploaded_image)
|
| 93 |
if uploaded_image is not None:
|
| 94 |
st.session_state['current_image'] = Image.open(uploaded_image)
|
| 95 |
st.session_state['qa_history'] = []
|
|
|
|
| 138 |
if 'kbvqa' not in st.session_state or st.session_state['detection_model'] != detection_model:
|
| 139 |
st.session_state['detection_model'] = detection_model
|
| 140 |
if 'model' not in st.session_state:
|
| 141 |
+
if st.button('Load Model'):
|
| 142 |
|
| 143 |
+
if load_kbvqa_model(detection_model):
|
| 144 |
+
set_model_confidence(detection_model)
|
| 145 |
+
image_qa_app(st.session_state['kbvqa'])
|
| 146 |
|
| 147 |
|
| 148 |
|