forked from render-examples/flask-hello-world
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapp.py
More file actions
28 lines (22 loc) · 818 Bytes
/
app.py
File metadata and controls
28 lines (22 loc) · 818 Bytes
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
from langchain.agents import create_csv_agent
from langchain.llms import OpenAI
from dotenv import load_dotenv
import os
from flask import Flask, render_template, request, jsonify
app = Flask(__name__)
@app.route('/')
def home():
return "Hello World"
@app.route('/query', methods=['POST'])
def query():
load_dotenv()
if os.getenv("OPENAI_API_KEY") is None or os.getenv("OPENAI_API_KEY") == "":
return jsonify({'error': 'OpenAI Key is not set'}), 500
agent = create_csv_agent(OpenAI(temperature=0), "./AAPL.csv")
user_question = request.form.get('query')
if user_question is None or user_question == "":
return jsonify({'error': 'No query provided'}), 400
ans = agent.run(user_question)
return jsonify({'answer': ans}), 200
if __name__ == '__main__':
app.run()