rxavier commited on
Commit
fe51ab9
1 Parent(s): 12b78a4

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +27 -0
app.py ADDED
@@ -0,0 +1,27 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import gradio as gr
2
+
3
+ from . import OffTopicDetector
4
+
5
+ detector = OffTopicDetector("openai/clip-vit-base-patch32")
6
+
7
+ def validate(item_id: str, threshold: float):
8
+ images, domain, probas, valid_probas, invalid_probas = detector.predict_item_probas(item_id)
9
+ valid_images = [x for i, x in enumerate(images) if valid_probas[i].squeeze() >= threshold]
10
+ invalid_images = [x for i, x in enumerate(images) if valid_probas[i].squeeze() < threshold]
11
+ return valid_images, invalid_images
12
+
13
+
14
+ with gr.Blocks() as demo:
15
+ with gr.Tabs():
16
+ with gr.Tab("From Item ID"):
17
+ item_id = gr.Textbox(label="Item ID")
18
+ threshold = gr.Number(label="Threshold", value=0.5)
19
+ submit = gr.Button("Submit")
20
+ valid = gr.Gallery(label="Valid images").style(grid=[1, 2, 3], height="auto")
21
+ invalid = gr.Gallery(label="Invalid images").style(grid=[1, 2, 3], height="auto")
22
+ submit.click(inputs=[item_id, threshold], outputs=[valid, invalid], fn=validate)
23
+
24
+
25
+ demo.launch()
26
+
27
+