Abdullah6395 commited on
Commit
99bad59
·
1 Parent(s): 8ef2fb2

made site responsive resolved image error in add products section

Browse files
__pycache__/algorithms.cpython-310.pyc CHANGED
Binary files a/__pycache__/algorithms.cpython-310.pyc and b/__pycache__/algorithms.cpython-310.pyc differ
 
app.py CHANGED
@@ -3,7 +3,6 @@ import numpy as np
3
  from sklearn.metrics.pairwise import cosine_similarity
4
  import matplotlib.pyplot as plt
5
  import pandas as pd
6
- import pickle
7
  import os
8
  import json
9
  import re
@@ -16,14 +15,14 @@ folder='static/images'
16
  app.config["UPLOAD_FOLDER"]=folder
17
  user="null"
18
  pair={}
19
- def pred_ver_and_save_data(img,img_file,data,digit,name,vector,brand,desc,cat,price):
20
  try:
21
  ans=alg.tell_vernelable(img)
22
  except Exception as e:
23
  ans=0.000001
24
  vector=list(vector)
25
  if ans>0.5:
26
- data[f"id{digit+1}"]={"name":name,"description":desc,"reviews":[],"clicks":0,"category":cat,"price":price,"brand":brand,"img":f"images/{img_file.filename}","vector":vector}
27
  else:
28
  data[f"id{digit+1}"]={"name":name,"description":desc,"reviews":[],"clicks":0,"category":cat,"price":price,"brand":brand,"img":'images/error.png',"vector":vector}
29
  with open("products.json","w") as file:
@@ -138,18 +137,18 @@ def seller():
138
  with open("products.json") as file:
139
  prod=json.load(file)
140
  file.close()
141
- return render_template("seller_dashboard.html",product=prod,ids=products,reviews=reviews)
142
  @app.route("/tell",methods=['POST',"GET"])
143
  def tell():
144
  if request.method=="GET":
145
  return render_template("add_product.html")
146
  else:
147
- img_file=request.files["image"]
148
- image_data=img_file.read()
149
- img=Image.open(BytesIO(image_data))
150
- img=np.expand_dims(np.array(img.resize((256,256))).astype(np.float32)/255,axis=0)
151
- image_path=os.path.join(app.config['UPLOAD_FOLDER'],img_file.filename)
152
- img_file.save(image_path)
153
  with open("products.json") as file:
154
  data=json.load(file)
155
  file.close()
@@ -161,25 +160,23 @@ def tell():
161
  brand=request.form["brand"]
162
  price=request.form['price']
163
  vector=name+" "+brand+" "+desc
164
- with open("tokenize_description.pkl","rb") as file:
165
- tokenizer=pickle.load(file)
166
- file.close()
167
  with open("seller.json") as file:
168
  seller=json.load(file)
169
- file.close()
170
  new_product_id = f"id{digit+1}"
171
  if new_product_id not in seller[user]["products"]:
172
  seller[user]["products"].append(new_product_id)
173
  with open("seller.json","w") as file:
174
  json.dump(seller,file)
175
  file.close()
176
- seq=[tokenizer.word_index[word] for word in vector.split() if word in tokenizer.word_index]
177
  if len(seq)<=22:
178
  vector=np.pad(seq,(22-len(seq),0))
179
  else:
180
  vector=np.array(vector[:22])
181
- threading.Thread(target=pred_ver_and_save_data,args=(img,img_file,data,digit,name,vector,brand,desc,cat,price)).start()
182
- return render_template("seller_dashboard.html",ids=seller[user]["products"][:-1],product=data,reviews=seller[user]["reviews"])
183
  @app.route("/chatbot",methods=["GET","POST"])
184
  def chatbot():
185
  if request.method=="GET":
 
3
  from sklearn.metrics.pairwise import cosine_similarity
4
  import matplotlib.pyplot as plt
5
  import pandas as pd
 
6
  import os
7
  import json
8
  import re
 
15
  app.config["UPLOAD_FOLDER"]=folder
16
  user="null"
17
  pair={}
