hjianganthony commited on
Commit
92b5c08
·
1 Parent(s): 611275b
Files changed (1) hide show
  1. app.py +77 -61
app.py CHANGED
@@ -1,62 +1,78 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
  import gradio as gr
2
- import pandas as pd
3
- import numpy as np
4
-
5
- import pickle, json
6
- from src.utils import *
7
-
8
- ##### Start #####
9
-
10
- # load operation data
11
- path1 = "data/brand_belong_category_dict.json"
12
- path2 = "data/product_upper_category_dict.json"
13
- path3 = "data/offered_brands.pkl"
14
- path4 = "data/offer_retailer.csv"
15
-
16
- with open(path1, 'r') as f:
17
- brand_belong_category_dict = json.load(f)
18
-
19
- with open(path2, 'rb') as f:
20
- category_dict = json.load(f)
21
-
22
- with open(path3, 'rb') as f:
23
- offered_brands = pickle.load(f)
24
-
25
- df_offers_brand_retailer = pd.read_csv(path4)
26
-
27
- examples = [
28
- ["Simply Spiked Lemonade 12 pack at Walmart"],
29
- ["Back to the Roots Garden Soil, 1 cubic foot, at Lowe's Home Improvement"],
30
- ["Costco Member subscription"],
31
- ["Apple watch coupon at Best Buy"],
32
- ["A giraffe at Lincoln Park Zoo"]
33
- ]
34
-
35
- def main(sentence: str, score_type: str, threshold_cosine: float, threshold_jaccard: float):
36
- threshold = threshold_cosine if score_type == "cosine" else threshold_jaccard
37
- results = search_offers(sentence, df_offers_brand_retailer, category_dict, brand_belong_category_dict, score_type, threshold)
38
- message, processed_results = process_output(results)
39
- return message, processed_results
40
-
41
- def process_output(output):
42
- """Function to process the output"""
43
- if output is None or output.empty:
44
- return "We couldn't find your results, please try our examples or search again", None
45
- else:
46
- return "We found some great offers!", output
47
-
48
- iface = gr.Interface(
49
- fn=main,
50
- inputs=[
51
- gr.Textbox(lines=1, placeholder="Type here..."),
52
- gr.Dropdown(choices=["cosine", "jaccard"], label="Score Type"),
53
- gr.Slider(minimum=0, maximum=1, step=0.1, label="Threshold for Cosine Similarity"),
54
- gr.Slider(minimum=0, maximum=1, step=0.1, label="Threshold for Jaccard Similarity")
55
- ],
56
- outputs=[gr.Textbox(placeholder="Message..."), gr.Dataframe()],
57
- examples=examples,
58
- live=False,
59
- )
60
-
61
-
62
- iface.launch(share=True)
 
1
+ # import gradio as gr
2
+ # import pandas as pd
3
+ # import numpy as np
4
+
5
+ # import pickle, json
6
+ # from src.utils import *
7
+
8
+ # ##### Start #####
9
+
10
+ # # load operation data
11
+ # path1 = "data/brand_belong_category_dict.json"
12
+ # path2 = "data/product_upper_category_dict.json"
13
+ # path3 = "data/offered_brands.pkl"
14
+ # path4 = "data/offer_retailer.csv"
15
+
16
+ # with open(path1, 'r') as f:
17
+ # brand_belong_category_dict = json.load(f)
18
+
19
+ # with open(path2, 'rb') as f:
20
+ # category_dict = json.load(f)
21
+
22
+ # with open(path3, 'rb') as f:
23
+ # offered_brands = pickle.load(f)
24
+
25
+ # df_offers_brand_retailer = pd.read_csv(path4)
26
+
27
+ # examples = [
28
+ # ["Simply Spiked Lemonade 12 pack at Walmart"],
29
+ # ["Back to the Roots Garden Soil, 1 cubic foot, at Lowe's Home Improvement"],
30
+ # ["Costco Member subscription"],
31
+ # ["Apple watch coupon at Best Buy"],
32
+ # ["A giraffe at Lincoln Park Zoo"]
33
+ # ]
34
+
35
+ # def main(sentence: str, score_type: str, threshold_cosine: float, threshold_jaccard: float):
36
+ # threshold = threshold_cosine if score_type == "cosine" else threshold_jaccard
37
+ # results = search_offers(sentence, df_offers_brand_retailer, category_dict, brand_belong_category_dict, score_type, threshold)
38
+ # message, processed_results = process_output(results)
39
+ # return message, processed_results
40
+
41
+ # def process_output(output):
42
+ # """Function to process the output"""
43
+ # if output is None or output.empty:
44
+ # return "We couldn't find your results, please try our examples or search again", None
45
+ # else:
46
+ # return "We found some great offers!", output
47
+
48
+ # iface = gr.Interface(
49
+ # fn=main,
50
+ # inputs=[
51
+ # gr.Textbox(lines=1, placeholder="Type here..."),
52
+ # gr.Dropdown(choices=["cosine", "jaccard"], label="Score Type"),
53
+ # gr.Slider(minimum=0, maximum=1, step=0.1, label="Threshold for Cosine Similarity"),
54
+ # gr.Slider(minimum=0, maximum=1, step=0.1, label="Threshold for Jaccard Similarity")
55
+ # ],
56
+ # outputs=[gr.Textbox(placeholder="Message..."), gr.Dataframe()],
57
+ # examples=examples,
58
+ # live=False,
59
+ # )
60
+
61
+
62
+ # iface.launch(share=True)
63
+
64
  import gradio as gr
65
+ from transformers import pipeline
66
+
67
+ pipeline = pipeline(task="image-classification", model="julien-c/hotdog-not-hotdog")
68
+
69
+ def predict(image):
70
+ predictions = pipeline(image)
71
+ return {p["label"]: p["score"] for p in predictions}
72
+
73
+ gr.Interface(
74
+ predict,
75
+ inputs=gr.inputs.Image(label="Upload hot dog candidate", type="filepath"),
76
+ outputs=gr.outputs.Label(num_top_classes=2),
77
+ title="Hot Dog? Or Not?",
78
+ ).launch()