Spaces:
Runtime error
Runtime error
Beta-version
Browse files
app.py
CHANGED
@@ -13,11 +13,47 @@ from langchain.schema import HumanMessage, SystemMessage, AIMessage
|
|
13 |
st.set_page_config(page_title = "Magical Healer")
|
14 |
st.header("Welcome, What help do you need?")
|
15 |
|
|
|
|
|
|
|
|
|
|
|
|
|
16 |
# Configuring the key
|
17 |
os.environ["GOOGLE_API_KEY"] = keyfile.GOOGLEKEY
|
18 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
19 |
# User message
|
20 |
def get_text():
|
21 |
input_text = st.text_input("You: ", key = input)
|
22 |
return input_text
|
23 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
13 |
st.set_page_config(page_title = "Magical Healer")
|
14 |
st.header("Welcome, What help do you need?")
|
15 |
|
16 |
+
# General Instruction
|
17 |
+
if "sessionMessages" not in st.session_state:
|
18 |
+
st.session_state.sessionMessage = [
|
19 |
+
SystemMessage(content = "You are a medieval magical healer known for your peculiar sarcasm")
|
20 |
+
]
|
21 |
+
|
22 |
# Configuring the key
|
23 |
os.environ["GOOGLE_API_KEY"] = keyfile.GOOGLEKEY
|
24 |
|
25 |
+
# Create a model
|
26 |
+
llm = ChatGoogleGenerativeAI(
|
27 |
+
model="gemini-1.5-pro",
|
28 |
+
temperature=0.7,
|
29 |
+
convert_system_message_to_human= True
|
30 |
+
)
|
31 |
+
|
32 |
+
|
33 |
+
# Response function
|
34 |
+
def load_answer(question):
|
35 |
+
# This is code, where we are adding new message to the model
|
36 |
+
st.session_state.sessionMessages.append(HumanMessage(content = question))
|
37 |
+
# We will get output from the model
|
38 |
+
assistant_answer = llm.invoke(st.session_state.sessionMessages)
|
39 |
+
# Appending the assistance answer in conversation
|
40 |
+
st.session_state.sessionMessages.append(AIMessage(content = assistant_answer))
|
41 |
+
|
42 |
+
return assistant_answer.content
|
43 |
+
|
44 |
# User message
|
45 |
def get_text():
|
46 |
input_text = st.text_input("You: ", key = input)
|
47 |
return input_text
|
48 |
|
49 |
+
|
50 |
+
# Implementation
|
51 |
+
user_input = get_text()
|
52 |
+
submit = st.button("Generate")
|
53 |
+
|
54 |
+
if submit:
|
55 |
+
resp = load_answer(user_input)
|
56 |
+
st.subheader("Answer: ")
|
57 |
+
st.write(resp, key = 1)
|
58 |
+
|
59 |
+
|