-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.py
35 lines (27 loc) · 841 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
import openai
from flask import Flask, render_template, request
app = Flask(__name__)
openai.api_key = "YOUR_API_KEY"
def generate_response(prompt):
try:
response = openai.Completion.create(
engine="text-davinci-002",
prompt=prompt,
max_tokens=100,
n=1,
stop=None,
temperature=0.5,
)
return response.choices[0].text
except Exception as e:
return f"Error: {e}"
@app.route('/')
def home():
return render_template('home.html')
@app.route('/result', methods=['POST'])
def result():
prompt = request.form['prompt']
response = generate_response(prompt)
return render_template('result.html', prompt=prompt, response=response)
if __name__ == '__main__':
app.run(debug=True)