FranklinMoses commited on
Commit
7cf73d4
1 Parent(s): bd23a27
Files changed (1) hide show
  1. app.py +9 -10
app.py CHANGED
@@ -6,6 +6,8 @@ import numpy as np
6
  import torch.nn.functional as F
7
  import clip
8
  import cv2
 
 
9
  # Compute the cosine similarity between two vectors.
10
  def cosine_similarity(a, b):
11
  return np.dot(a, b) / (np.linalg.norm(a) * np.linalg.norm(b))
@@ -22,26 +24,23 @@ def compute_text_embeddings(text_prompts):
22
 
23
  return text_embeddings
24
 
25
- zoo=dg.connect(dg.CLOUD,zoo_url='https://cs.degirum.com/degirum/kvk_upload_test',token=st.secrets["DG_TOKEN"])
26
 
27
  st.title('DeGirum CLIP model Demo')
28
- embeddings = []
29
  with st.sidebar:
30
  st.header('Specify Model Options Below')
31
-
32
- prompts = st.text_area("Enter text prompts (comma-separated):", value="People Running, People Talking, People Fighting, People Laughing, People Dancing")
33
  prompts = [prompt.strip() for prompt in prompts.split(',')]
34
- if st.button("Generate Text Embedding"):
35
- # Call the compute_text_embeddings function when the button is clicked
36
- embeddings = compute_text_embeddings(prompts)
37
- st.success("Text embeddings generated successfully!")
38
-
39
  st.text('Upload an image. Then click on the submit button')
40
  with st.form("model_form"):
41
  uploaded_file=st.file_uploader('input image')
42
  submitted = st.form_submit_button("Submit")
43
- # embeddings = compute_text_embeddings(prompts)
 
44
  if submitted:
 
 
45
  model=zoo.load_model('clip--224x224_float_openvino_cpu_4',
46
  input_image_format = "RAW"
47
  )
 
6
  import torch.nn.functional as F
7
  import clip
8
  import cv2
9
+
10
+ prev_prompt = None
11
  # Compute the cosine similarity between two vectors.
12
  def cosine_similarity(a, b):
13
  return np.dot(a, b) / (np.linalg.norm(a) * np.linalg.norm(b))
 
24
 
25
  return text_embeddings
26
 
27
+ zoo=dg.connect(dg.CLOUD,zoo_url='https://cs.degirum.com/degirum/kvk_upload_test', token=st.secrets["DG_TOKEN"])
28
 
29
  st.title('DeGirum CLIP model Demo')
30
+
31
  with st.sidebar:
32
  st.header('Specify Model Options Below')
33
+ prompts = st.text_area("Enter text prompts (comma-separated):", value="People Running, People sitting, People swimming, People sleeping, People watching television")
 
34
  prompts = [prompt.strip() for prompt in prompts.split(',')]
 
 
 
 
 
35
  st.text('Upload an image. Then click on the submit button')
36
  with st.form("model_form"):
37
  uploaded_file=st.file_uploader('input image')
38
  submitted = st.form_submit_button("Submit")
39
+ if prev_prompt is None or prev_prompt != prompts:
40
+ embeddings = compute_text_embeddings(prompts)
41
  if submitted:
42
+ if prev_prompt != prompts:
43
+ prev_prompt = prompts
44
  model=zoo.load_model('clip--224x224_float_openvino_cpu_4',
45
  input_image_format = "RAW"
46
  )