Spaces:
Build error
Build error
Update app.py
Browse files112345677899101111121313141516141516171819202120222322232425262726282930313233343536373829394041313242434434454647484938505152535455564057585960#Generics# Genericsimport osimport keyfileimport warningsimport streamlit as stwarnings.filterwarnings("ignore")
#langchain pachages# Langchain packagesfrom langchain_google_genai import ChatGoogleGenerativeAIfrom langchain.schema import HumanMessage , SystemMessage , ATMessagefrom langchain.schema import HumanMessage, SystemMessage, AIMessage
#first message that will pop on the screen# First message that will pop on the screenst.set_page_config(page_title = "Magical Healer")st.header("welcome, what help do you need?")
#general instructionst.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 medieva magical healer known for your peculiar sarcasm.") SystemMessage(content = "You are a medieval magical healer known for your peculiar sarcasm") ] #configuring the key
# Configuring the keyos.environ["GOOGLE_API_KEY"] = keyfile.GOOGLEKEY
#Response function# 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 model st.session_state.sessionMessage.append(HumanMessage(content = question)) st.session_state.sessionMessages.append(HumanMessage(content = question)) # We will get output from the model assistant_answer = llm.invoke(st.session_state.sessionMessages) st.session_state.sessionMessages.append(AIMessge(content = assistant_answer)) return assistant_answer.content # Appending the assistance answer in conversation st.session_state.sessionMessages.append(AIMessage(content = assistant_answer))
#user msg return assistant_answer.content
# User messagedef get_text(): input_text = st.text_input("You: ", key = input) return input_text return str(input_text)
# Implementationuser_input = get_text()submit = st.button("Generate")
#implementationif submit: resp = load_answer(user_input) st.subheader("Answer: ") st.write(resp, key = 1)app.py+38-18