File size: 1,020 Bytes
d29ec33
 
 
 
 
 
5fbaaf1
 
 
 
 
 
 
 
 
d29ec33
 
ef01d24
 
 
 
 
d29ec33
 
 
3aca399
40f14c1
5fbaaf1
 
 
 
 
 
 
 
 
84fd755
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
from product_update_validator import Update_Validator
import gradio as gr

update_validator = Update_Validator(text_model="DistilRoBERTa-v1", image_model="CLIP-ViT Base", threshold=0.75)

def gradio_interface(text1, image1, text2, image2, threshold=0.75):
    out = update_validator.validate(
        text1=text1,
        image1=image1,
        text2=text2,
        image2=image2,
        threshold=threshold,
        return_score=True
    )
    return out['score'], "Valid" if out['label'] else "Invalid"

inputs = [
    gr.Textbox(lines=5, label="Description 1"),
    gr.Image(type="pil", label="Image 1"),
    gr.Textbox(lines=5, label="Description 2"),
    gr.Image(type="pil", label="Image 2"),
    gr.Slider(minimum=0, maximum=1, value=0.75, step=0.01, label="Similarity Threshold")
]

outputs = [
    gr.Number(label="Similarity Score"),
    gr.Textbox(label="Label")
]

iface = gr.Interface(
    fn=gradio_interface,
    inputs=inputs,
    outputs=outputs,
    title="Product Update Validator"
)

iface.launch()