ChandraP12330 commited on
Commit
0ba7cdf
1 Parent(s): e356bc7

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +7 -6
app.py CHANGED
@@ -36,13 +36,7 @@ st.title("Image Caption Surveillance")
36
 
37
  # Input field for URL
38
  image_url = st.text_input("Enter the URL of the image:")
39
- image = Image.open(requests.get(image_url, stream=True).raw)
40
- inputs = processor(text=scene_labels, images=image, return_tensors="pt", padding=True)
41
- outputs = model(**inputs)
42
- logits_per_image = outputs.logits_per_image # this is the image-text similarity score
43
- probs = logits_per_image.softmax(dim=1) # we can take the softmax to get the label probabilities
44
 
45
- context= scene_labels[probs.argmax(-1)]
46
 
47
 
48
 
@@ -50,6 +44,13 @@ context= scene_labels[probs.argmax(-1)]
50
  if image_url:
51
  try:
52
  st.image(image_url, caption="Uploaded Image")
 
 
 
 
 
 
 
53
  st.write("context: ", context)
54
  except Exception as e:
55
  st.error(f"Error: {e}")
 
36
 
37
  # Input field for URL
38
  image_url = st.text_input("Enter the URL of the image:")
 
 
 
 
 
39
 
 
40
 
41
 
42
 
 
44
  if image_url:
45
  try:
46
  st.image(image_url, caption="Uploaded Image")
47
+ image = Image.open(requests.get(image_url, stream=True).raw)
48
+ inputs = processor(text=scene_labels, images=image, return_tensors="pt", padding=True)
49
+ outputs = model(**inputs)
50
+ logits_per_image = outputs.logits_per_image # this is the image-text similarity score
51
+ probs = logits_per_image.softmax(dim=1) # we can take the softmax to get the label probabilities
52
+
53
+ context= scene_labels[probs.argmax(-1)]
54
  st.write("context: ", context)
55
  except Exception as e:
56
  st.error(f"Error: {e}")