jason137 commited on
Commit
2c74cef
·
1 Parent(s): b495c25

Update script.py

Browse files
Files changed (1) hide show
  1. script.py +9 -18
script.py CHANGED
@@ -1,24 +1,15 @@
1
  import os
2
  from langchain import OpenAI, SQLDatabase, SQLDatabaseChain
3
 
4
- api_key = os.getenv('OPENAI_API_KEY')
 
5
 
6
- db = SQLDatabase.from_uri("sqlite:///Chinook.db"
7
- , include_tables=['Album', 'Track']
8
- )
9
 
10
- llm = OpenAI(temperature=0.0, openai_api_key=api_key)
 
11
 
12
- db_chain = SQLDatabaseChain.from_llm(llm
13
- , db
14
- , verbose=True
15
- , use_query_checker=True
16
- )
17
-
18
- queries = ("How many albums are there?"
19
- , "How many tracks are there?"
20
- , "Which album has the most tracks?"
21
- )
22
-
23
- for query in queries:
24
- print(db_chain.run(query))
 
1
  import os
2
  from langchain import OpenAI, SQLDatabase, SQLDatabaseChain
3
 
4
+ import sqlite3
5
+ import streamlit as st
6
 
7
+ st.title("English to SQL via LangChain")
 
 
8
 
9
+ tables = ['Album', 'Artist', 'Track']
10
+ db = SQLDatabase.from_uri("sqlite:///Chinook.db", include_tables=tables)
11
 
12
+ con = sqlite3.connect("Chinook.db")
13
+ for table in tables:
14
+ rows = cur.execute("select * from %s limit 5" %s table).fetchall()
15
+ st.table(rows)