import streamlit as st from streamlit_chat import message import os from utils import ( parse_docx, parse_pdf, parse_txt, parse_csv, parse_pptx, search_docs, embed_docs, text_to_docs, get_answer, parse_any, get_sources, wrap_text_in_html, ) from openai.error import OpenAIError def clear_submit(): st.session_state["submit"] = False def set_openai_api_key(api_key: str): st.session_state["OPENAI_API_KEY"] = api_key st.markdown('
Read the article to know more details: Medium Article (Spanish)
', unsafe_allow_html=True) st.write("## File GPT was written with the following tools:") st.markdown("#### Code GPT") st.write('All code was written with the help of Code GPT. Visit https://codegpt.co to get the extension.') st.markdown("#### Streamlit") st.write('The design was written with Streamlit.', unsafe_allow_html=True) st.markdown("#### LangChain") st.write('Question answering with source Langchain QA.', unsafe_allow_html=True) st.markdown("#### Embedding") st.write('Embedding is done via the OpenAI API with "text-embedding-ada-002"', unsafe_allow_html=True) st.write("Please note that you must have credits in your OpenAI account to use this tool. Each file uploaded to the platform consumes credits for embedding and each query consumes credits to obtain the response.") st.markdown("""---""") st.write('Author: Daniel Avila', unsafe_allow_html=True) st.write('Repo: Github', unsafe_allow_html=True) st.write("This software was developed with Code GPT, for more information visit: https://codegpt.co", unsafe_allow_html=True) with tab2: st.write('To obtain an API Key you must create an OpenAI account at the following link: https://openai.com/api/') if 'generated' not in st.session_state: st.session_state['generated'] = [] if 'past' not in st.session_state: st.session_state['past'] = [] def get_text(): if user_secret: st.header("Ask me something about the document:") input_text = st.text_area("You:", on_change=clear_submit) return input_text user_input = get_text() button = st.button("Submit") if button or st.session_state.get("submit"): if not user_input: st.error("Please enter a question!") else: st.session_state["submit"] = True sources = search_docs(index, user_input) try: answer = get_answer(sources, user_input) st.session_state.past.append(user_input) st.session_state.generated.append(answer["output_text"].split("SOURCES: ")[0]) except OpenAIError as e: st.error(e._message) if st.session_state['generated']: for i in range(len(st.session_state['generated'])-1, -1, -1): message(st.session_state["generated"][i], key=str(i)) message(st.session_state['past'][i], is_user=True, key=str(i) + '_user')