-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.py
149 lines (117 loc) · 4.19 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
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
import imp
from flask import Flask, jsonify, render_template, request
import joblib
import numpy as np
import requests
from flask_restful import Resource, Api,reqparse
from fire import Uploader
from realtime import RealTimeDataCall
app = Flask(__name__)
upl = Uploader()
obj = RealTimeDataCall()
# apis
api = Api(app)
parser = reqparse.RequestParser()
parser.add_argument('message', type=str, location='json')
class HelloWorld(Resource):
def post(self):
json_data = request.get_json(force=True)
msg = json_data['message']
API_URL = "https://api-inference.huggingface.co/models/ANIKEThash/DialoGPT-medium-character"
headers = {"Authorization": "Bearer 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"}
form_data = request.form
input = msg
def query(payload):
response = requests.post(API_URL, headers=headers, json=payload)
return response.json()
output = query({
"inputs": input
})
# take input output here
print(output['generated_text'])
return {'data': output['generated_text']}
api.add_resource(HelloWorld, '/api')
@app.route("/")
def hello():
return render_template("index.html")
@app.route("/speak")
def speak_expert():
return render_template("speak_to_an_expert.html")
# Carrer choice
@app.route("/forms")
def forms():
return render_template("forms.html")
@app.route("/form-action", methods = ['POST', 'GET'])
def form_action():
model = joblib.load("Model.joblib")
form_data = request.form
pred_arr = [form_data["location"],form_data["branch"],form_data["Marks"]]
upl.upload_career(pred_arr)
pred_arr = [int(elem) for elem in pred_arr]
pred_arr = np.array(pred_arr).reshape(1, -1)
pred = model.predict(pred_arr)[0]
pred = pred[0].upper() + pred[1:]
obj.runtimeCall()
return render_template("display.html", pred=pred)
# Job
@app.route("/forms1")
def forms1():
return render_template("forms1.html")
@app.route("/form-action1", methods = ['POST', 'GET'])
def form_action1():
model = joblib.load("ModelJob.joblib")
form_data = request.form
pred_arr = [form_data["Age"], form_data["Location"], form_data["Current Qualification"], form_data["Strength"], form_data["Experience"],
form_data["Salary Expectation"], form_data["Hobbies"]]
upl.upload_job(pred_arr)
pred_arr = [int(elem) for elem in pred_arr]
pred_arr = np.array(pred_arr).reshape(1, -1)
pred = model.predict(pred_arr)[0]
pred = pred[0].upper() + pred[1:]
obj.runtimeCall()
return render_template("display1.html", pred=pred)
# Courses
@app.route("/forms2")
def forms2():
return render_template("forms2.html")
@app.route("/form-action2", methods = ['POST', 'GET'])
def form_action2():
model = joblib.load("Modelcourse.joblib")
form_data = request.form
pred_arr = [form_data["Interested"], form_data["Location"], form_data["Duration"]]
upl.upload_courses(pred_arr)
pred_arr = [int(elem) for elem in pred_arr]
pred_arr = np.array(pred_arr).reshape(1, -1)
pred = model.predict(pred_arr)[0]
# pred = pred[0].upper() + pred[1:]
obj.runtimeCall()
return render_template("display2.html", pred=pred)
@app.route("/api-call", methods=["GET", "POST"])
def apiCall():
API_URL = "https://api-inference.huggingface.co/models/ANIKEThash/DialoGPT-medium-character"
headers = {"Authorization": "Bearer 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"}
form_data = request.form
input = form_data["msg"]
def query(payload):
response = requests.post(API_URL, headers=headers, json=payload)
return response.json()
output = query({
"inputs": input
})
return render_template("ouput.html", output=output)
@app.route("/#")
def login():
return render_template("login.html")
@app.route("/send-data", methods=["GET", "POST"])
def send():
form_data = request.form
upl.upload(form_data["name"],
form_data["email"],
form_data["phone"],
form_data["mssg"])
return render_template("index.html")
@app.route("/#")
def #():
return render_template("#.html")
if __name__ == "__main__":
app.run(debug=True)