-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapp.py
More file actions
71 lines (59 loc) · 2.25 KB
/
Copy pathapp.py
File metadata and controls
71 lines (59 loc) · 2.25 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
import os
import sys
sys.path.insert(0, os.path.abspath(os.path.join(os.path.dirname(__file__), "src")))
import streamlit as st
from PIL import Image
from src.image_utils import load_image_from_url
from src.inference import VQAInference
@st.cache_data()
def load_vqa_inference(model_path=None):
return VQAInference(model_path=model_path)
def footer():
st.markdown(
"""
<style>
.footer {
position: fixed;
bottom: 0;
width: 100%;
text-align: center;
padding: 10px;
background-color: black;
font-size: 14px;
color: white;
}
</style>
<div class="footer">
Made with ❤️ by <a href="https://tedoa.vercel.app/" target="_blank">Tadesse Abateneh</a>
</div>
""",
unsafe_allow_html=True
)
def main():
st.title("Visual Question Answering (VQA)")
st.write("This application uses a pre-trained VQA model to answer questions about images.")
st.sidebar.title("Model Selection")
model_path = st.sidebar.text_input("Local Model Path (leave blank for default Hugging Face model)", "")
vqa_inference = load_vqa_inference(model_path if model_path else None)
st.sidebar.title("Image Upload")
image_source = st.sidebar.radio("Select Image Source", ("Upload", "URL"))
if image_source == "Upload":
uploaded_file = st.sidebar.file_uploader("Choose an image...", type=["jpg", "jpeg", "png"])
if uploaded_file is not None:
image = Image.open(uploaded_file)
else:
image_url = st.sidebar.text_input("Enter Image URL")
if image_url:
image = load_image_from_url(image_url)
if 'image' in locals():
st.image(image, caption="Uploaded Image", use_container_width=True)
question = st.text_input("Enter your question about the image:")
if question:
answer = vqa_inference.predict(image, question)
st.write("**Question:**", question)
st.write("**Answer:**", answer)
with st.sidebar:
st.markdown("© 2025 Tadesse Abateneh | [GitHub](https://github.com/tedoaba) | [LinkedIn](https://linkedin.com/in/tadesse-abateneh)")
footer()
if __name__ == "__main__":
main()