Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -9,6 +9,7 @@ from langchain_experimental.sql.base import SQLDatabaseChain
|
|
| 9 |
import streamlit as st
|
| 10 |
import pyodbc
|
| 11 |
import openai
|
|
|
|
| 12 |
from langchain_openai import AzureChatOpenAI
|
| 13 |
|
| 14 |
from tabulate import tabulate
|
|
@@ -22,6 +23,8 @@ openai.api_key = os.environ['OPENAI_API_KEY']
|
|
| 22 |
openai.api_type = 'azure'
|
| 23 |
openai.api_base = os.environ['AZURE_OPENAI_ENDPOINT']
|
| 24 |
openai.api_version = os.environ['OPENAI_API_VERSION']
|
|
|
|
|
|
|
| 25 |
deployment_name = "gpt-4o"
|
| 26 |
|
| 27 |
print(pyodbc.drivers())
|
|
@@ -96,6 +99,29 @@ template = """
|
|
| 96 |
Question: {input}
|
| 97 |
"""
|
| 98 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 99 |
if __name__ == '__main__':
|
| 100 |
connection_string = ("Driver=FreeTDS;Server=crawlersdb.c3pzpntwjvdf.us-east-1.rds.amazonaws.com;Database=SmartCleverST;PORT=1433;UID=CleverData;PWD={};TrustServerCertificate=yes;".format(os.environ['DB_PWD'])
|
| 101 |
)
|
|
@@ -120,7 +146,7 @@ if __name__ == '__main__':
|
|
| 120 |
})
|
| 121 |
|
| 122 |
#question = st.text_input("Ask a question in natural language and press enter")
|
| 123 |
-
|
| 124 |
if "messages" not in st.session_state:
|
| 125 |
st.session_state.messages = []
|
| 126 |
|
|
@@ -135,6 +161,9 @@ if __name__ == '__main__':
|
|
| 135 |
with st.chat_message(message["role"]):
|
| 136 |
st.markdown(message["content"])
|
| 137 |
|
|
|
|
|
|
|
|
|
|
| 138 |
question = st.chat_input("Ask a question in natural language and press enter")
|
| 139 |
|
| 140 |
#if 'questions' not in st.session_state:
|
|
|
|
| 9 |
import streamlit as st
|
| 10 |
import pyodbc
|
| 11 |
import openai
|
| 12 |
+
import hmac
|
| 13 |
from langchain_openai import AzureChatOpenAI
|
| 14 |
|
| 15 |
from tabulate import tabulate
|
|
|
|
| 23 |
openai.api_type = 'azure'
|
| 24 |
openai.api_base = os.environ['AZURE_OPENAI_ENDPOINT']
|
| 25 |
openai.api_version = os.environ['OPENAI_API_VERSION']
|
| 26 |
+
password = os.environ['app_password']
|
| 27 |
+
|
| 28 |
deployment_name = "gpt-4o"
|
| 29 |
|
| 30 |
print(pyodbc.drivers())
|
|
|
|
| 99 |
Question: {input}
|
| 100 |
"""
|
| 101 |
|
| 102 |
+
def check_password():
|
| 103 |
+
"""Returns `True` if the user had the correct password."""
|
| 104 |
+
|
| 105 |
+
def password_entered():
|
| 106 |
+
"""Checks whether a password entered by the user is correct."""
|
| 107 |
+
if hmac.compare_digest(st.session_state["password"], password):
|
| 108 |
+
st.session_state["password_correct"] = True
|
| 109 |
+
del st.session_state["password"] # Don't store the password.
|
| 110 |
+
else:
|
| 111 |
+
st.session_state["password_correct"] = False
|
| 112 |
+
|
| 113 |
+
# Return True if the password is validated.
|
| 114 |
+
if st.session_state.get("password_correct", False):
|
| 115 |
+
return True
|
| 116 |
+
|
| 117 |
+
# Show input for password.
|
| 118 |
+
st.text_input(
|
| 119 |
+
"Password", type="password", on_change=password_entered, key="password"
|
| 120 |
+
)
|
| 121 |
+
if "password_correct" in st.session_state:
|
| 122 |
+
st.error("😕 Password incorrect")
|
| 123 |
+
return False
|
| 124 |
+
|
| 125 |
if __name__ == '__main__':
|
| 126 |
connection_string = ("Driver=FreeTDS;Server=crawlersdb.c3pzpntwjvdf.us-east-1.rds.amazonaws.com;Database=SmartCleverST;PORT=1433;UID=CleverData;PWD={};TrustServerCertificate=yes;".format(os.environ['DB_PWD'])
|
| 127 |
)
|
|
|
|
| 146 |
})
|
| 147 |
|
| 148 |
#question = st.text_input("Ask a question in natural language and press enter")
|
| 149 |
+
|
| 150 |
if "messages" not in st.session_state:
|
| 151 |
st.session_state.messages = []
|
| 152 |
|
|
|
|
| 161 |
with st.chat_message(message["role"]):
|
| 162 |
st.markdown(message["content"])
|
| 163 |
|
| 164 |
+
if not check_password():
|
| 165 |
+
st.stop() # Do not continue if check_password is not True.
|
| 166 |
+
|
| 167 |
question = st.chat_input("Ask a question in natural language and press enter")
|
| 168 |
|
| 169 |
#if 'questions' not in st.session_state:
|