Spaces:
Runtime error
Runtime error
ambujraj2001
commited on
Commit
·
884d8cd
1
Parent(s):
a10d99b
done
Browse files- .gitattributes +1 -0
- app.py +56 -0
- blip.sav +3 -0
- details.png +0 -0
- requirements.txt +3 -0
.gitattributes
CHANGED
|
@@ -32,3 +32,4 @@ saved_model/**/* filter=lfs diff=lfs merge=lfs -text
|
|
| 32 |
*.zip filter=lfs diff=lfs merge=lfs -text
|
| 33 |
*.zst filter=lfs diff=lfs merge=lfs -text
|
| 34 |
*tfevents* filter=lfs diff=lfs merge=lfs -text
|
|
|
|
|
|
| 32 |
*.zip filter=lfs diff=lfs merge=lfs -text
|
| 33 |
*.zst filter=lfs diff=lfs merge=lfs -text
|
| 34 |
*tfevents* filter=lfs diff=lfs merge=lfs -text
|
| 35 |
+
*.sav filter=lfs diff=lfs merge=lfs -text
|
app.py
ADDED
|
@@ -0,0 +1,56 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import streamlit as st
|
| 2 |
+
import requests
|
| 3 |
+
import pickle
|
| 4 |
+
from PIL import Image
|
| 5 |
+
from transformers import BlipProcessor
|
| 6 |
+
with st.sidebar:
|
| 7 |
+
st.subheader('Image Captioning App using BLIP')
|
| 8 |
+
st.write('This app uses the BLIP model to generate captions for images.Model card for image captioning pretrained on COCO dataset - base architecture (with ViT base backbone).')
|
| 9 |
+
image = Image.open('details.png')
|
| 10 |
+
st.image(image, caption='BLIP Model')
|
| 11 |
+
st.code('App Built by Ambuj Raj', language='python')
|
| 12 |
+
|
| 13 |
+
|
| 14 |
+
st.title('Image Captioning App using BLIP')
|
| 15 |
+
|
| 16 |
+
flag_image=0
|
| 17 |
+
flag_url=0
|
| 18 |
+
tab1, tab2 = st.tabs(["Upload Image", "Use URL"])
|
| 19 |
+
with tab1:
|
| 20 |
+
flag_image=1
|
| 21 |
+
uploaded_file = st.file_uploader("Choose a image",type=['png','jpeg','jpg'])
|
| 22 |
+
if uploaded_file is not None:
|
| 23 |
+
st.image(uploaded_file, width=300)
|
| 24 |
+
raw_image = Image.open(uploaded_file).convert('RGB')
|
| 25 |
+
|
| 26 |
+
with tab2:
|
| 27 |
+
flag_url=1
|
| 28 |
+
img_url = st.text_input('Enter URL of image')
|
| 29 |
+
if img_url:
|
| 30 |
+
raw_image = Image.open(requests.get(img_url, stream=True).raw).convert('RGB')
|
| 31 |
+
st.image(raw_image, width=300)
|
| 32 |
+
|
| 33 |
+
if st.button('Generate Caption'):
|
| 34 |
+
if(flag_image==1):
|
| 35 |
+
flag_image=1
|
| 36 |
+
with st.spinner('Generating Caption...'):
|
| 37 |
+
processor = BlipProcessor.from_pretrained("Salesforce/blip-image-captioning-base")
|
| 38 |
+
filename = 'blip.sav'
|
| 39 |
+
loaded_model = pickle.load(open(filename, 'rb'))
|
| 40 |
+
inputs = processor(raw_image, return_tensors="pt")
|
| 41 |
+
out = loaded_model.generate(**inputs)
|
| 42 |
+
st.success('Caption Generated!')
|
| 43 |
+
st.write('Generated Caption is: ',processor.decode(out[0], skip_special_tokens=True))
|
| 44 |
+
elif(flag_url==1):
|
| 45 |
+
flag_url=0
|
| 46 |
+
with st.spinner('Generating Caption...'):
|
| 47 |
+
processor = BlipProcessor.from_pretrained("Salesforce/blip-image-captioning-base")
|
| 48 |
+
filename = 'blip.sav'
|
| 49 |
+
loaded_model = pickle.load(open(filename, 'rb'))
|
| 50 |
+
inputs = processor(raw_image, return_tensors="pt")
|
| 51 |
+
out = loaded_model.generate(**inputs)
|
| 52 |
+
st.success('Caption Generated!')
|
| 53 |
+
st.write('Generated Caption is: ',processor.decode(out[0], skip_special_tokens=True))
|
| 54 |
+
|
| 55 |
+
|
| 56 |
+
|
blip.sav
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:d080c8a428adc06c30862e46cae29cb24c6aadb4e36bd53572798cc1c1f152b7
|
| 3 |
+
size 989879618
|
details.png
ADDED
|
requirements.txt
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
streamlit
|
| 2 |
+
transformers
|
| 3 |
+
torch
|