File size: 893 Bytes
97a631f
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
from flask import Flask, render_template, request
from langchain.llms import OpenAI

app = Flask(__name__)

# Function to load OpenAI model and get responses


def get_openai_response(question):
    llm = OpenAI(
        openai_api_key=app.config['OPENAI_API_KEY'],
        model_name="text-davinci-003",
        temperature=0.5
    )
    response = llm(question)
    return response


@app.route('/', methods=['GET', 'POST'])
def index():
    if request.method == 'POST':
        input_question = request.form['input']
        response = get_openai_response(input_question)
        return render_template('index.html', input_question=input_question, response=response)

    return render_template('index.html')


if __name__ == '__main__':
    # Replace with your OpenAI API key
    app.config['OPENAI_API_KEY'] = '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'
    app.run(debug=True)