SelimGilon commited on
Commit
43ac598
·
1 Parent(s): ca42178
Files changed (1) hide show
  1. app.py +99 -99
app.py CHANGED
@@ -12,110 +12,110 @@ import gradio as gr
12
  from ultralytics import YOLO
13
 
14
 
15
- search_google = False
16
- # GOOGLE_API_KEY = "AIzaSyCD5eIu3N2uD6Vf5GE0VLBpkPsJ3mEZgA0"
17
- # GOOGLE_CSE_ID = "b536303d151b94476"
18
- # GOOGLE_API_KEY = "AIzaSyBUvPKAZa2TddKYDJI9t0ac2A_JJqdgWHo"
19
- # GOOGLE_CSE_ID = "f3446c60c52cd4dc2"
20
- # GOOGLE_API_KEY = "AIzaSyCoBYZK4khX_W5eW-AqEXKOclUIer6CiC8"
21
- # GOOGLE_CSE_ID = "c3ba01991c1a14c7d"
22
- mode = 'local'
23
- # mode = 'rbf'
24
-
25
- if mode == 'local':
26
- model = YOLO('/Users/selimgilon/Desktop/SportBoost/Projects/Iflyers/best-flyers-yolov8-1000img-v10.pt')
27
- else:
28
- rf = Roboflow(api_key="TN586SQsdwjUUvMN3H8e")
29
- project = rf.workspace().project("smartflyers")
30
- model = project.version(9).model
31
-
32
- # def process(selected_shop):
33
- # print(selected_shop)
34
- # return selected_shop
35
- hotspots_sku_links = []
36
- shop = None
37
- shops = {
38
- 'Latulippe': {
39
- 'url': 'https://latulippe.com/fr/recherche/?keywords=',
40
- 'regex': r'N° (M\d+)',
41
- 'multi_items': False,
42
- },
43
- 'Decathlon': {
44
- 'url': 'https://www.decathlon.fr/search?Ntt=',
45
- 'regex': r'Réf\. ?: ?([\d, ]+)',
46
- 'multi_items': True,
47
- 'brands': [
48
- "Allsix", "Aptonia", "Artengo", "Atorka", "B'Twin", "Caperlan", "Domyos", "Dreamscape",
49
- "FLX", "Forclaz", "Fouganza", "Geologic", "Geonaute", "Inesis", "Imviso", "Inovik",
50
- "Itiwit", "KOODZA", "KOROK", "Kalenji", "Kimjaly", "Kipsta", "Kuikma", "Nabaiji",
51
- "Newfeel", "Offload", "Olaian", "Opfeel", "Orao", "Oroks", "Outshock", "Oxelo",
52
- "Perfly", "Pongori", "Quechua", "Rockrider", "Sandever", "Simond", "Solognac",
53
- "Subea", "Tarmak", "Triban", "Tribord", "Urball", "Van Rysel", "Wed'Ze", "Decathlon"
54
- ]
55
- },
56
- 'Canadian Tire': {
57
- 'url': 'https://www.canadiantire.ca/en/search-results.html?q=',
58
- 'regex': r'(\d{2,3}-\d{4}-\d(?:/\d{4}-\d)?)',
59
- 'multi_items': True,
60
- },
61
- 'Walmart': {
62
- # 'url': 'https://www.walmart.ca/en/search?q=',
63
- 'url': '',
64
- 'regex': r'N°(\d+)',
65
- 'multi_items': False,
66
- },
67
- # Add more shops and their respective information here
68
- }
69
-
70
- regex_price = r'(\d+\.?\d*) ?([€$])|([€$]) ?(\d+\.?\d*)'
71
-
72
-
73
- # def app(img, selected_shop):
74
- # if img is None:
75
- # raise gr.Error("No file uploaded. Please upload an image.")
76
- #
77
- # # Check if the uploaded file is a PDF
78
- # if selected_shop is None:
79
- # raise gr.Error("Please select a shop.")
80
- #
81
- # try:
82
- # image_annotated = section(img)
83
- # pass
84
- # except Exception as e:
85
- # return gr.Error(f"An error occurred: {str(e)}")
86
- #
87
- # return image_annotated, hotspots_sku_links[selected_shop]
88
-
89
-
90
- def build_request(query, start=1, num=10, date_restrict=None, **params):
91
- request = {
92
- 'key': GOOGLE_API_KEY,
93
- 'q': query,
94
- 'cx': GOOGLE_CSE_ID,
95
- # 'start': start,
96
- # 'num': num,
97
- # 'dateRestrict': date_restrict,
98
- }
99
- request.update(params)
100
- return request
101
-
102
 
103
- def make_request(request):
104
- response = requests.get('https://www.googleapis.com/customsearch/v1', params=request)
105
- # print(f"Status Code: {response.status_code}") # Print status code for debugging
106
- if response.status_code != 200:
107
- raise Exception("Google Custom Search request failed with status code {}".format(response.status_code))
108
 
109
- search_results = response.json()
110
- # print(f"Response JSON: {search_results}") # Print raw response for debugging
111
- if 'items' in search_results and len(search_results['items']) > 0:
112
- first_result_url = search_results['items'][0]['link']
113
- return first_result_url
 
 
 
 
 
 
 
 
114
  else:
115
- return None
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
116
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
117
 
118
- with gr.Blocks() as demo:
119
 
120
  with gr.Row():
121
  selected_shop = gr.Dropdown(shops.keys(), label="Shop")
 
