jaketae commited on
Commit
e4b9c8b
1 Parent(s): 938499b

wip: add streamlit page for zero shot img cls

Browse files
Files changed (1) hide show
  1. image2text.py +23 -2
image2text.py CHANGED
@@ -1,14 +1,35 @@
1
  import streamlit as st
 
 
2
 
3
  from utils import load_model
4
 
5
 
6
  def app(model_name):
7
- model, processor = load_model(model_name)
8
 
9
- st.title("Image to Text")
10
  st.markdown(
11
  """
12
  Some text goes in here.
13
  """
14
  )
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
  import streamlit as st
2
+ import numpy as np
3
+ from PIL import Image
4
 
5
  from utils import load_model
6
 
7
 
8
  def app(model_name):
9
+ model, processor = load_model(f"koclip/{model_name}")
10
 
11
+ st.title("Zero-shot Image Classification")
12
  st.markdown(
13
  """
14
  Some text goes in here.
15
  """
16
  )
17
+
18
+ query = st.file_uploader("Choose an image...", type=["jpg", "jpeg", "png"])
19
+
20
+ if st.button("질문 (Query)"):
21
+ if query is None:
22
+ st.error("Please upload an image query.")
23
+ else:
24
+ image = Image.open(query)
25
+ inputs = processor(text=[""], images=image, return_tensors="jax", padding=True)
26
+ # vec = np.asarray(model.get_image_features(**inputs))
27
+ # ids, dists = index.knnQuery(vec, k=10)
28
+ # result_files = map(lambda id: files[id], ids)
29
+ # result_imgs, result_captions = [], []
30
+ # for file, dist in zip(result_files, dists):
31
+ # result_imgs.append(plt.imread(os.path.join(images_directory, file)))
32
+ # result_captions.append("{:s} (유사도: {:.3f})".format(file, 1.0 - dist))
33
+
34
+
35
+