-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathapp.py
More file actions
37 lines (26 loc) · 1.11 KB
/
app.py
File metadata and controls
37 lines (26 loc) · 1.11 KB
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
from flask import Flask, request, jsonify, render_template
import openai
import webbrowser
app = Flask(__name__)
@app.route('/')
def index():
return render_template('index.html')
@app.route('/run_python', methods=['POST'])
def run_python():
api_key = request.form.get('api_key') # Get the API key from the form
user_input = "You are a diversity and inclusion consultant.\n"
user_input += "Please evaluate our job listing for the given job position and provide feedback on how to make it more inclusive.\n"
user_input += request.form.get('user_input')
print(user_input)
# Set the API key for OpenAI
openai.api_key = api_key
# Create a conversation with user input
messages = [
{"role": "system", "content": "You are an intelligent assistant."}]
messages.append({"role": "user", "content": user_input})
chat = openai.ChatCompletion.create(model="gpt-4", messages=messages)
assistant_reply = chat.choices[0].message.content
return jsonify({"response": assistant_reply})
if __name__ == '__main__':
webbrowser.open("http://127.0.0.1:5000")
app.run(debug=True)