Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
@@ -1,16 +1,57 @@
|
|
1 |
import streamlit as st
|
2 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
3 |
# Title
|
4 |
-
st.title("Image
|
5 |
|
6 |
# Input field for URL
|
7 |
image_url = st.text_input("Enter the URL of the image:")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
8 |
|
9 |
# Display image if a valid URL is provided
|
10 |
if image_url:
|
11 |
try:
|
12 |
st.image(image_url, caption="Uploaded Image")
|
|
|
13 |
except Exception as e:
|
14 |
st.error(f"Error: {e}")
|
15 |
else:
|
16 |
-
st.warning("Please enter a valid image URL.")
|
|
|
1 |
import streamlit as st
|
2 |
|
3 |
+
|
4 |
+
##CLIP
|
5 |
+
scene_labels=['Arrest',
|
6 |
+
'Arson',
|
7 |
+
'Explosion',
|
8 |
+
'public fight',
|
9 |
+
'Normal',
|
10 |
+
'Road Accident',
|
11 |
+
'Robbery',
|
12 |
+
'Shooting',
|
13 |
+
'Stealing',
|
14 |
+
'Vandalism',
|
15 |
+
'Suspicious activity',
|
16 |
+
'Tailgating',
|
17 |
+
'Unauthorized entry',
|
18 |
+
'Protest/Demonstration',
|
19 |
+
'Drone suspicious activity',
|
20 |
+
'Fire/Smoke detection',
|
21 |
+
'Medical emergency',
|
22 |
+
'Suspicious package/object',
|
23 |
+
'Threatening',
|
24 |
+
'Attack',
|
25 |
+
'Shoplifting',
|
26 |
+
'burglary ',
|
27 |
+
'distress',
|
28 |
+
'assault']
|
29 |
+
from transformers import CLIPProcessor, CLIPModel
|
30 |
+
model_id = "openai/clip-vit-large-patch14"
|
31 |
+
processor = CLIPProcessor.from_pretrained(model_id)
|
32 |
+
model = CLIPModel.from_pretrained(model_id)
|
33 |
+
|
34 |
# Title
|
35 |
+
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 |
|
49 |
# Display image if a valid URL is provided
|
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}")
|
56 |
else:
|
57 |
+
st.warning("Please enter a valid image URL.")
|