SilvusTV commited on
Commit
f098da2
1 Parent(s): aa58e2f

test image.py import on app.py

Browse files
Files changed (2) hide show
  1. app.py +4 -1
  2. image.py +20 -0
app.py CHANGED
@@ -1,4 +1,7 @@
1
  import streamlit as st
2
 
 
3
  x = st.slider('Select a value')
4
- st.write(x, 'squared is', x * x)
 
 
 
1
  import streamlit as st
2
 
3
+ import os
4
  x = st.slider('Select a value')
5
+ st.write(x, 'squared is', x * x)
6
+
7
+ os.system("python image.py")
image.py ADDED
@@ -0,0 +1,20 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from transformers import ViltProcessor, ViltForQuestionAnswering
2
+ import requests
3
+ from PIL import Image
4
+
5
+ # prepare image + question
6
+ url = "http://images.cocodataset.org/val2017/000000039769.jpg"
7
+ image = Image.open(requests.get(url, stream=True).raw)
8
+ text = "How many cats are there?"
9
+
10
+ processor = ViltProcessor.from_pretrained("dandelin/vilt-b32-finetuned-vqa")
11
+ model = ViltForQuestionAnswering.from_pretrained("dandelin/vilt-b32-finetuned-vqa")
12
+
13
+ # prepare inputs
14
+ encoding = processor(image, text, return_tensors="pt")
15
+
16
+ # forward pass
17
+ outputs = model(**encoding)
18
+ logits = outputs.logits
19
+ idx = logits.argmax(-1).item()
20
+ print("Predicted answer:", model.config.id2label[idx])