Spaces:
Build error
Build error
Update app.py
Browse files12345678910111213141516171819202122232425262728293031323334353637383940#Genericsimport osimport keyfileimport warningswarnings.filterwarnings("ignore")#langchain pachagesfrom langchain_google_genai import ChatGoogleGenerativeAIfrom langchain.schema import HumanMessage , SystemMessage , ATMessage#first message that will pop on the screenst.set_page_config(page_title = "Magical Healer")st.header("welcome, what help do you need?")#general instructionif "sessionMessages" not in st.session_state:st.session_state.sessionMessage = [SystemMessage(content = "You are a medieva magical healer known for your peculiar sarcasm.")]#configuring the keyos.environ["GOOGLE_API_KEY"] = keyfile.GOOGLEKEY#Response functiondef load_answer(question):st.session_state.sessionMessage.append(HumanMessage(content = question))assistant_answer = llm.invoke(st.session_state.sessionMessages)st.session_state.sessionMessages.append(AIMessge(content = assistant_answer))return assistant_answer.content#user msgdef get_text():input_text = st.text_input("You: ", key = input)return input_text#implementation123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960# Genericsimport osimport keyfileimport warningsimport streamlit as stwarnings.filterwarnings("ignore")# Langchain packagesfrom langchain_google_genai import ChatGoogleGenerativeAIfrom langchain.schema import HumanMessage, SystemMessage, AIMessage# First message that will pop on the screenst.set_page_config(page_title = "Magical Healer")st.header("Welcome, What help do you need?")# initializing the sessionMessagesif "sessionMessages" not in st.session_state:st.session_state["sessionMessages"] = []# General Instructionif "sessionMessages" not in st.session_state:st.session_state.sessionMessage = [SystemMessage(content = "You are a medieval magical healer known for your peculiar sarcasm")]# Configuring the keyos.environ["GOOGLE_API_KEY"] = keyfile.GOOGLEKEY# Create a modelllm = ChatGoogleGenerativeAI(model="gemini-1.5-pro",temperature=0.7,convert_system_message_to_human= True)# Response functiondef load_answer(question):# This is code, where we are adding new message to the modelst.session_state.sessionMessages.append(HumanMessage(content = question))# We will get output from the modelassistant_answer = llm.invoke(st.session_state.sessionMessages)# Appending the assistance answer in conversationst.session_state.sessionMessages.append(AIMessage(content = assistant_answer))return assistant_answer.content# User messagedef get_text():input_text = st.text_input("You: ", key = input)return str(input_text)# Implementationuser_input = get_text()submit = st.button("Generate")if submit:resp = load_answer(user_input)st.subheader("Answer: ")st.write(resp, key = 1)
app.py+38-18