-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.py
64 lines (50 loc) · 1.79 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
import os
import requests
from flask import Flask, render_template,request
from flask_restful import Resource, Api, reqparse
app = Flask(__name__)
@app.route("/")
def hello():
return render_template("index.html")
# 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/aniketface/DialoGPT-product"
headers = {"Authorization": f"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
if output.get('generated_text', 0):
return {'data': output['generated_text']}
else:
return {'data': "Sorry, Server Error"}
api.add_resource(HelloWorld, '/api')
@app.route('/chat-bot')
def chat():
return render_template('speak_to_an_expert.html')
@app.route("/api-call", methods=["GET", "POST"])
def apiCall():
API_URL = "https://api-inference.huggingface.co/models/aniketface/DialoGPT-product"
headers = {"Authorization": f"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)
if __name__ == "__main__":
app.run(debug=True)