Spaces:
Sleeping
Sleeping
Zwea Htet
commited on
Commit
•
402c1d3
1
Parent(s):
6cadddb
fix api error
Browse files- app.py +8 -6
- models/bloom.py +4 -4
app.py
CHANGED
@@ -1,5 +1,6 @@
|
|
1 |
import os
|
2 |
|
|
|
3 |
import requests
|
4 |
import streamlit as st
|
5 |
from streamlit_chat import message
|
@@ -10,17 +11,18 @@ from utils.util import *
|
|
10 |
st.title("Welcome to RegBotBeta")
|
11 |
st.header("Powered by `LlamaIndex🦙` and `OpenAI API`")
|
12 |
|
13 |
-
if
|
14 |
st.session_state.messages = []
|
15 |
|
16 |
api_key = st.text_input("Enter your OpenAI API key here:", type="password")
|
17 |
if api_key:
|
18 |
resp = validate(api_key)
|
19 |
-
if
|
20 |
st.info("Invalid Token! Try again.")
|
21 |
else:
|
22 |
st.info("Success")
|
23 |
os.environ["OPENAI_API_KEY"] = api_key
|
|
|
24 |
index = create_index(bloom)
|
25 |
|
26 |
st.write("---")
|
@@ -28,15 +30,15 @@ input_text = st.text_area("Ask your question")
|
|
28 |
|
29 |
if input_text is not None:
|
30 |
if st.button("Ask"):
|
31 |
-
st.session_state.messages.append((
|
32 |
with st.spinner("Processing your query..."):
|
33 |
bot_response = get_response(index, input_text)
|
34 |
print("bot: ", bot_response)
|
35 |
-
st.session_state.messages.append((
|
36 |
|
37 |
# Display previous messages
|
38 |
msg_key = 0
|
39 |
for sender, msg in st.session_state.messages[::-1]:
|
40 |
is_user = sender == "User"
|
41 |
-
message(str(msg), is_user, key=str(msg_key)+f
|
42 |
-
msg_key += 1
|
|
|
1 |
import os
|
2 |
|
3 |
+
import openai
|
4 |
import requests
|
5 |
import streamlit as st
|
6 |
from streamlit_chat import message
|
|
|
11 |
st.title("Welcome to RegBotBeta")
|
12 |
st.header("Powered by `LlamaIndex🦙` and `OpenAI API`")
|
13 |
|
14 |
+
if "messages" not in st.session_state:
|
15 |
st.session_state.messages = []
|
16 |
|
17 |
api_key = st.text_input("Enter your OpenAI API key here:", type="password")
|
18 |
if api_key:
|
19 |
resp = validate(api_key)
|
20 |
+
if "error" in resp.json():
|
21 |
st.info("Invalid Token! Try again.")
|
22 |
else:
|
23 |
st.info("Success")
|
24 |
os.environ["OPENAI_API_KEY"] = api_key
|
25 |
+
openai.api_key = api_key
|
26 |
index = create_index(bloom)
|
27 |
|
28 |
st.write("---")
|
|
|
30 |
|
31 |
if input_text is not None:
|
32 |
if st.button("Ask"):
|
33 |
+
st.session_state.messages.append(("User", input_text))
|
34 |
with st.spinner("Processing your query..."):
|
35 |
bot_response = get_response(index, input_text)
|
36 |
print("bot: ", bot_response)
|
37 |
+
st.session_state.messages.append(("Bot", bot_response))
|
38 |
|
39 |
# Display previous messages
|
40 |
msg_key = 0
|
41 |
for sender, msg in st.session_state.messages[::-1]:
|
42 |
is_user = sender == "User"
|
43 |
+
message(str(msg), is_user, key=str(msg_key) + f"_{sender}")
|
44 |
+
msg_key += 1
|
models/bloom.py
CHANGED
@@ -90,8 +90,8 @@ def initialize_index(index_name):
|
|
90 |
index = load_index_from_storage(storage_context)
|
91 |
|
92 |
# huggingface repo load access
|
93 |
-
with fs.open(file_path, "r") as file:
|
94 |
-
|
95 |
return index
|
96 |
else:
|
97 |
documents = prepare_data(r"./assets/regItems.json")
|
@@ -102,6 +102,6 @@ def initialize_index(index_name):
|
|
102 |
index.storage_context.persist(file_path)
|
103 |
|
104 |
# huggingface repo write access
|
105 |
-
with fs.open(file_path, "w") as file:
|
106 |
-
|
107 |
return index
|
|
|
90 |
index = load_index_from_storage(storage_context)
|
91 |
|
92 |
# huggingface repo load access
|
93 |
+
# with fs.open(file_path, "r") as file:
|
94 |
+
# index = pickle.loads(file.readlines())
|
95 |
return index
|
96 |
else:
|
97 |
documents = prepare_data(r"./assets/regItems.json")
|
|
|
102 |
index.storage_context.persist(file_path)
|
103 |
|
104 |
# huggingface repo write access
|
105 |
+
# with fs.open(file_path, "w") as file:
|
106 |
+
# file.write(pickle.dumps(index))
|
107 |
return index
|