12
  from ultralytics import YOLO
13
 
14
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
15
 
 
 
 
 
 
16
 
17
+ with gr.Blocks() as demo:
18
+ search_google = False
19
+ GOOGLE_API_KEY = "AIzaSyCD5eIu3N2uD6Vf5GE0VLBpkPsJ3mEZgA0"
20
+ GOOGLE_CSE_ID = "b536303d151b94476"
21
+ # GOOGLE_API_KEY = "AIzaSyBUvPKAZa2TddKYDJI9t0ac2A_JJqdgWHo"
22
+ # GOOGLE_CSE_ID = "f3446c60c52cd4dc2"
23
+ # GOOGLE_API_KEY = "AIzaSyCoBYZK4khX_W5eW-AqEXKOclUIer6CiC8"
24
+ # GOOGLE_CSE_ID = "c3ba01991c1a14c7d"
25
+ mode = 'local'
26
+ # mode = 'rbf'
27
+
28
+ if mode == 'local':
29
+ model = YOLO('/Users/selimgilon/Desktop/SportBoost/Projects/Iflyers/best-flyers-yolov8-1000img-v10.pt')
30
  else:
31
+ rf = Roboflow(api_key="TN586SQsdwjUUvMN3H8e")
32
+ project = rf.workspace().project("smartflyers")
33
+ model = project.version(9).model
34
+
35
+ # def process(selected_shop):
36
+ # print(selected_shop)
37
+ # return selected_shop
38
+ hotspots_sku_links = []
39
+ shop = None
40
+ shops = {
41
+ 'Latulippe': {
42
+ 'url': 'https://latulippe.com/fr/recherche/?keywords=',
43
+ 'regex': r'N° (M\d+)',
44
+ 'multi_items': False,
45
+ },
46
+ 'Decathlon': {
47
+ 'url': 'https://www.decathlon.fr/search?Ntt=',
48
+ 'regex': r'Réf\. ?: ?([\d, ]+)',
49
+ 'multi_items': True,
50
+ 'brands': [
51
+ "Allsix", "Aptonia", "Artengo", "Atorka", "B'Twin", "Caperlan", "Domyos", "Dreamscape",
52
+ "FLX", "Forclaz", "Fouganza", "Geologic", "Geonaute", "Inesis", "Imviso", "Inovik",
53
+ "Itiwit", "KOODZA", "KOROK", "Kalenji", "Kimjaly", "Kipsta", "Kuikma", "Nabaiji",
54
+ "Newfeel", "Offload", "Olaian", "Opfeel", "Orao", "Oroks", "Outshock", "Oxelo",
55
+ "Perfly", "Pongori", "Quechua", "Rockrider", "Sandever", "Simond", "Solognac",
56
+ "Subea", "Tarmak", "Triban", "Tribord", "Urball", "Van Rysel", "Wed'Ze", "Decathlon"
57
+ ]
58
+ },
59
+ 'Canadian Tire': {
60
+ 'url': 'https://www.canadiantire.ca/en/search-results.html?q=',
61
+ 'regex': r'(\d{2,3}-\d{4}-\d(?:/\d{4}-\d)?)',
62
+ 'multi_items': True,
63
+ },
64
+ 'Walmart': {
65
+ # 'url': 'https://www.walmart.ca/en/search?q=',
66
+ 'url': '',
67
+ 'regex': r'N°(\d+)',
68
+ 'multi_items': False,
69
+ },
70
+ # Add more shops and their respective information here
71
+ }
72
 
73
+ regex_price = r'(\d+\.?\d*) ?([€$])|([€$]) ?(\d+\.?\d*)'
74
+
75
+
76
+ # def app(img, selected_shop):
77
+ # if img is None:
78
+ # raise gr.Error("No file uploaded. Please upload an image.")
79
+ #
80
+ # # Check if the uploaded file is a PDF
81
+ # if selected_shop is None:
82
+ # raise gr.Error("Please select a shop.")
83
+ #
84
+ # try:
85
+ # image_annotated = section(img)
86
+ # pass
87
+ # except Exception as e:
88
+ # return gr.Error(f"An error occurred: {str(e)}")
89
+ #
90
+ # return image_annotated, hotspots_sku_links[selected_shop]
91
+
92
+ def build_request(query, start=1, num=10, date_restrict=None, **params):
93
+ request = {
94
+ 'key': GOOGLE_API_KEY,
95
+ 'q': query,
96
+ 'cx': GOOGLE_CSE_ID,
97
+ # 'start': start,
98
+ # 'num': num,
99
+ # 'dateRestrict': date_restrict,
100
+ }
101
+ request.update(params)
102
+ return request
103
+
104
+
105
+ def make_request(request):
106
+ response = requests.get('https://www.googleapis.com/customsearch/v1', params=request)
107
+ # print(f"Status Code: {response.status_code}") # Print status code for debugging
108
+ if response.status_code != 200:
109
+ raise Exception("Google Custom Search request failed with status code {}".format(response.status_code))
110
+
111
+ search_results = response.json()
112
+ # print(f"Response JSON: {search_results}") # Print raw response for debugging
113
+ if 'items' in search_results and len(search_results['items']) > 0:
114
+ first_result_url = search_results['items'][0]['link']
115
+ return first_result_url
116
+ else:
117
+ return None
118
 
 
119
 
120
  with gr.Row():
121
  selected_shop = gr.Dropdown(shops.keys(), label="Shop")