forked from niru17/CSE6332_Assignment1
-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.py
107 lines (92 loc) · 3.98 KB
/
app.py
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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
from flask import Flask
from flask import render_template
from flask import request
from flask import url_for
from PIL import Image
import csv
import pandas as pd
from PIL import Image
import base64
import io
from flask import Flask, request, render_template, redirect, url_for
from werkzeug.utils import secure_filename
from azure.storage.blob import BlobServiceClient
import os
from io import BytesIO
from IPython.display import HTML
app = Flask(__name__)
app = Flask(__name__, static_folder='static', static_url_path='')
app.config.from_pyfile('config.py')
account = app.config['ACCOUNT_NAME'] # Azure account name
key = app.config['ACCOUNT_KEY'] # Azure Storage account access key
connect_str = app.config['CONNECTION_STRING']
container = app.config['CONTAINER'] # Container name
allowed_ext = app.config['ALLOWED_EXTENSIONS'] # List of accepted extensions
blob_service_client = BlobServiceClient.from_connection_string(connect_str)
@app.route('/', methods = ["GET","POST"])
def Name():
photo_name = 'cat.jpg'
image = Image.open(photo_name)
data=io.BytesIO()
image.save(data,"JPEG")
encoded_img_data = base64.b64encode(data.getvalue())
p = encoded_img_data.decode('UTF-8')
return render_template("Name.html",photo_name=p)
@app.route('/user', methods = ["POST"])
def user():
df = pd.read_csv("data-1.csv",on_bad_lines='skip')
name = request.form["name"]
for i in df["name"]:
if i !=name:
next
elif i ==name:
pdict = zip(df.name,df.picture)
pdict=dict(pdict)
state = df[df["name"]==i]["class"].values[0]
print("{}'s class is {}".format(i,state))
photo_name = pdict[i]
image = Image.open(photo_name)
data=io.BytesIO()
image.save(data,"JPEG")
encoded_img_data = base64.b64encode(data.getvalue())
return render_template('user.html',user=name,state=state,photo_name=encoded_img_data.decode('utf-8'))
return render_template('not_found.html')
@app.route('/get_salary', methods = ["GET", "POST"])
def salary_input():
return render_template('get_salary.html')
@app.route('/salary', methods = ["POST"])
def salary():
df_op = pd.DataFrame()
sal = request.form["sal"].isdigit()
sal1 = request.form["sal1"].isdigit()
df = pd.read_csv("data-1.csv",on_bad_lines='skip')
df = pd.read_csv("data-1.csv", converters={'income': int})
#df['income'] = df['income'].fillna(0)
#df['income'] = pd.to_numeric(df['income'])
df_op = df.loc[(df['num'] >= sal) & (df['num'] <= sal1)]
return render_template('salary.html',tables = [df_op.to_html()], titles=['name','income','comments'])
@app.route('/nameinc', methods = ["GET", "POST"])
def nameinc_input():
return render_template('nameinc.html')
@app.route('/update', methods = ["GET", "POST"])
def nameinc():
df = pd.read_csv("data-1.csv",on_bad_lines='skip')
df_op = pd.DataFrame()
name = request.form["name"]
year = request.form["sal1"]
comments = request.form["text"]
#df_op = df.loc[df.name == name, ['name','income', 'comments']] = name,inc, comments
df.loc[df.name == name, ['name','year', 'comments']] = name,year, comments
df.to_csv ("data-1.csv", index = None, header=True)
return render_template('update.html',name=name,tables=[df.to_html()],titles=['name','year','comments'],comments=comments)
@app.route('/picture', methods = ["GET","POST"])
def picture():
df = pd.read_csv("data-1.csv",on_bad_lines='skip')
df.loc[df.picture == ' ', 'picture'] = 'No_Picture.jpg'
df.loc[df.picture == 'Nan', 'picture'] = 'No_Picture.jpg'
df.to_csv ("data-1.csv", index = None, header=True)
pdict = zip(df.name,df.picture)
pdict=dict(pdict)
return render_template("picture.html",tables=[df.to_html()],titles=['name','year','comments'],image_name=pdict)
if __name__ == "__main__":
app.run(debug = True)