Update app.py
Browse files
app.py
CHANGED
|
@@ -10,7 +10,7 @@ from langchain import OpenAI
|
|
| 10 |
from langchain import PromptTemplate
|
| 11 |
from loguru import logger
|
| 12 |
|
| 13 |
-
ns = SimpleNamespace(counter=0)
|
| 14 |
|
| 15 |
st.set_page_config(page_title="Talk2Book", page_icon="π")
|
| 16 |
|
|
@@ -138,7 +138,7 @@ with st.sidebar:
|
|
| 138 |
type = "password",
|
| 139 |
help = "This isn't saved π"
|
| 140 |
)
|
| 141 |
-
os.environ["OPENAI_API_KEY"] = api_key
|
| 142 |
|
| 143 |
st.markdown("---")
|
| 144 |
|
|
@@ -162,18 +162,27 @@ col1.write(f"**You:** {user_input}")
|
|
| 162 |
# ask button to the right of the displayed question
|
| 163 |
ask = col2.button("Ask", type="primary")
|
| 164 |
|
| 165 |
-
|
| 166 |
if ask:
|
| 167 |
-
|
| 168 |
if api_key is "":
|
| 169 |
-
st.write(f"**{BOOK_NAME}:** Whoops looks like you forgot your API key buddy")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 170 |
st.stop()
|
| 171 |
else:
|
| 172 |
-
|
|
|
|
|
|
|
| 173 |
msg = "Just one sec"
|
| 174 |
else:
|
| 175 |
msg = "Um... excuse me but... this can take about a minute for your first question because some stuff have to be downloaded π₯Ίππ»ππ»"
|
| 176 |
-
|
|
|
|
| 177 |
with st.spinner(msg):
|
| 178 |
try:
|
| 179 |
answer, pages, extract = get_answer(question=user_input)
|
|
|
|
| 10 |
from langchain import PromptTemplate
|
| 11 |
from loguru import logger
|
| 12 |
|
| 13 |
+
# ns = SimpleNamespace(counter=0)
|
| 14 |
|
| 15 |
st.set_page_config(page_title="Talk2Book", page_icon="π")
|
| 16 |
|
|
|
|
| 138 |
type = "password",
|
| 139 |
help = "This isn't saved π"
|
| 140 |
)
|
| 141 |
+
# os.environ["OPENAI_API_KEY"] = api_key
|
| 142 |
|
| 143 |
st.markdown("---")
|
| 144 |
|
|
|
|
| 162 |
# ask button to the right of the displayed question
|
| 163 |
ask = col2.button("Ask", type="primary")
|
| 164 |
|
|
|
|
| 165 |
if ask:
|
|
|
|
| 166 |
if api_key is "":
|
| 167 |
+
st.write(f"**{BOOK_NAME}:** Whoops looks like you forgot your API key buddy. We throw a dice to decide wether you can ask one question for free.")
|
| 168 |
+
# stop with a prob = 0.9
|
| 169 |
+
if random() > 1/6:
|
| 170 |
+
st.stop()
|
| 171 |
+
else: # use space secret[OPENAI_API_KEY/envion,
|
| 172 |
+
api_key = os.environ["OPENAI_API_KEY"]
|
| 173 |
+
|
| 174 |
+
if not api_key:
|
| 175 |
+
st.write(f"**{BOOK_NAME}:** no luck, try again?")
|
| 176 |
st.stop()
|
| 177 |
else:
|
| 178 |
+
os.environ["OPENAI_API_KEY"] = api_key
|
| 179 |
+
# if ns.counter: # this does not work
|
| 180 |
+
if 'key' in st.session_state:
|
| 181 |
msg = "Just one sec"
|
| 182 |
else:
|
| 183 |
msg = "Um... excuse me but... this can take about a minute for your first question because some stuff have to be downloaded π₯Ίππ»ππ»"
|
| 184 |
+
st.session_state.key = 'value'
|
| 185 |
+
# ns.counter = 1
|
| 186 |
with st.spinner(msg):
|
| 187 |
try:
|
| 188 |
answer, pages, extract = get_answer(question=user_input)
|