-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathConnectionToTheDatabase.py
More file actions
54 lines (39 loc) · 2.22 KB
/
ConnectionToTheDatabase.py
File metadata and controls
54 lines (39 loc) · 2.22 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
import streamlit as st
import time
from SessionVariables import InitializationOfSessionVariables,CreationOfCacheSessionVariable
from VannaOpenAIAPI import VannaObjectCreation
def ConnectionToDataBase():
if not st.session_state.connected:
# Title of the Streamlit app
st.title("Connect to the Required Database")
option = st.selectbox(
"Connect to the Database",
["postgres"],index=0)
if option == 'postgres':
st.subheader("Postgres Connection Configuration")
postgres_user = st.text_input("current_user")
postgres_password = st.text_input("current password")
postgres_db = st.text_input("current_database")
postgres_port = st.text_input("server_port")
postgres_ip = st.text_input("host")
# Ensure all fields are mandatory
if postgres_user and postgres_db and postgres_port and postgres_ip and postgres_password:
connect_button = st.button("Connect To The Database")
if connect_button:
st.session_state.connected = True
CreationOfCacheSessionVariable()
# Creation of Vanna Object with Llama3 Model
vn = VannaObjectCreation(config={'api_key': 'sk-proj-GNHT4noCay7Yp0Gsh3h8T3BlbkFJb40I8ghuyfHKlqdMeGoiop', 'model': 'gpt-4-turbo'})
returnValue_Connection = vn.ConnectionToPostgres(str(postgres_ip),str(postgres_db),str(postgres_user),str(postgres_password),int(postgres_port))
if returnValue_Connection == "Success":
st.success("Connected to the Database")
time.sleep(0.1)
st.session_state.canNavigateToTextToSqlPage = True
st.session_state.vn = vn
st.switch_page("pages/TextToSQL.py")
else:
st.error(returnValue_Connection)
else:
st.warning("Please fill out all fields")
InitializationOfSessionVariables()
ConnectionToDataBase()