vishnun commited on
Commit
ec563f5
·
1 Parent(s): 424c263

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +19 -16
app.py CHANGED
@@ -1,20 +1,24 @@
1
- import gradio as gr
2
  import numpy as np
3
  from PIL import Image
4
  from transformers import CLIPProcessor, CLIPModel, YolosImageProcessor, YolosForObjectDetection
5
  import torch
6
 
7
- feature_extractor = YolosImageProcessor.from_pretrained("hustvl/yolos-tiny")
8
- dmodel = YolosForObjectDetection.from_pretrained('hustvl/yolos-tiny')
9
 
10
- model = CLIPModel.from_pretrained("openai/clip-vit-base-patch16")
11
- processor = CLIPProcessor.from_pretrained("openai/clip-vit-base-patch16")
 
12
 
13
- i1 = gr.Image(type="pil", label="Input image")
14
- i2 = gr.Textbox(label="Description for section to extracted")
15
- i3 = gr.Number(value=0.96, label="Threshold percentage score")
16
- o1 = gr.Image(type="pil", label="Extracted Crop part")
17
- o2 = gr.Textbox(label="Similarity score")
 
 
 
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
- title = "ClipnCrop"
68
- description = "<p style= 'color:white'>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.</p>"
69
- examples=[['ex3.jpg', 'black bag', 0.96],['ex2.jpg', 'man in red dress', 0.85]]
70
- article = "<p style= 'color:white; text-align:center;'><a href='https://github.com/Vishnunkumar/clipcrop' target='_blank'>clipcrop</a></p>"
71
- gr_app = gr.Interface(fn=extract_image, inputs=[i1, i2, i3], outputs=[o1, o2], title=title, description=description, article=article, examples=examples, concurrency_limit=20)
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)