DhruvDecoder commited on
Commit
338be5d
·
verified ·
1 Parent(s): dc3cde9
Files changed (1) hide show
  1. main.py +25 -0
main.py ADDED
@@ -0,0 +1,25 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import streamlit as st
2
+ from vanna.remote import VannaDefault
3
+
4
+ # Set your Vanna API key and model name from Streamlit secrets
5
+ api_key = st.secrets["general"]["vanna_api_key"]
6
+ vanna_model_name = 'chinook' # Assuming 'chinook' is your model name
7
+
8
+ # Initialize Vanna
9
+ vn = VannaDefault(model=vanna_model_name, api_key=api_key)
10
+
11
+ vn.connect_to_sqlite('https://vanna.ai/Chinook.sqlite')
12
+
13
+ my_question = st.session_state.get("my_question", default=None)
14
+ if my_question is None:
15
+ st.image("chinook.png", use_column_width=True)
16
+ my_question = st.text_input("Ask me a question that I can turn into SQL", key="my_question")
17
+ else:
18
+ st.title(my_question)
19
+ sql = vn.generate_sql(my_question)
20
+ st.code(sql, language='sql')
21
+ df = vn.run_sql(sql)
22
+ st.dataframe(df, use_container_width=True)
23
+ fig = vn.get_plotly_figure(plotly_code=vn.generate_plotly_code(question=my_question, sql=sql, df=df), df=df)
24
+ st.plotly_chart(fig, use_container_width=True)
25
+ st.button("Ask another question", on_click=lambda: st.session_state.clear())