Spaces:
Sleeping
Sleeping
debug
Browse files
app.py
CHANGED
@@ -11,9 +11,30 @@ import sqlite3
|
|
11 |
import os
|
12 |
from langchain_openai import ChatOpenAI
|
13 |
os.environ["OPENAI_API_KEY"] = st.secrets["OPENAI_API_KEY"]
|
14 |
-
st.set_page_config(page_title="
|
15 |
-
st.title("🦜
|
16 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
17 |
|
18 |
# User inputs
|
19 |
radio_opt = ["US Protected Areas v3"]
|
@@ -25,6 +46,9 @@ def configure_db(db_uri):
|
|
25 |
return SQLDatabase.from_uri(database_uri=db_uri, view_support=True)
|
26 |
db = configure_db(db_uri)
|
27 |
|
|
|
|
|
|
|
28 |
llm = ChatOpenAI(model="gpt-3.5-turbo", temperature=0)
|
29 |
agent = create_sql_agent(llm, db=db, agent_type="openai-tools", verbose=True)
|
30 |
|
@@ -55,7 +79,7 @@ with main:
|
|
55 |
st.markdown("\n") #add some space for iphone users
|
56 |
|
57 |
|
58 |
-
#if "messages" not in st.session_state or st.sidebar.button("Clear message history"):
|
59 |
# st.session_state["messages"] = [{"role": "assistant", "content": "How can I help you?"}]
|
60 |
|
61 |
|
|
|
11 |
import os
|
12 |
from langchain_openai import ChatOpenAI
|
13 |
os.environ["OPENAI_API_KEY"] = st.secrets["OPENAI_API_KEY"]
|
14 |
+
st.set_page_config(page_title="Protected Areas Database Chat", page_icon="🦜")
|
15 |
+
st.title("🦜 Protected Areas Database Chat")
|
16 |
+
|
17 |
+
|
18 |
+
# +
|
19 |
+
import duckdb
|
20 |
+
con = duckdb.connect("pad_views.duckdb")
|
21 |
+
|
22 |
+
con.sql("create or replace view agency_name as select * from 'https://huggingface.co/datasets/boettiger-lab/pad-us-3/resolve/main/parquet/pad-agency-name.parquet'")
|
23 |
+
con.sql("create or replace view agency_type as select * from 'https://huggingface.co/datasets/boettiger-lab/pad-us-3/resolve/main/parquet/pad-agency-type.parquet'")
|
24 |
+
con.sql("create or replace view category as select * from 'https://huggingface.co/datasets/boettiger-lab/pad-us-3/resolve/main/parquet/pad-category.parquet'")
|
25 |
+
con.sql("create or replace view designation_type as select * from 'https://huggingface.co/datasets/boettiger-lab/pad-us-3/resolve/main/parquet/pad-desgination-type.parquet'")
|
26 |
+
con.sql("create or replace view easement as select * from 'https://huggingface.co/datasets/boettiger-lab/pad-us-3/resolve/main/parquet/pad-easement.parquet'")
|
27 |
+
con.sql("create or replace view fee as select * from 'https://huggingface.co/datasets/boettiger-lab/pad-us-3/resolve/main/parquet/pad-fee.parquet'")
|
28 |
+
con.sql("create or replace view marine as select * from 'https://huggingface.co/datasets/boettiger-lab/pad-us-3/resolve/main/parquet/pad-marine.parquet'")
|
29 |
+
con.sql("create or replace view iucn as select * from 'https://huggingface.co/datasets/boettiger-lab/pad-us-3/resolve/main/parquet/pad-iucn.parquet'")
|
30 |
+
con.sql("create or replace view public_access as select * from 'https://huggingface.co/datasets/boettiger-lab/pad-us-3/resolve/main/parquet/pad-public-access.parquet'")
|
31 |
+
con.sql("create or replace view state_name as select * from 'https://huggingface.co/datasets/boettiger-lab/pad-us-3/resolve/main/parquet/pad-state-name.parquet'")
|
32 |
+
con.sql("create or replace view combined as select * from 'https://huggingface.co/datasets/boettiger-lab/pad-us-3/resolve/main/parquet/pad-combined.parquet'")
|
33 |
+
con.close()
|
34 |
+
# -
|
35 |
+
|
36 |
+
#db_uri = "duckdb:///:memory:"
|
37 |
+
db_uri = "duckdb:///pad_views.duckdb"
|
38 |
|
39 |
# User inputs
|
40 |
radio_opt = ["US Protected Areas v3"]
|
|
|
46 |
return SQLDatabase.from_uri(database_uri=db_uri, view_support=True)
|
47 |
db = configure_db(db_uri)
|
48 |
|
49 |
+
|
50 |
+
db.get_usable_table_names()
|
51 |
+
|
52 |
llm = ChatOpenAI(model="gpt-3.5-turbo", temperature=0)
|
53 |
agent = create_sql_agent(llm, db=db, agent_type="openai-tools", verbose=True)
|
54 |
|
|
|
79 |
st.markdown("\n") #add some space for iphone users
|
80 |
|
81 |
|
82 |
+
# if "messages" not in st.session_state or st.sidebar.button("Clear message history"):
|
83 |
# st.session_state["messages"] = [{"role": "assistant", "content": "How can I help you?"}]
|
84 |
|
85 |
|