vin56 commited on
Commit
4750129
1 Parent(s): 868e0f2

Add ML model some depen and streamlit file

Browse files
README.md CHANGED
@@ -1,13 +1,12 @@
1
  ---
2
- title: Saw And Tell
3
- emoji: 📊
4
  colorFrom: red
5
- colorTo: yellow
6
  sdk: streamlit
7
- sdk_version: 1.17.0
8
  app_file: app.py
9
  pinned: false
10
- license: apache-2.0
11
  ---
12
 
13
  Check out the configuration reference at https://huggingface.co/docs/hub/spaces-config-reference
 
1
  ---
2
+ title: Image Captioning
3
+ emoji: 🦀
4
  colorFrom: red
5
+ colorTo: gray
6
  sdk: streamlit
7
+ sdk_version: 1.10.0
8
  app_file: app.py
9
  pinned: false
 
10
  ---
11
 
12
  Check out the configuration reference at https://huggingface.co/docs/hub/spaces-config-reference
app.py ADDED
@@ -0,0 +1,53 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import io
2
+ import os
3
+ import streamlit as st
4
+ import requests
5
+ from PIL import Image
6
+ from model import get_caption_model, generate_caption
7
+
8
+
9
+ @st.cache(allow_output_mutation=True)
10
+ def get_model():
11
+ return get_caption_model()
12
+
13
+ caption_model = get_model()
14
+
15
+
16
+ def predict():
17
+ captions = []
18
+ pred_caption = generate_caption('tmp.jpg', caption_model)
19
+
20
+ st.markdown('#### Predicted Captions:')
21
+ captions.append(pred_caption)
22
+
23
+ for _ in range(4):
24
+ pred_caption = generate_caption('tmp.jpg', caption_model, add_noise=True)
25
+ if pred_caption not in captions:
26
+ captions.append(pred_caption)
27
+
28
+ for c in captions:
29
+ st.write(c)
30
+
31
+ st.title('Image Captioner')
32
+ img_url = st.text_input(label='Enter Image URL')
33
+
34
+ if (img_url != "") and (img_url != None):
35
+ img = Image.open(requests.get(img_url, stream=True).raw)
36
+ img = img.convert('RGB')
37
+ st.image(img)
38
+ img.save('tmp.jpg')
39
+ predict()
40
+ os.remove('tmp.jpg')
41
+
42
+
43
+ st.markdown('<center style="opacity: 70%">OR</center>', unsafe_allow_html=True)
44
+ img_upload = st.file_uploader(label='Upload Image', type=['jpg', 'png', 'jpeg'])
45
+
46
+ if img_upload != None:
47
+ img = img_upload.read()
48
+ img = Image.open(io.BytesIO(img))
49
+ img = img.convert('RGB')
50
+ img.save('tmp.jpg')
51
+ st.image(img)
52
+ predict()
53
+ os.remove('tmp.jpg')
image-captioning-on-coco-dataset.ipynb ADDED
The diff for this file is too large to render. See raw diff
 
requirements.txt ADDED
@@ -0,0 +1,7 @@
 
 
 
 
 
 
 
 
1
+ numpy==1.22.3
2
+ pandas==1.4.3
3
+ pandas_stubs==1.2.0.56
4
+ Pillow==9.2.0
5
+ requests==2.27.1
6
+ streamlit==1.11.1
7
+ tensorflow==2.9.1
test.ipynb ADDED
The diff for this file is too large to render. See raw diff