File size: 1,673 Bytes
0829602
 
 
92b5c08
0fc9bde
92b5c08
0829602
92b5c08
0829602
43602f3
 
 
 
 
0829602
92b5c08
79663a3
 
a827fba
 
 
79663a3
 
7036f8f
0829602
 
 
 
 
 
92b5c08
a93db09
33f9644
0829602
43602f3
 
 
 
0829602
 
 
 
a93db09
0829602
a93db09
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
40
41
42
43
44
45
46
import gradio as gr
import pandas as pd
import numpy as np

from src.utils import *

##### Start #####

examples = [
    ["Simply Spiked Lemonade 12 pack at Walmart", "jaccard", 0.1, 0.1],
    ["Back to the Roots Garden Soil, 1 cubic foot, at Lowe's Home Improvement", "jaccard", 0.1, 0.1],
    ["Costco Member subscription", "jaccard", 0.1, 0.1],
    ["Apple watch coupon at Best Buy", "jaccard", 0.1, 0.1],
    ["A giraffe at Lincoln Park Zoo", "jaccard", 0.1, 0.1]
]

def main(sentence: str, score_type: str, threshold_cosine: float, threshold_jaccard: float = 0.1):
    threshold = threshold_cosine if score_type == "cosine" else threshold_jaccard    
    results = search_offers(search_input=sentence, 
                            score=score_type, 
                            score_threshold=threshold)
    message, processed_results = process_output(results)
    return message, processed_results

def process_output(output):
    """Function to process the output"""
    if output is None or output.empty:
        return "We couldn't find your results, please try our examples or search again", None
    else:
        return "We found some great offers!", output

demo = gr.Interface(
    fn=main,
    inputs=[
        gr.Textbox(lines=1, placeholder="Type here..."),
        gr.Dropdown(choices=["cosine", "jaccard"], label="Score Type"),
        gr.Slider(minimum=0, maximum=1, step=0.1, label="Threshold for Cosine Similarity"),
        gr.Slider(minimum=0, maximum=1, step=0.1, label="Threshold for Jaccard Similarity")
    ],
    outputs=[gr.Textbox(placeholder="Message..."), gr.Dataframe()],
    examples=examples,
    live=False,
)

demo.launch(share=True)