Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,4 +1,4 @@
|
|
| 1 |
-
from flask import Flask,render_template,request,Response,jsonify,session,redirect,url_for
|
| 2 |
import numpy as np
|
| 3 |
from sklearn.metrics.pairwise import cosine_similarity
|
| 4 |
import matplotlib.pyplot as plt
|
|
@@ -14,8 +14,7 @@ from io import BytesIO
|
|
| 14 |
app=Flask(__name__)
|
| 15 |
folder='static/images'
|
| 16 |
app.config["UPLOAD_FOLDER"]=folder
|
| 17 |
-
|
| 18 |
-
app.secret_key="mykey"
|
| 19 |
pair={}
|
| 20 |
def pred_ver_and_save_data(img,img_file,data,digit,name,vector,brand,desc,cat,price):
|
| 21 |
try:
|
|
@@ -60,7 +59,7 @@ def product_panel(product_id):
|
|
| 60 |
return render_template("product_panel.html",product=data[product_id],rec_pro=rec)
|
| 61 |
@app.route("/products",methods=["GET"])
|
| 62 |
def products():
|
| 63 |
-
if
|
| 64 |
return redirect(url_for('login'))
|
| 65 |
with open("products.json") as f:
|
| 66 |
data=json.load(f)
|
|
@@ -68,7 +67,7 @@ def products():
|
|
| 68 |
return render_template("products.html",products=data)
|
| 69 |
@app.route("/login",methods=['GET',"POST"])
|
| 70 |
def login():
|
| 71 |
-
if
|
| 72 |
with open("products.json") as file:
|
| 73 |
data=json.load(file)
|
| 74 |
file.close()
|
|
@@ -83,7 +82,7 @@ def login():
|
|
| 83 |
elif password=="":
|
| 84 |
return render_template("login.html")
|
| 85 |
elif int(password) == data[name]['password']:
|
| 86 |
-
|
| 87 |
with open("products.json") as f:
|
| 88 |
pro=json.load(f)
|
| 89 |
f.close()
|
|
@@ -94,7 +93,7 @@ def login():
|
|
| 94 |
return render_template("login.html")
|
| 95 |
@app.route("/sign_up",methods=["GET","POST"])
|
| 96 |
def sign_up():
|
| 97 |
-
if
|
| 98 |
with open("products.json") as f:
|
| 99 |
data=json.load(f)
|
| 100 |
f.close()
|
|
@@ -109,7 +108,7 @@ def sign_up():
|
|
| 109 |
if name in list(data):
|
| 110 |
return redirect(url_for("login"))
|
| 111 |
else:
|
| 112 |
-
|
| 113 |
password=request.form['confirm']
|
| 114 |
data[name]={"password":int(password),"products":[],"reviews":[]}
|
| 115 |
with open("seller.json","w") as f:
|
|
@@ -143,8 +142,8 @@ def seller():
|
|
| 143 |
with open("seller.json") as file:
|
| 144 |
seller=json.load(file)
|
| 145 |
file.close()
|
| 146 |
-
reviews=seller[
|
| 147 |
-
products=seller[
|
| 148 |
with open("products.json") as file:
|
| 149 |
prod=json.load(file)
|
| 150 |
file.close()
|
|
@@ -178,8 +177,8 @@ def tell():
|
|
| 178 |
seller=json.load(file)
|
| 179 |
file.close()
|
| 180 |
new_product_id = f"id{digit+1}"
|
| 181 |
-
if new_product_id not in seller[
|
| 182 |
-
seller[
|
| 183 |
with open("seller.json","w") as file:
|
| 184 |
json.dump(seller,file)
|
| 185 |
file.close()
|
|
@@ -189,7 +188,7 @@ def tell():
|
|
| 189 |
else:
|
| 190 |
vector=np.array(vector[:22])
|
| 191 |
threading.Thread(target=pred_ver_and_save_data,args=(img,img_file,data,digit,name,vector,brand,desc,cat,price)).start()
|
| 192 |
-
return render_template("seller_dashboard.html",ids=seller[
|
| 193 |
@app.route("/chatbot",methods=["GET","POST"])
|
| 194 |
def chatbot():
|
| 195 |
if request.method=="GET":
|
|
|
|
| 1 |
+
from flask import Flask,render_template,request,Response,jsonify,session,redirect,url_for
|
| 2 |
import numpy as np
|
| 3 |
from sklearn.metrics.pairwise import cosine_similarity
|
| 4 |
import matplotlib.pyplot as plt
|
|
|
|
| 14 |
app=Flask(__name__)
|
| 15 |
folder='static/images'
|
| 16 |
app.config["UPLOAD_FOLDER"]=folder
|
| 17 |
+
user="none"
|
|
|
|
| 18 |
pair={}
|
| 19 |
def pred_ver_and_save_data(img,img_file,data,digit,name,vector,brand,desc,cat,price):
|
| 20 |
try:
|
|
|
|
| 59 |
return render_template("product_panel.html",product=data[product_id],rec_pro=rec)
|
| 60 |
@app.route("/products",methods=["GET"])
|
| 61 |
def products():
|
| 62 |
+
if user=="null":
|
| 63 |
return redirect(url_for('login'))
|
| 64 |
with open("products.json") as f:
|
| 65 |
data=json.load(f)
|
|
|
|
| 67 |
return render_template("products.html",products=data)
|
| 68 |
@app.route("/login",methods=['GET',"POST"])
|
| 69 |
def login():
|
| 70 |
+
if user!="null"
|
| 71 |
with open("products.json") as file:
|
| 72 |
data=json.load(file)
|
| 73 |
file.close()
|
|
|
|
| 82 |
elif password=="":
|
| 83 |
return render_template("login.html")
|
| 84 |
elif int(password) == data[name]['password']:
|
| 85 |
+
user=name
|
| 86 |
with open("products.json") as f:
|
| 87 |
pro=json.load(f)
|
| 88 |
f.close()
|
|
|
|
| 93 |
return render_template("login.html")
|
| 94 |
@app.route("/sign_up",methods=["GET","POST"])
|
| 95 |
def sign_up():
|
| 96 |
+
if user!="null"
|
| 97 |
with open("products.json") as f:
|
| 98 |
data=json.load(f)
|
| 99 |
f.close()
|
|
|
|
| 108 |
if name in list(data):
|
| 109 |
return redirect(url_for("login"))
|
| 110 |
else:
|
| 111 |
+
user=name
|
| 112 |
password=request.form['confirm']
|
| 113 |
data[name]={"password":int(password),"products":[],"reviews":[]}
|
| 114 |
with open("seller.json","w") as f:
|
|
|
|
| 142 |
with open("seller.json") as file:
|
| 143 |
seller=json.load(file)
|
| 144 |
file.close()
|
| 145 |
+
reviews=seller[user]['reviews']
|
| 146 |
+
products=seller[user]['products']
|
| 147 |
with open("products.json") as file:
|
| 148 |
prod=json.load(file)
|
| 149 |
file.close()
|
|
|
|
| 177 |
seller=json.load(file)
|
| 178 |
file.close()
|
| 179 |
new_product_id = f"id{digit+1}"
|
| 180 |
+
if new_product_id not in seller[user]["products"]:
|
| 181 |
+
seller[user]["products"].append(new_product_id)
|
| 182 |
with open("seller.json","w") as file:
|
| 183 |
json.dump(seller,file)
|
| 184 |
file.close()
|
|
|
|
| 188 |
else:
|
| 189 |
vector=np.array(vector[:22])
|
| 190 |
threading.Thread(target=pred_ver_and_save_data,args=(img,img_file,data,digit,name,vector,brand,desc,cat,price)).start()
|
| 191 |
+
return render_template("seller_dashboard.html",ids=seller[user]["products"][:-1],product=data,reviews=seller[user]["reviews"])
|
| 192 |
@app.route("/chatbot",methods=["GET","POST"])
|
| 193 |
def chatbot():
|
| 194 |
if request.method=="GET":
|