Spaces:
Sleeping
Sleeping
File size: 1,215 Bytes
0809507 0e8a2bc 3b7cf58 0e8a2bc 0809507 3b7cf58 0809507 3b7cf58 1230ae3 0809507 1230ae3 3b7cf58 1230ae3 3b7cf58 1230ae3 3b7cf58 0809507 3b7cf58 0809507 3b7cf58 38bc9e2 3b7cf58 0809507 3b7cf58 38bc9e2 3b7cf58 38bc9e2 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 |
import os
import requests
import streamlit as st
from streamlit_chat import message
from models import bloom
from utils.util import *
st.title("Welcome to RegBotBeta")
st.header("Powered by `LlamaIndex🦙` and `OpenAI API`")
if 'messages' not in st.session_state:
st.session_state.messages = []
api_key = st.text_input("Enter your OpenAI API key here:", type="password")
if api_key:
resp = validate(api_key)
if ("error" in resp.json()):
st.info("Invalid Token! Try again.")
else:
st.info("Success")
os.environ["OPENAI_API_KEY"] = api_key
index = create_index(bloom)
st.write("---")
input_text = st.text_area("Ask your question")
if input_text is not None:
if st.button("Ask"):
st.session_state.messages.append(('User', input_text))
with st.spinner("Processing your query..."):
bot_response = get_response(index, input_text)
print("bot: ", bot_response)
st.session_state.messages.append(('Bot', bot_response))
# Display previous messages
msg_key = 0
for sender, msg in st.session_state.messages[::-1]:
is_user = sender == "User"
message(str(msg), is_user, key=str(msg_key)+f'_{sender}')
msg_key += 1 |