18
+ def pred_ver_and_save_data(img,img_name,data,digit,name,vector,brand,desc,cat,price):
19
  try:
20
  ans=alg.tell_vernelable(img)
21
  except Exception as e:
22
  ans=0.000001
23
  vector=list(vector)
24
  if ans>0.5:
25
+ data[f"id{digit+1}"]={"name":name,"description":desc,"reviews":[],"clicks":0,"category":cat,"price":price,"brand":brand,"img":f"images/{img_name}","vector":vector}
26
  else:
27
  data[f"id{digit+1}"]={"name":name,"description":desc,"reviews":[],"clicks":0,"category":cat,"price":price,"brand":brand,"img":'images/error.png',"vector":vector}
28
  with open("products.json","w") as file:
 
137
  with open("products.json") as file:
138
  prod=json.load(file)
139
  file.close()
140
+ return render_template("seller_dashboard.html",user=user,product=prod,ids=products,reviews=reviews)
141
  @app.route("/tell",methods=['POST',"GET"])
142
  def tell():
143
  if request.method=="GET":
144
  return render_template("add_product.html")
145
  else:
146
+ img_file=request.files["image"]
147
+ img_name=img_file.filename
148
+ img_file=Image.open(img_file.stream).convert("RGB")
149
+ image_path=os.path.join(app.config['UPLOAD_FOLDER'],f"{img_name.split('.')[0]}.jpg")
150
+ img_file.save(image_path,"JPEG")
151
+ img=np.expand_dims(np.array(img_file.resize((256,256))).astype(np.float32)/255,axis=0)
152
  with open("products.json") as file:
153
  data=json.load(file)
154
  file.close()
 
160
  brand=request.form["brand"]
161
  price=request.form['price']
162
  vector=name+" "+brand+" "+desc
163
+ with open("tokenize_description.json","r") as file:
164
+ tokenizer=json.load(file)
 
165
  with open("seller.json") as file:
166
  seller=json.load(file)
 
167
  new_product_id = f"id{digit+1}"
168
  if new_product_id not in seller[user]["products"]:
169
  seller[user]["products"].append(new_product_id)
170
  with open("seller.json","w") as file:
171
  json.dump(seller,file)
172
  file.close()
173
+ seq=[tokenizer[word] for word in vector.split() if word in tokenizer.keys()]
174
  if len(seq)<=22:
175
  vector=np.pad(seq,(22-len(seq),0))
176
  else:
177
  vector=np.array(vector[:22])
178
+ threading.Thread(target=pred_ver_and_save_data,args=(img,img_name,data,digit,name,vector,brand,desc,cat,price)).start()
179
+ return render_template("seller_dashboard.html",user=user,ids=seller[user]["products"][:-1],product=data,reviews=seller[user]["reviews"])
180
  @app.route("/chatbot",methods=["GET","POST"])
181
  def chatbot():
182
  if request.method=="GET":
requirements.txt CHANGED
@@ -1,5 +1,4 @@
1
  onnxruntime
2
- keras
3
  scikit-learn
4
  matplotlib
5
  pandas
 
1
  onnxruntime
 
2
  scikit-learn
3
  matplotlib
4
  pandas
