Spaces:
Runtime error
Runtime error
Update app.py
Browse files1234581 unmodified lines8788899091929394959697989966 unmodified lines166167168169170171172173174175176101 unmodified lines27827928028128228328428528628728847 unmodified lines336337338339import streamlit as stfrom PIL import Imageimport timeimport streamlit_analyticsfrom dotenv import load_dotenv81 unmodified linesreturn load_qa_chain(llm=OpenAI(model_name="gpt-3.5-turbo-instruct"), chain_type="stuff")def display_chat_history(chat_history):for chat in chat_history:background_color = "#ffeecf" if chat[2] == "new" else "#ffeecf" if chat[0] == "User" else "#ffeecf"st.markdown(f"<div style='background-color: {background_color}; padding: 10px; border-radius: 10px; margin: 10px;'>{chat[0]}: {chat[1]}</div>", unsafe_allow_html=True)def page1():66 unmodified linesstart_time = time.time()with st.spinner('Bot is thinking...'):# Use the VectorStore loaded at the start from the session statechain = load_chatbot()docs = VectorStore.similarity_search(query=query, k=3)with get_openai_callback() as cb:response = chain.run(input_documents=docs, question=query)# Stop timing101 unmodified linesstart_time = time.time()with st.spinner('Bot is thinking...'):# Use the VectorStore loaded at the start from the session statechain = load_chatbot()docs = VectorStore.similarity_search(query=query, k=3)with get_openai_callback() as cb:response = chain.run(input_documents=docs, question=query)# Stop timing47 unmodified linesif __name__ == "__main__":main()12345681 unmodified lines88899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813966 unmodified lines206207208209210211212213214215216217101 unmodified lines31932032132232332432532632732832933047 unmodified lines378379380381import streamlit as stfrom PIL import Imageimport randomimport timeimport streamlit_analyticsfrom dotenv import load_dotenv81 unmodified linesreturn load_qa_chain(llm=OpenAI(model_name="gpt-3.5-turbo-instruct"), chain_type="stuff")def display_chat_history(chat_history):for chat in chat_history:background_color = "#ffeecf" if chat[2] == "new" else "#ffeecf" if chat[0] == "User" else "#ffeecf"st.markdown(f"<div style='background-color: {background_color}; padding: 10px; border-radius: 10px; margin: 10px;'>{chat[0]}: {chat[1]}</div>", unsafe_allow_html=True)def handle_no_answer(response):no_answer_phrases = ["ich weiß es nicht","ich weiß nicht","ich bin mir nicht sicher","es wird nicht erwähnt","Leider kann ich diese Frage nicht beantworten","kann ich diese Frage nicht beantworten","ich kann diese Frage nicht beantworten","ich kann diese Frage leider nicht beantworten","keine information","das ist unklar","da habe ich keine antwort","das kann ich nicht beantworten","i don't know","i am not sure","it is not mentioned","no information","that is unclear","i have no answer","i cannot answer that","unable to provide an answer","not enough context",]alternative_responses = ["Hmm, das ist eine knifflige Frage. Lass uns das gemeinsam erkunden. Kannst du mehr Details geben?","Interessante Frage! Ich bin mir nicht sicher, aber wir können es herausfinden. Hast du weitere Informationen?","Das ist eine gute Frage. Ich habe momentan keine Antwort darauf, aber vielleicht kannst du sie anders formulieren?","Da bin ich überfragt. Kannst du die Frage anders stellen oder mir mehr Kontext geben?","Ich stehe hier etwas auf dem Schlauch. Gibt es noch andere Aspekte der Frage, die wir betrachten könnten?",# Add more alternative responses as needed]# Check if response matches any phrase in no_answer_phrasesif any(phrase in response.lower() for phrase in no_answer_phrases):return random.choice(alternative_responses) # Randomly select a responsereturn responsedef page1():66 unmodified linesstart_time = time.time()with st.spinner('Bot is thinking...'):chain = load_chatbot()docs = VectorStore.similarity_search(query=query, k=3)with get_openai_callback() as cb:response = chain.run(input_documents=docs, question=query)response = handle_no_answer(response) # Process the response through the new function# Stop timing101 unmodified linesstart_time = time.time()with st.spinner('Bot is thinking...'):chain = load_chatbot()docs = VectorStore.similarity_search(query=query, k=3)with get_openai_callback() as cb:response = chain.run(input_documents=docs, question=query)response = handle_no_answer(response) # Process the response through the new function# Stop timing47 unmodified linesif __name__ == "__main__":main()
app.py+46-4