Anandhu-Jayan commited on
Commit
f6cca0e
·
1 Parent(s): 5d1ef31

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +14 -5
app.py CHANGED
@@ -4,6 +4,7 @@ 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)
@@ -17,7 +18,7 @@ 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):
@@ -25,10 +26,18 @@ def predict():
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):
@@ -50,4 +59,4 @@ if img_upload != None:
50
  img.save('tmp.jpg')
51
  st.image(img)
52
  predict()
53
- os.remove('tmp.jpg')
 
4
  import requests
5
  from PIL import Image
6
  from model import get_caption_model, generate_caption
7
+ import gradio as gr
8
 
9
 
10
  @st.cache(allow_output_mutation=True)
 
18
  captions = []
19
  pred_caption = generate_caption('tmp.jpg', caption_model)
20
 
21
+
22
  captions.append(pred_caption)
23
 
24
  for _ in range(4):
 
26
  if pred_caption not in captions:
27
  captions.append(pred_caption)
28
 
29
+ return captions;
30
+ def launch():
31
+ img = Image.open(requests.get(inputs, stream=True).raw)
32
+ img = img.convert('RGB')
33
+ st.image(img)
34
+ img.save('tmp.jpg')
35
+ return predict()
36
+ os.remove('tmp.jpg')
37
+ iface = gr.Interface(launch, inputs="text", outputs=[])
38
+ iface.launch()
39
 
40
+ '''st.title('Image Captioner')
41
  img_url = st.text_input(label='Enter Image URL')
42
 
43
  if (img_url != "") and (img_url != None):
 
59
  img.save('tmp.jpg')
60
  st.image(img)
61
  predict()
62
+ os.remove('tmp.jpg')'''