Update app.py
Browse files
app.py
CHANGED
@@ -44,61 +44,46 @@ def image_qa_and_object_detection():
|
|
44 |
object_detection_app()
|
45 |
|
46 |
def image_qa_app():
|
47 |
-
# Initialize session state for storing
|
48 |
-
if '
|
49 |
-
st.session_state['
|
50 |
-
|
51 |
-
|
52 |
-
|
53 |
-
|
54 |
-
|
55 |
-
|
56 |
-
# Image uploader
|
57 |
-
uploaded_image = st.file_uploader("Upload an Image", type=["png", "jpg", "jpeg"])
|
58 |
-
|
59 |
-
# Display sample images
|
60 |
-
st.write("Or choose from sample images:")
|
61 |
for idx, sample_image_path in enumerate(sample_images):
|
62 |
-
|
63 |
-
|
64 |
-
|
|
|
|
|
65 |
|
|
|
|
|
66 |
if uploaded_image is not None:
|
67 |
-
|
68 |
-
|
69 |
-
|
70 |
-
|
71 |
-
|
72 |
-
|
73 |
-
if not any(info['image_key'] == current_image_key for info in st.session_state['images_qa_history']):
|
74 |
-
st.session_state['images_qa_history'].append({
|
75 |
-
'image_key': current_image_key,
|
76 |
-
'image': image,
|
77 |
-
'qa_history': []
|
78 |
-
})
|
79 |
-
|
80 |
-
# Display all images and their Q&A histories
|
81 |
-
for image_info in st.session_state['images_qa_history']:
|
82 |
-
st.image(image_info['image'], caption='Uploaded Image.', use_column_width=True)
|
83 |
-
for q, a in image_info['qa_history']:
|
84 |
-
st.text(f"Q: {q}\nA: {a}\n")
|
85 |
|
86 |
-
#
|
87 |
-
|
88 |
-
# Unique keys for each widget
|
89 |
-
question_key = f"question_{current_image_key}"
|
90 |
-
button_key = f"button_{current_image_key}"
|
91 |
|
92 |
-
|
93 |
-
|
|
|
|
|
|
|
94 |
|
95 |
-
|
96 |
-
|
97 |
-
|
98 |
-
answer = answer_question(image_info['image'], question, None, None) # Implement this function
|
99 |
-
image_info['qa_history'].append((question, answer))
|
100 |
-
st.experimental_rerun() # Rerun to update the display
|
101 |
|
|
|
102 |
# Object Detection App
|
103 |
def object_detection_app():
|
104 |
# ... Implement your code for object detection ...
|
|
|
44 |
object_detection_app()
|
45 |
|
46 |
def image_qa_app():
|
47 |
+
# Initialize session state for storing the current image and its Q&A history
|
48 |
+
if 'current_image' not in st.session_state:
|
49 |
+
st.session_state['current_image'] = None
|
50 |
+
if 'qa_history' not in st.session_state:
|
51 |
+
st.session_state['qa_history'] = []
|
52 |
+
|
53 |
+
# Display sample images as clickable thumbnails
|
54 |
+
st.write("Choose from sample images:")
|
55 |
+
cols = st.columns(len(sample_images))
|
|
|
|
|
|
|
|
|
|
|
56 |
for idx, sample_image_path in enumerate(sample_images):
|
57 |
+
with cols[idx]:
|
58 |
+
image = Image.open(sample_image_path)
|
59 |
+
if st.image(image, use_column_width=True):
|
60 |
+
st.session_state['current_image'] = image
|
61 |
+
st.session_state['qa_history'] = []
|
62 |
|
63 |
+
# Image uploader
|
64 |
+
uploaded_image = st.file_uploader("Or upload an Image", type=["png", "jpg", "jpeg"])
|
65 |
if uploaded_image is not None:
|
66 |
+
st.session_state['current_image'] = Image.open(uploaded_image)
|
67 |
+
st.session_state['qa_history'] = []
|
68 |
+
|
69 |
+
# Display the current image
|
70 |
+
if st.session_state['current_image'] is not None:
|
71 |
+
st.image(st.session_state['current_image'], caption='Uploaded Image.', use_column_width=True)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
72 |
|
73 |
+
# Question input
|
74 |
+
question = st.text_input("Ask a question about this image:")
|
|
|
|
|
|
|
75 |
|
76 |
+
# Get Answer button
|
77 |
+
if st.button('Get Answer'):
|
78 |
+
# Process the question
|
79 |
+
answer = answer_question(st.session_state['current_image'], question)
|
80 |
+
st.session_state['qa_history'].append((question, answer))
|
81 |
|
82 |
+
# Display all Q&A
|
83 |
+
for q, a in st.session_state['qa_history']:
|
84 |
+
st.text(f"Q: {q}\nA: {a}\n")
|
|
|
|
|
|
|
85 |
|
86 |
+
|
87 |
# Object Detection App
|
88 |
def object_detection_app():
|
89 |
# ... Implement your code for object detection ...
|