yurapodk commited on
Commit
f527373
1 Parent(s): f73ed63
Files changed (2) hide show
  1. app.py +37 -0
  2. requirements.txt +3 -0
app.py ADDED
@@ -0,0 +1,37 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import ast
2
+ import os
3
+ import requests
4
+ from requests_toolbelt.multipart.encoder import MultipartEncoder
5
+ from PIL import Image
6
+ import streamlit as st
7
+ import io
8
+
9
+ api = "http://127.0.0.1:8000/"
10
+
11
+ st.title("Stamp2vec")
12
+
13
+ input_image = st.file_uploader("insert image")
14
+ image = Image.open(input_image)
15
+ if(input_image):
16
+ st.header("Original")
17
+ st.image(input_image, use_column_width=True)
18
+ if st.button("Get prediction"):
19
+ col1, col2 = st.columns(2)
20
+ col1.subheader("Prediction")
21
+ response = requests.post(os.path.join(api, "bounding-boxes/"), files = {"file": input_image.getvalue()})
22
+ prediction = ast.literal_eval(response.text)
23
+ col1.write(prediction)
24
+
25
+ col2.subheader("Image")
26
+ response = requests.post(os.path.join(api, "image-w-boxes/"), files = {"file": input_image.getvalue()})
27
+ col2.image(response.content, use_column_width=True)
28
+
29
+ arr = []
30
+ for b in prediction["bboxes"]:
31
+ stamp = image.crop((b["xmin"], b["ymin"], b["xmin"] + b["width"], b["ymin"] + b["height"]))
32
+ output = io.BytesIO()
33
+ stamp.save(output, format="BMP")
34
+ response = ast.literal_eval(requests.post(os.path.join(api, "embeddings-from-cropped/"), files = {"file": output.getvalue()}).text)
35
+ arr.append(response["emb"])
36
+
37
+ st.write(arr)
requirements.txt ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ requests
2
+ requests_toolbelt
3
+ pillow