seller.json CHANGED
@@ -1 +1 @@
1
- {"username1": {"password": 123, "products": ["id1"], "reviews": ["this product is useless", "you are worst", "quality is poor", "not worth the price", "delivered late", "item damaged", "waste of money", "terrible experience", "not recommended", "customer service is bad"]}, "username2": {"password": 123, "products": ["id2"], "reviews": ["amazing quality", "not worth the price", "fast shipping", "great product", "superb quality", "perfect as described", "worth every penny", "customer service was helpful", "highly recommended", "would buy again"]}, "username3": {"password": 123, "products": ["id3"], "reviews": ["fast delivery", "poor packaging", "product arrived broken", "not what I expected", "color is different", "overpriced", "excellent quality", "customer service ignored me", "works perfectly", "great buy"]}, "username4": {"password": 123, "products": ["id4"], "reviews": ["great value for money", "never buying again", "loved it", "very stylish", "does not match description", "cheap material", "exactly what I needed", "highly durable", "better than expected", "shipping was slow"]}, "username5": {"password": 123, "products": ["id5"], "reviews": ["product exceeded expectations", "color is different than shown", "worth the money", "not as advertised", "great product", "customer service was unhelpful", "high quality", "defective item", "came with missing parts", "fantastic experience"]}, "username6": {"password": 123, "products": ["id6"], "reviews": ["would recommend", "terrible customer service", "fantastic purchase", "superb build quality", "not happy with the product", "too expensive", "great performance", "came in excellent packaging", "return process was easy", "item was different from the picture"]}, "username7": {"password": 123, "products": ["id7"], "reviews": ["excellent packaging", "item missing", "shipping was too slow", "love this product", "not as described", "completely broken on arrival", "exactly what I wanted", "very poor material", "well-designed product", "not worth the money"]}, "username8": {"password": 123, "products": ["id8"], "reviews": ["satisfied with the purchase", "too expensive", "great customer service", "did not work as expected", "very high quality", "delivery was quick", "the item is fantastic", "superb craftsmanship", "not durable", "looks cheap"]}, "username9": {"password": 123, "products": ["id9"], "reviews": ["not as described", "arrived late", "works fine", "completely disappointed", "best product I ever bought", "size is incorrect", "colors are vibrant", "not a good experience", "highly recommended", "worst purchase ever"]}, "username10": {"password": 123, "products": ["id10"], "reviews": ["absolutely love it", "not working", "excellent quality", "money well spent", "received wrong item", "customer service was great", "superb value", "totally unreliable", "fast shipping", "best purchase ever"]}, "abdullah": {"password": 123, "products": [], "reviews": []}}
 
1
+ {"username1": {"password": 123, "products": ["id1"], "reviews": ["this product is useless", "you are worst", "quality is poor", "not worth the price", "delivered late", "item damaged", "waste of money", "terrible experience", "not recommended", "customer service is bad"]}, "username2": {"password": 123, "products": ["id2"], "reviews": ["amazing quality", "not worth the price", "fast shipping", "great product", "superb quality", "perfect as described", "worth every penny", "customer service was helpful", "highly recommended", "would buy again"]}, "username3": {"password": 123, "products": ["id3"], "reviews": ["fast delivery", "poor packaging", "product arrived broken", "not what I expected", "color is different", "overpriced", "excellent quality", "customer service ignored me", "works perfectly", "great buy"]}, "username4": {"password": 123, "products": ["id4"], "reviews": ["great value for money", "never buying again", "loved it", "very stylish", "does not match description", "cheap material", "exactly what I needed", "highly durable", "better than expected", "shipping was slow"]}, "username5": {"password": 123, "products": ["id5"], "reviews": ["product exceeded expectations", "color is different than shown", "worth the money", "not as advertised", "great product", "customer service was unhelpful", "high quality", "defective item", "came with missing parts", "fantastic experience"]}, "username6": {"password": 123, "products": ["id6"], "reviews": ["would recommend", "terrible customer service", "fantastic purchase", "superb build quality", "not happy with the product", "too expensive", "great performance", "came in excellent packaging", "return process was easy", "item was different from the picture"]}, "username7": {"password": 123, "products": ["id7"], "reviews": ["excellent packaging", "item missing", "shipping was too slow", "love this product", "not as described", "completely broken on arrival", "exactly what I wanted", "very poor material", "well-designed product", "not worth the money"]}, "username8": {"password": 123, "products": ["id8"], "reviews": ["satisfied with the purchase", "too expensive", "great customer service", "did not work as expected", "very high quality", "delivery was quick", "the item is fantastic", "superb craftsmanship", "not durable", "looks cheap"]}, "username9": {"password": 123, "products": ["id9"], "reviews": ["not as described", "arrived late", "works fine", "completely disappointed", "best product I ever bought", "size is incorrect", "colors are vibrant", "not a good experience", "highly recommended", "worst purchase ever"]}, "username10": {"password": 123, "products": ["id10"], "reviews": ["absolutely love it", "not working", "excellent quality", "money well spent", "received wrong item", "customer service was great", "superb value", "totally unreliable", "fast shipping", "best purchase ever"]}}
static/css/chatbot.css CHANGED
@@ -4,7 +4,7 @@
4
  border: 5px solid black;
