Spaces:
Runtime error
Runtime error
Zwea Htet commited on
Commit ·
402c1d3
1
Parent(s): 6cadddb
fix api error
Browse filesFiles changed (2)
- app.py+8-6
- models/bloom.py+4-4
123454 unmodified lines10111213141516171819202122232425261 unmodified line282930313233343536373839404142import osimport requestsimport streamlit as stfrom streamlit_chat import message4 unmodified linesst.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_keyindex = create_index(bloom)st.write("---")1 unmodified lineif 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 messagesmsg_key = 0for 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 += 11234564 unmodified lines1112131415161718192021222324252627281 unmodified line303132333435363738394041424344import osimport openaiimport requestsimport streamlit as stfrom streamlit_chat import message4 unmodified linesst.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_keyopenai.api_key = api_keyindex = create_index(bloom)st.write("---")1 unmodified lineif 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 messagesmsg_key = 0for 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
89 unmodified lines90919293949596974 unmodified lines10210310410510610789 unmodified linesindex = load_index_from_storage(storage_context)# huggingface repo load accesswith fs.open(file_path, "r") as file:index = pickle.loads(file.readlines())return indexelse:documents = prepare_data(r"./assets/regItems.json")4 unmodified linesindex.storage_context.persist(file_path)# huggingface repo write accesswith fs.open(file_path, "w") as file:file.write(pickle.dumps(index))return index89 unmodified lines90919293949596974 unmodified lines10210310410510610789 unmodified linesindex = load_index_from_storage(storage_context)# huggingface repo load access# with fs.open(file_path, "r") as file:# index = pickle.loads(file.readlines())return indexelse:documents = prepare_data(r"./assets/regItems.json")4 unmodified linesindex.storage_context.persist(file_path)# huggingface repo write access# with fs.open(file_path, "w") as file:# file.write(pickle.dumps(index))return index
app.py+8-6
models/bloom.py+4-4