Skip to content

Commit 7cac30a

Browse files
author
vikram-floweraura
committed
update connection
1 parent 59b610e commit 7cac30a

File tree

1 file changed

+29
-9
lines changed

1 file changed

+29
-9
lines changed

pages/Ask Your Database.py

Lines changed: 29 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -18,19 +18,40 @@
1818
OPENAI_API_KEY = os.getenv("openai_key")
1919
openai.api_key=OPENAI_API_KEY
2020

21+
conn = ''
2122

22-
st.write(OPENAI_API_KEY)
23-
st.write("Connect your Database")
23+
with st.form("my_form"):
24+
st.write("Inside the form")
25+
db_type = st.text_input("select db type")
26+
dbusername = st.text_input("select db username")
27+
dbpassword = st.text_input("select db password")
28+
dbname = st.text_input("select db name")
29+
dbhost = st.text_input("select db host")
2430

25-
26-
db = SQLDatabase.from_uri(
27-
"mysql+pymysql://bakewish:EmtTSRwDeKOk@admin.bakewish.in/bakewish_030123",
28-
)
31+
# Every form must have a submit button.
32+
submitted = st.form_submit_button("Submit")
33+
if submitted:
34+
if db_type=='mysql':
35+
conn = "mysql+pymysql://"+dbusername+":"+dbpassword+"@"+dbhost+"/"+dbname
36+
37+
st.write("Outside the form")
38+
39+
40+
41+
42+
43+
st.write(conn)
2944
# db = SQLDatabase.from_uri(
30-
# "mysql+pymysql://vikram:password@localhost/bank",
45+
# "mysql+pymysql://bakewish:EmtTSRwDeKOk@admin.bakewish.in/bakewish_030123",
3146
# )
47+
if conn!='':
48+
db = SQLDatabase.from_uri(
49+
conn,
50+
)
51+
3252
st.write("db connection established")
33-
# Create a cursor object to execute SQL commands
53+
#st.write(db)
54+
3455
# setup llm
3556
llm = OpenAI(temperature=0, openai_api_key=OPENAI_API_KEY)
3657

@@ -52,5 +73,4 @@
5273

5374
user_question = st.text_input("write a query:")
5475

55-
#question = QUERY.format(question=user_question)
5676
st.write(db_chain.run(user_question))

0 commit comments

Comments
 (0)