5
  bottom: 20px;
6
  left: 5px;
7
- right: 5%;
8
  height:50px ;
9
  font-size: larger;
10
  }
@@ -18,11 +18,11 @@
18
  border-radius: 20px;
19
  font-size: larger;
20
  bottom: 25px;
21
- left:95%;
22
  background-color: black;
23
  color: white;
24
  width: 70px;
25
  height: 50px;
 
26
  }
27
  .question{
28
  width:200px;
 
4
  border: 5px solid black;
5
  bottom: 20px;
6
  left: 5px;
7
+ right:75px;
8
  height:50px ;
9
  font-size: larger;
10
  }
 
18
  border-radius: 20px;
19
  font-size: larger;
20
  bottom: 25px;
 
21
  background-color: black;
22
  color: white;
23
  width: 70px;
24
  height: 50px;
25
+ right: 0;
26
  }
27
  .question{
28
  width:200px;
static/css/login_style.css CHANGED
@@ -12,8 +12,9 @@
12
 
13
  }
14
  .element{
 
15
  margin-bottom: 10px;
16
- border-radius: 10px;
17
  }
18
  h1{
19
  text-align: center;
@@ -35,7 +36,7 @@ body{
35
  top:0;
36
  left:0;
37
  right:0;
38
- background-image: url("../images/login.jpg");
39
  background-repeat: no-repeat;
40
  background-size: 100%;
41
  }
 
12
 
13
  }
14
  .element{
15
+ padding:5px;
16
  margin-bottom: 10px;
17
+ border-radius: 5px;
18
  }
19
  h1{
20
  text-align: center;
 
36
  top:0;
37
  left:0;
38
  right:0;
39
+ background-color: aqua;
40
  background-repeat: no-repeat;
41
  background-size: 100%;
42
  }
static/css/product_panel.css CHANGED
@@ -1,12 +1,13 @@
1
  .recomendation{
2
  display:flex;
3
- flex-wrap: wrap;
 
4
  }
5
  .rec_prod{
6
- width: 280px;
7
- height:450px;
8
- margin-left: 10px;
9
- margin-bottom: 10px;
10
- border: 1px solid wheat;
11
- background-color: antiquewhite;
12
  }
 
1
  .recomendation{
2
  display:flex;
3
+ flex-wrap: wrap;
4
+ justify-content: space-around;
5
  }
6
  .rec_prod{
7
+ text-align: left;
8
+ font-size: large;
9
+ }
10
+ .buton{
11
+ padding: 10px;
12
+ margin: 10px;
13
  }
static/css/welcome.css CHANGED
@@ -16,6 +16,7 @@
16
  right: 15%;
17
  }
18
  .welcome{
 
19
  font-size: 70px;
20
  color:white;
21
  }
 
16
  right: 15%;
17
  }
18
  .welcome{
19
+ text-align: center;
20
  font-size: 70px;
21
  color:white;
22
  }
static/images/pro2.jpg CHANGED
templates/product_panel.html CHANGED
@@ -8,21 +8,25 @@
8
  </head>
9
  <body>
10
  <img src="{{url_for('static',filename=product['img'])}}" alt="product">
11
- <h1>{{product["name"]}}</h1>
12
- <h2>{{product['price']}}</h2>
 
 
13
  <h1>Description</h1>
14
- <p>{{product['description']}}</p>
15
  <h1>Recomendation<h1>
16
  <div class="recomendation">
17
  {% for id_pro in rec_pro %}
18
- <a href="{{url_for('product_panel',product_id=id_pro)}}">
19
- <div class="rec_prod">
20
- <img src="{{url_for('static',filename=rec_pro[id_pro]['img'])}}" alt="image" width="250px" height="250px">
21
- <div>{{rec_pro[id_pro]["name"]}}</div>
22
- <div>{{rec_pro[id_pro]['brand']}}</div>
23
- <div>{{rec_pro[id_pro]['price']}}</div>
24
- </div>
25
- </a>
 
 
26
  {% endfor %}
