File size: 1,451 Bytes
f527373
 
 
 
 
 
 
 
30b4010
f527373
 
 
 
 
1c31448
f527373
 
 
b5bd9ee
5da6813
 
b5bd9ee
f527373
5da6813
 
 
 
 
 
 
f527373
05eb182
 
 
 
 
 
 
f527373
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
import ast
import os
import requests
from requests_toolbelt.multipart.encoder import MultipartEncoder
from PIL import Image
import streamlit as st
import io

api = "https://7bb4-188-130-155-168.ngrok-free.app"

st.title("Stamp2vec")

input_image = st.file_uploader("insert image")
if(input_image):
    image = Image.open(input_image)
    st.header("Original")
    st.image(input_image, use_column_width=True)
    if st.button("Get prediction"):
        with st.spinner("Loading..."):
            response = requests.post(os.path.join(api, "bounding-boxes/"), files = {"file": input_image.getvalue()})
            prediction = ast.literal_eval(response.text)
            response = requests.post(os.path.join(api, "image-w-boxes/"), files = {"file": input_image.getvalue()})

            arr = []
            for b in prediction["bboxes"]:
                stamp = image.crop((b["xmin"], b["ymin"], b["xmin"] + b["width"], b["ymin"] + b["height"]))
                output = io.BytesIO()
                stamp.save(output, format="BMP")
                response = ast.literal_eval(requests.post(os.path.join(api, "embeddings-from-cropped/"), files = {"file": output.getvalue()}).text)
                arr.extend(response["embedding"])

        col1, col2 = st.columns(2)
        col1.subheader("Prediction")
        col1.write(prediction)

        col2.subheader("Image")
        col2.image(response.content, use_column_width=True)

        st.write(arr)