Register
Login
Resources
Docs Blog Datasets Glossary Case Studies Tutorials & Webinars
Product
Data Engine LLMs Platform Enterprise
Pricing Explore
Connect to our Discord channel

app.py 1.9 KB

You have to be logged in to leave a comment. Sign In
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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
  1. from flask import Flask, render_template, jsonify, request
  2. import yfinance as yf
  3. import openai
  4. from getpass import getpass
  5. from langchain.llms import OpenAI
  6. from langchain.prompts import PromptTemplate
  7. from langchain.chains import LLMChain
  8. import os
  9. from dotenv import load_dotenv
  10. load_dotenv()
  11. openai_api_key = os.environ.get("OPENAI_API_KEY")
  12. def page_not_found(e):
  13. return render_template('404.html'), 404
  14. app = Flask(__name__)
  15. app.register_error_handler(404, page_not_found)
  16. @app.route('/')
  17. def index():
  18. return render_template('home.html', **locals())
  19. @app.route('/chatbot', methods=['GET', 'POST'])
  20. def chatbot():
  21. if request.method == 'POST':
  22. question = request.form['prompt']
  23. template = """Stock-related Query: {question}
  24. Response: """
  25. prompt = PromptTemplate(template=template, input_variables=["question"])
  26. llm = OpenAI()
  27. llm_chain = LLMChain(prompt=prompt, llm=llm)
  28. answer = llm_chain.run(question)
  29. return jsonify(answer=answer)
  30. return render_template('chatbot.html')
  31. @app.route('/login')
  32. def login():
  33. return render_template('login.html')
  34. @app.route('/signup')
  35. def signup():
  36. return render_template('signup.html')
  37. @app.route('/dashboard')
  38. def dashboard():
  39. return render_template('dashboard.html')
  40. @app.route('/investment')
  41. def investment():
  42. return render_template('investment.html')
  43. @app.route('/trading')
  44. def trading():
  45. return render_template('trading.html')
  46. @app.route('/wisewealth')
  47. def wisewealth():
  48. return render_template('wisewealth.html')
  49. @app.route('/get_stock_data', methods=['POST'])
  50. def get_stock_data():
  51. ticker = request.get_json()['ticker']
  52. data = yf.Ticker(ticker).history(period='1y')
  53. return jsonify({'currentPrice':data.iloc[-1].Close,
  54. 'openPrice':data.iloc[-1].Open})
  55. if __name__ == '__main__':
  56. app.run(host='0.0.0.0', port='8888', debug=True)
Tip!

Press p or to see the previous file or, n or to see the next file

Comments

Loading...