greencatted commited on
Commit
a60484d
1 Parent(s): aa652b2

Trying Salesforce image classification

Browse files
Files changed (1) hide show
  1. app.py +13 -1
app.py CHANGED
@@ -1,7 +1,19 @@
1
  import streamlit as st
 
 
 
 
 
2
 
3
  enable = st.checkbox("Enable camera")
4
  picture = st.camera_input("Take a picture", disabled=not enable)
5
 
6
  if picture:
7
- st.image(picture)
 
 
 
 
 
 
 
 
1
  import streamlit as st
2
+ from PIL import Image
3
+ from transformers import BlipProcessor, BlipForConditionalGeneration
4
+
5
+ processor = BlipProcessor.from_pretrained("Salesforce/blip-image-captioning-large")
6
+ model = BlipForConditionalGeneration.from_pretrained("Salesforce/blip-image-captioning-large")
7
 
8
  enable = st.checkbox("Enable camera")
9
  picture = st.camera_input("Take a picture", disabled=not enable)
10
 
11
  if picture:
12
+ raw_image = Image.open(picture)
13
+
14
+ # conditional image captioning
15
+ text = "A view of a person in"
16
+ inputs = processor(raw_image, text, return_tensors="pt")
17
+
18
+ out = model.generate(**inputs)
19
+ st.write(processor.decode(out[0], skip_special_tokens=True))