linh-truong commited on
Commit
6d1520c
1 Parent(s): 9301987

update example

Browse files
app.py CHANGED
@@ -4,11 +4,11 @@ import streamlit as st
4
  from streamlit_image_select import image_select
5
 
6
  #Trick to not init function multitime
7
- # if "model" not in st.session_state:
8
- # print("INIT MODEL")
9
- # from src.model import Model
10
- # st.session_state.model = Model()
11
- # print("DONE INIT MODEL")
12
 
13
  st.set_page_config(page_title="VQA", layout="wide")
14
  hide_menu_style = """
@@ -19,11 +19,11 @@ footer {visibility: hidden;}
19
  st.markdown(hide_menu_style, unsafe_allow_html= True)
20
 
21
  mapper = {
22
- "images\\000000000008.jpg": "A",
23
- "images\\000000000012.jpg": "B",
24
- "images\\000000000016.jpg": "C",
25
- "images\\000000000019.jpg": "D",
26
- "images\\000000000181.jpg": "E"
27
  }
28
 
29
  image = st.file_uploader("Choose an image file", type=["jpg", "jpeg", "png", "webp", ])
@@ -43,7 +43,7 @@ else:
43
  if 'image' in st.session_state:
44
  st.image(st.session_state.image)
45
  question = st.text_input("Question: ", value=st.session_state.question)
46
- # if question:
47
- # answer = st.session_state.model.inference(st.session_state.image, question)
48
- # st.write(f"Answer: {answer}")
49
 
 
4
  from streamlit_image_select import image_select
5
 
6
  #Trick to not init function multitime
7
+ if "model" not in st.session_state:
8
+ print("INIT MODEL")
9
+ from src.model import Model
10
+ st.session_state.model = Model()
11
+ print("DONE INIT MODEL")
12
 
13
  st.set_page_config(page_title="VQA", layout="wide")
14
  hide_menu_style = """
 
19
  st.markdown(hide_menu_style, unsafe_allow_html= True)
20
 
21
  mapper = {
22
+ "images/000000000645.jpg": "Đây là đâu",
23
+ "images/000000000661.jpg": "Tốc độ tối đa trên đoạn đường này là bao nhiêu",
24
+ "images/000000000674.jpg": "Còn bao xa nữa là tới Huế",
25
+ "images/000000000706.jpg": "Cầu này dài bao nhiêu",
26
+ "images/000000000777.jpg": "Chè khúc bạch giá bao nhiêu"
27
  }
28
 
29
  image = st.file_uploader("Choose an image file", type=["jpg", "jpeg", "png", "webp", ])
 
43
  if 'image' in st.session_state:
44
  st.image(st.session_state.image)
45
  question = st.text_input("Question: ", value=st.session_state.question)
46
+ if question:
47
+ answer = st.session_state.model.inference(st.session_state.image, question)
48
+ st.write(f"Answer: {answer}")
49
 
images/000000000008.jpg DELETED
Binary file (130 kB)
 
images/000000000012.jpg DELETED
Binary file (103 kB)
 
images/000000000016.jpg DELETED
Binary file (80.1 kB)
 
images/000000000019.jpg DELETED
Binary file (22.9 kB)
 
images/000000000181.jpg DELETED
Binary file (114 kB)
 
images/000000000645.jpg ADDED
images/000000000661.jpg ADDED
images/000000000674.jpg ADDED
images/000000000706.jpg ADDED
images/000000000777.jpg ADDED
requirements.txt CHANGED
@@ -4,4 +4,5 @@ vietocr>=0.3.8
4
  pillow==9.5.0
5
  torchvision==0.18.0
6
  streamlit==1.35.0
7
- transformers==4.41.2
 
 
4
  pillow==9.5.0
5
  torchvision==0.18.0
6
  streamlit==1.35.0
7
+ transformers==4.41.2
8
+ streamlit-image-select==0.6.0