27
  </div>
28
  </body>
 
8
  </head>
9
  <body>
10
  <img src="{{url_for('static',filename=product['img'])}}" alt="product">
11
+ <h1>Name</h1>
12
+ <h3>{{product["name"]}}</h3>
13
+ <h1>Price</h1>
14
+ <h3>{{product['price']}}</h3>
15
  <h1>Description</h1>
16
+ <h3>{{product['description']}}</h3>
17
  <h1>Recomendation<h1>
18
  <div class="recomendation">
19
  {% for id_pro in rec_pro %}
20
+ <form action="{{url_for('product_panel',product_id=id_pro)}}" method="get">
21
+ <button type="submit" class="buton">
22
+ <div class="rec_prod">
23
+ <img src="{{url_for('static',filename=rec_pro[id_pro]['img'])}}" alt="image" width="250px" height="250px">
24
+ <div>{{rec_pro[id_pro]["name"]}}</div>
25
+ <div>{{rec_pro[id_pro]['brand']}}</div>
26
+ <div>{{rec_pro[id_pro]['price']}}</div>
27
+ </div>
28
+ </button>
29
+ </form>
30
  {% endfor %}
31
  </div>
32
  </body>
templates/products.html CHANGED
@@ -37,9 +37,16 @@
37
  font-size: 20px;
38
  }
39
  #suggestions{
40
- width: 400px; height:50px; border: 1px solid #ccc; display: none; position: absolute; background: white;
41
- margin-left: 515px;
 
 
 
 
42
  font-size: large;
 
 
 
43
  }
44
  .but{
45
  height: 50px;
@@ -52,11 +59,14 @@
52
  background-image: linear-gradient(pink,orange);
53
  }
54
  .Products{
55
- display: flex;
56
- flex-wrap: wrap;
 
57
  }
58
  .Product{
59
- margin: 20px;
 
 
60
  }
61
  </style>
62
  </head>
@@ -68,7 +78,7 @@
68
  <button type="submit" class="but">Dashboard</button>
69
  </form>
70
  </div>
71
- <div id="suggestions">hello</div>
72
  <script>
73
  const searchBox = document.getElementById("searchBox");
74
  const suggestionsBox = document.getElementById("suggestions");
@@ -115,8 +125,6 @@
115
  event.preventDefault();
116
  }
117
  });
118
-
119
- // Hide suggestions when clicking outside
120
  document.addEventListener("click", function(event) {
121
  if (!searchBox.contains(event.target)) {
122
  suggestionsBox.style.display = "none";
@@ -156,13 +164,16 @@
156
  </div>
157
  <div class="Products">
158
  {% for id in products %}
159
- <a href="{{url_for("product_panel",product_id=id)}}">
160
- <div class="Product">
161
- <img src="{{url_for('static',filename=products[id]['img'])}}" alt="img" width="250px" height="250px">
162
- <p>{{products[id]['name']}}</p>
163
- <p>{{products[id]['price']}}</p>
164
- <p>{{products[id]['brand']}}</p>
165
- </div>
 
 
 
166
  {%endfor%}
167
  </div>
168
  <form action="/chatbot" method="get">
 
37
  font-size: 20px;
38
  }
39
  #suggestions{
40
+ position: absolute;
41
+ width: auto;
42
+ height: 50px;
43
+ border: 1px solid #ccc;
44
+ display: none;
45
+ background: white;
46
  font-size: large;
47
+ margin: 0;
48
+ right:33%;
49
+ left:33%;
50
  }
51
  .but{
52
  height: 50px;
 
59
  background-image: linear-gradient(pink,orange);
60
  }
61
  .Products{
62
+ display: flex;
63
+ flex-wrap: wrap;
64
+ justify-content: space-around;
65
  }
66
  .Product{
67
+ margin: 20px;
68
+ text-align: left;
69
+ font-size: large;
70
  }
71
  </style>
72
  </head>
 
78
  <button type="submit" class="but">Dashboard</button>
79
  </form>
80
  </div>
81
+ <div id="suggestions">hello</div>
82
  <script>
83
  const searchBox = document.getElementById("searchBox");
84
  const suggestionsBox = document.getElementById("suggestions");
 
125
  event.preventDefault();
126
  }
