Update app.py
Browse files
app.py
CHANGED
@@ -1,20 +1,24 @@
|
|
1 |
-
import
|
2 |
import numpy as np
|
3 |
from PIL import Image
|
4 |
from transformers import CLIPProcessor, CLIPModel, YolosImageProcessor, YolosForObjectDetection
|
5 |
import torch
|
6 |
|
7 |
-
|
8 |
-
|
9 |
|
10 |
-
|
11 |
-
|
|
|
12 |
|
13 |
-
|
14 |
-
|
15 |
-
|
16 |
-
|
17 |
-
|
|
|
|
|
|
|
18 |
|
19 |
def extract_image(image, text, prob, num=1):
|
20 |
|
@@ -64,9 +68,8 @@ def extract_image(image, text, prob, num=1):
|
|
64 |
fi = sorted(final_ims, key=lambda item: item.get("score"), reverse=True)
|
65 |
return fi[0]['image'], fi[0]['score']
|
66 |
|
67 |
-
|
68 |
-
|
69 |
-
|
70 |
-
|
71 |
-
|
72 |
-
gr_app.launch()
|
|
|
1 |
+
import streamlit as st
|
2 |
import numpy as np
|
3 |
from PIL import Image
|
4 |
from transformers import CLIPProcessor, CLIPModel, YolosImageProcessor, YolosForObjectDetection
|
5 |
import torch
|
6 |
|
7 |
+
st.title("CLIP & CROP")
|
8 |
+
st.markdown("**Extract sections of images from your image by using OpenAI's CLIP and Facebooks Detr implemented on HuggingFace Transformers, if the similarity score is not so much, then please consider the prediction to be void.**")
|
9 |
|
10 |
+
with st.spinner("Models are loading"):
|
11 |
+
feature_extractor = YolosImageProcessor.from_pretrained("hustvl/yolos-tiny")
|
12 |
+
dmodel = YolosForObjectDetection.from_pretrained('hustvl/yolos-tiny')
|
13 |
|
14 |
+
model = CLIPModel.from_pretrained("openai/clip-vit-base-patch16")
|
15 |
+
processor = CLIPProcessor.from_pretrained("openai/clip-vit-base-patch16")
|
16 |
+
|
17 |
+
IMAGE_INPUT = st.file_uploader(type="pil", label="Input image")
|
18 |
+
TEXT_INPUT = st.text_input(label="Description for section to extracted")
|
19 |
+
NUMBER_INPUT = st.number_input(value=0.96, label="Threshold percentage score")
|
20 |
+
|
21 |
+
SUBMIT_BUTTON = st.button("SUBMIT")
|
22 |
|
23 |
def extract_image(image, text, prob, num=1):
|
24 |
|
|
|
68 |
fi = sorted(final_ims, key=lambda item: item.get("score"), reverse=True)
|
69 |
return fi[0]['image'], fi[0]['score']
|
70 |
|
71 |
+
if SUBMIT_BUTTON:
|
72 |
+
imageOutput, scoreOutput = extract(IMAGE_INPUT, TEXT_INPUT, NUMBER_INPUT)
|
73 |
+
st.image(imageOutput, caption="Cropped Image")
|
74 |
+
st.markdown("*Confidence Score:*")
|
75 |
+
st.success(scoreOutput)
|
|