Update app.py
Browse files
app.py
CHANGED
@@ -11,7 +11,6 @@ from my_model.captioner.image_captioning import get_caption
|
|
11 |
from my_model.utilities import free_gpu_resources
|
12 |
|
13 |
|
14 |
-
|
15 |
# Placeholder for undefined functions
|
16 |
def load_caption_model():
|
17 |
st.write("Placeholder for load_caption_model function")
|
@@ -29,6 +28,9 @@ def get_caption(image):
|
|
29 |
def free_gpu_resources():
|
30 |
pass
|
31 |
|
|
|
|
|
|
|
32 |
# Main function
|
33 |
def main():
|
34 |
st.sidebar.title("Navigation")
|
@@ -47,37 +49,21 @@ def main():
|
|
47 |
elif selection == "Object Detection":
|
48 |
run_object_detection()
|
49 |
|
50 |
-
|
51 |
-
st.title("MultiModal Learning for Knowledge-Based Visual Question Answering")
|
52 |
-
st.write("Home page content goes here...")
|
53 |
-
|
54 |
-
def display_dissertation_report():
|
55 |
-
st.title("Dissertation Report")
|
56 |
-
st.write("Click the link below to view the PDF.")
|
57 |
-
st.download_button(
|
58 |
-
label="Download PDF",
|
59 |
-
data=open("Files/Dissertation Report.pdf", "rb"),
|
60 |
-
file_name="example.pdf",
|
61 |
-
mime="application/octet-stream"
|
62 |
-
)
|
63 |
-
|
64 |
-
def display_evaluation_results():
|
65 |
-
st.title("Evaluation Results")
|
66 |
-
st.write("This is a Place Holder until the contents are uploaded.")
|
67 |
-
|
68 |
-
def display_dataset_analysis():
|
69 |
-
st.title("OK-VQA Dataset Analysis")
|
70 |
-
st.write("This is a Place Holder until the contents are uploaded.")
|
71 |
|
72 |
def run_inference():
|
73 |
-
st.title("
|
|
|
|
|
|
|
|
|
74 |
# Image-based Q&A functionality
|
|
|
75 |
image_qa_app()
|
76 |
|
77 |
-
def run_object_detection():
|
78 |
-
st.title("Object Detection")
|
79 |
# Object Detection functionality
|
80 |
-
|
|
|
81 |
|
82 |
def image_qa_app():
|
83 |
# Initialize session state for storing images and their Q&A histories
|
@@ -89,46 +75,28 @@ def image_qa_app():
|
|
89 |
st.session_state['images_qa_history'] = []
|
90 |
st.experimental_rerun()
|
91 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
92 |
# Image uploader
|
93 |
uploaded_image = st.file_uploader("Upload an Image", type=["png", "jpg", "jpeg"])
|
94 |
-
|
95 |
if uploaded_image is not None:
|
96 |
image = Image.open(uploaded_image)
|
97 |
-
|
98 |
-
|
99 |
-
|
100 |
-
|
101 |
-
|
102 |
-
|
103 |
-
|
104 |
-
|
105 |
-
|
106 |
-
|
107 |
-
|
108 |
-
for image_info in st.session_state['images_qa_history']:
|
109 |
-
st.image(image_info['image'], caption='Uploaded Image.', use_column_width=True)
|
110 |
-
for q, a in image_info['qa_history']:
|
111 |
-
st.text(f"Q: {q}\nA: {a}\n")
|
112 |
-
|
113 |
-
# If the current image is being processed
|
114 |
-
if image_info['image_key'] == current_image_key:
|
115 |
-
# Unique keys for each widget
|
116 |
-
question_key = f"question_{current_image_key}"
|
117 |
-
button_key = f"button_{current_image_key}"
|
118 |
-
|
119 |
-
# Question input for the current image
|
120 |
-
question = st.text_input("Ask a question about this image:", key=question_key)
|
121 |
-
|
122 |
-
# Get Answer button for the current image
|
123 |
-
if st.button('Get Answer', key=button_key):
|
124 |
-
# Process the image and question
|
125 |
-
answer = get_answer(image_info['image'], question) # Implement this function
|
126 |
-
image_info['qa_history'].append((question, answer))
|
127 |
-
st.experimental_rerun() # Rerun to update the display
|
128 |
-
|
129 |
-
def get_answer(image, question):
|
130 |
-
# Implement the logic to process the image and question, and return the answer
|
131 |
-
return "Sample answer based on the image and question."
|
132 |
|
133 |
if __name__ == "__main__":
|
134 |
main()
|
|
|
11 |
from my_model.utilities import free_gpu_resources
|
12 |
|
13 |
|
|
|
14 |
# Placeholder for undefined functions
|
15 |
def load_caption_model():
|
16 |
st.write("Placeholder for load_caption_model function")
|
|
|
28 |
def free_gpu_resources():
|
29 |
pass
|
30 |
|
31 |
+
# Sample images (assuming these are paths to your sample images)
|
32 |
+
sample_images = ["path/to/sample1.jpg", "path/to/sample2.jpg", "path/to/sample3.jpg"]
|
33 |
+
|
34 |
# Main function
|
35 |
def main():
|
36 |
st.sidebar.title("Navigation")
|
|
|
49 |
elif selection == "Object Detection":
|
50 |
run_object_detection()
|
51 |
|
52 |
+
# Other display functions...
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
53 |
|
54 |
def run_inference():
|
55 |
+
st.title("Run Inference")
|
56 |
+
# Image-based Q&A and Object Detection functionality
|
57 |
+
image_qa_and_object_detection()
|
58 |
+
|
59 |
+
def image_qa_and_object_detection():
|
60 |
# Image-based Q&A functionality
|
61 |
+
st.subheader("Image-based Q&A")
|
62 |
image_qa_app()
|
63 |
|
|
|
|
|
64 |
# Object Detection functionality
|
65 |
+
st.subheader("Object Detection")
|
66 |
+
object_detection_app()
|
67 |
|
68 |
def image_qa_app():
|
69 |
# Initialize session state for storing images and their Q&A histories
|
|
|
75 |
st.session_state['images_qa_history'] = []
|
76 |
st.experimental_rerun()
|
77 |
|
78 |
+
# Display sample images
|
79 |
+
st.write("Or choose from sample images:")
|
80 |
+
for idx, sample_image_path in enumerate(sample_images):
|
81 |
+
if st.button(f"Use Sample Image {idx+1}", key=f"sample_{idx}"):
|
82 |
+
uploaded_image = Image.open(sample_image_path)
|
83 |
+
process_uploaded_image(uploaded_image)
|
84 |
+
|
85 |
# Image uploader
|
86 |
uploaded_image = st.file_uploader("Upload an Image", type=["png", "jpg", "jpeg"])
|
|
|
87 |
if uploaded_image is not None:
|
88 |
image = Image.open(uploaded_image)
|
89 |
+
process_uploaded_image(image)
|
90 |
+
|
91 |
+
def process_uploaded_image(image):
|
92 |
+
current_image_key = image.filename # Use image filename as a unique key
|
93 |
+
# ... rest of the image processing code ...
|
94 |
+
|
95 |
+
# Object Detection App
|
96 |
+
def object_detection_app():
|
97 |
+
# ... Implement your code for object detection ...
|
98 |
+
|
99 |
+
# Other functions...
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
100 |
|
101 |
if __name__ == "__main__":
|
102 |
main()
|