-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathmain.py
More file actions
111 lines (82 loc) · 3.07 KB
/
main.py
File metadata and controls
111 lines (82 loc) · 3.07 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
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
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
# Import necessary libraries
# Flask is a web framework for Python that allows backend-frontend communication
from flask import Flask
# json is a library for parsing and creating JSON data
import json
# googleapiclient is a library for working with Google APIs(Getting data from Google Sheets in this case)
from googleapiclient.discovery import build
# openai is a library for working with OpenAI
from openai import OpenAI
# openai is a library for working with OpenAI
import openai
from langchain_community.chat_models import ChatOpenAI
from langchain.memory import ConversationBufferMemory
from langchain_openai import ChatOpenAI
from database import init_firebase
from study import init_pydantic
from routes.page_init import page_init
from routes.analyze_routes import analyze_routes
from routes.data_routes import data_routes
from routes.ai_routes import ai_routes
#get api keys from static/api_keys.json file
keys = json.load(open('api_keys.json'))
init_firebase()
# Initialize other variables
def init():
vars = {}
keys = json.load(open('api_keys.json'))
vars['openAIAPI'] = keys["OpenAiAPIKey"]
openai.api_key = vars['openAIAPI']
vars['spreadsheet_id'] = '1k7VOAgZY9FVdcyVFaQmY_iW_DXvYQluosM2LYL2Wmc8'
vars['gSheet_api_key'] = keys["GoogleAPIKey"]
# URL for the SheetDB API, for POST requests
vars['sheetdb_url'] = 'https://sheetdb.io/api/v1/y0fswwtbyapbd'
vars['DISCOVERY_SERVICE_URL'] = 'https://sheets.googleapis.com/$discovery/rest?version=v4'
try:
vars['service'] = build('sheets',
'v4',
developerKey=vars['gSheet_api_key'],
discoveryServiceUrl=vars['DISCOVERY_SERVICE_URL'])
except Exception as e:
print(f"Warning: Failed to initialize Google Sheets API: {e}")
# Fallback to None - application should handle this gracefully
vars['service'] = None
vars['max_column'] = "O"
vars['AppSecretKey'] = keys["AppSecretKey"]
# firebase or gsheet
vars['database'] = 'firebase'
vars['allow_demo_change'] = True
vars['client'] = OpenAI(api_key=vars['openAIAPI'])
vars['google_credentials_path'] = 'cloudRunKey.json'
# Initialize LangChain components
vars['llm'] = ChatOpenAI(
api_key=vars['openAIAPI'],
temperature=0.7,
model_name="gpt-4"
)
vars['vision_llm'] = ChatOpenAI(
api_key=vars['openAIAPI'],
temperature=0.7,
model_name="gpt-4"
)
# Initialize memory for different conversation contexts
vars['eval_memory'] = ConversationBufferMemory(
memory_key="chat_history",
return_messages=True
)
# App secret key for session management
app.config['SECRET_KEY'] = vars["AppSecretKey"]
generate_grade_insights = True
return vars
app = Flask(__name__)
app.config['SESSION_TYPE'] = 'filesystem'
app.config['SESSION_PERMANENT'] = True
app.register_blueprint(page_init)
app.register_blueprint(analyze_routes)
app.register_blueprint(data_routes)
app.register_blueprint(ai_routes)
def utility_function():
print("Utility function called")
vars = init()
if __name__ == '__main__':
app.run(host='localhost', port=8080)