127
  });
 
 
128
  document.addEventListener("click", function(event) {
129
  if (!searchBox.contains(event.target)) {
130
  suggestionsBox.style.display = "none";
 
164
  </div>
165
  <div class="Products">
166
  {% for id in products %}
167
+ <form action="{{url_for("product_panel",product_id=id)}}">
168
+ <button type="submit" class="Product">
169
+ <div class="Product">
170
+ <img src="{{url_for('static',filename=products[id]['img'])}}" alt="img" width="250px" height="250px">
171
+ <p>{{products[id]['name']}}</p>
172
+ <p>{{products[id]['price']}}</p>
173
+ <p>{{products[id]['brand']}}</p>
174
+ </div>
175
+ </button>
176
+ </form>
177
  {%endfor%}
178
  </div>
179
  <form action="/chatbot" method="get">
templates/seller_dashboard.html CHANGED
@@ -13,7 +13,7 @@
13
  Marketplace
14
  </button>
15
  </form>
16
- <h1>Hi {{session['user']}} lets make day of others sweet</h1>
17
  <form action="/tell" method="get">
18
  <button type="submit">Add Products</button>
19
  </form>
 
13
  Marketplace
14
  </button>
15
  </form>
16
+ <h1>Hi {{user}} lets make day of others sweet</h1>
17
  <form action="/tell" method="get">
18
  <button type="submit">Add Products</button>
19
  </form>
tokenize_description.json ADDED
@@ -0,0 +1 @@
 
 
1
+ {"and": 1, "a": 2, "skin": 3, "with": 4, "to": 5, "serum": 6, "face": 7, "cream": 8, "that": 9, "organic": 10, "care": 11, "lux": 12, "hashmi": 13, "the": 14, "goat": 15, "milk": 16, "soap": 17, "brighten": 18, "for": 19, "luxury": 20, "ingredients": 21, "hair": 22, "reduce": 23, "shea": 24, "butter": 25, "body": 26, "lotion": 27, "deeply": 28, "infused": 29, "soft": 30, "charcoal": 31, "mask": 32, "anti": 33, "aging": 34, "aloe": 35, "vera": 36, "gel": 37, "rose": 38, "water": 39, "facial": 40, "vitamin": 41, "c": 42, "hand": 43, "whitening": 44, "gentle": 45, "enriched": 46, "nourish": 47, "perfect": 48, "sensitive": 49, "types": 50, "premium": 51, "hydrates": 52, "smoothens": 53, "high": 54, "quality": 55, "radiant": 56, "look": 57, "nourishing": 58, "made": 59, "promote": 60, "shine": 61, "frizz": 62, "moisturizing": 63, "keep": 64, "hydrated": 65, "detox": 66, "purifying": 67, "activated": 68, "remove": 69, "toxins": 70, "cleanse": 71, "pores": 72, "powerful": 73, "reduces": 74, "fine": 75, "lines": 76, "improves": 77, "elasticity": 78, "over": 79, "time": 80, "pure": 81, "soothes": 82, "irritated": 83, "provides": 84, "deep": 85, "hydration": 86, "spray": 87, "refreshing": 88, "mist": 89, "revitalize": 90, "tone": 91, "lightweight": 92, "dark": 93, "spots": 94, "rich": 95, "hydrating": 96, "keeps": 97, "hands": 98, "moisturized": 99, "throughout": 100, "day": 101}
tokenize_description.pkl DELETED
@@ -1,3 +0,0 @@
1
- version https://git-lfs.github.com/spec/v1
2
- oid sha256:54cac1a53721b2a05d3dbedcca40d5f54487e6fd35be4839c8c62c08465e30ab
3
- size 3083