-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.py
55 lines (29 loc) · 757 Bytes
/
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
from flask import Flask, jsonify, request
from flask_ngrok import run_with_ngrok
from dotenv import load_dotenv
import os
import openai
load_dotenv()
app = Flask(__name__)
run_with_ngrok(app)
@app.route('/')
def appname():
return "Hello World!"
@app.route("/demo", methods=['POST'])
def keywords():
openai.api_key = os.getenv("OPENAI_API_KEY")
ptext = request.json['ptext']
response = openai.Completion.create(
model="text-davinci-002",
prompt= ptext,
temperature=0.3,
max_tokens=2500,
top_p=1,
frequency_penalty=0.8,
presence_penalty=0
)
print(response.choices[0].text)
keywords = response.choices[0].text
return jsonify(keywords)
if __name__ == "__main__":
app.run()