Spaces:
Sleeping
Sleeping
Beta Version 6
Browse files
app.py
CHANGED
@@ -1,42 +1,45 @@
|
|
1 |
-
#Generic
|
2 |
import os
|
3 |
import keyfile
|
4 |
import streamlit as st
|
5 |
import warnings
|
|
|
|
|
|
|
6 |
warnings.filterwarnings("ignore")
|
7 |
|
8 |
-
#Langchain Packages
|
9 |
from langchain_google_genai import ChatGoogleGenerativeAI
|
10 |
from langchain.schema import HumanMessage, SystemMessage, AIMessage
|
|
|
11 |
|
12 |
-
#First message that will pop on the screen
|
13 |
-
st.set_page_config(page_title
|
14 |
st.header("Welcome, How can I help you?")
|
15 |
|
16 |
-
|
17 |
class AIMessage(BaseModel):
|
18 |
content: str
|
19 |
|
20 |
if "sessionMessages" not in st.session_state:
|
21 |
-
st.session_state["sessionMessages"]=[]
|
22 |
-
#General Instruction
|
23 |
if "sessionMessages" not in st.session_state:
|
24 |
-
st.session_state.sessionMessage=[
|
25 |
SystemMessage(content="You are a medievel magical healer known for your peculiar sarcasm")
|
26 |
]
|
27 |
|
28 |
-
#Configure the key
|
29 |
os.environ["GOOGLE_API_KEY"] = keyfile.GOOGLEKEY
|
30 |
|
31 |
-
|
32 |
# Create the model
|
33 |
llm = ChatGoogleGenerativeAI(
|
34 |
model="gemini-1.5-pro",
|
35 |
temperature=0.7,
|
36 |
-
convert_system_message_to_human=
|
37 |
)
|
38 |
|
39 |
-
#User message
|
40 |
def load_answer(question):
|
41 |
st.session_state.sessionMessages.append(HumanMessage(content=question))
|
42 |
assistant_response = llm.invoke(st.session_state.sessionMessages)
|
@@ -51,27 +54,16 @@ def load_answer(question):
|
|
51 |
|
52 |
return processed_content
|
53 |
|
54 |
-
#
|
55 |
-
#def load_answer(question):
|
56 |
-
|
57 |
-
# st.session_state.sessionMessages.append(HumanMessage(content=question))
|
58 |
-
# assistant_answer=llm.invoke(st.session_state.sessionMessages)
|
59 |
-
# st.session_state.sessionMessages.append(AIMessage(content = assistant_answer))
|
60 |
-
# return assistant_answer.content
|
61 |
-
|
62 |
def get_text():
|
63 |
-
input_text=st.text_input("You: ", key=input)
|
64 |
return input_text
|
65 |
|
66 |
-
#Implementing
|
67 |
-
user_input=get_text()
|
68 |
-
submit= st.button("Generate")
|
69 |
|
70 |
if submit:
|
71 |
-
resp=load_answer(user_input)
|
72 |
-
st.subheader("Answer:
|
73 |
-
st.write(resp,key=1)
|
74 |
-
|
75 |
-
|
76 |
-
|
77 |
-
|
|
|
1 |
+
# Generic
|
2 |
import os
|
3 |
import keyfile
|
4 |
import streamlit as st
|
5 |
import warnings
|
6 |
+
# Add this import at the beginning of your code
|
7 |
+
from pydantic import BaseModel
|
8 |
+
|
9 |
warnings.filterwarnings("ignore")
|
10 |
|
11 |
+
# Langchain Packages
|
12 |
from langchain_google_genai import ChatGoogleGenerativeAI
|
13 |
from langchain.schema import HumanMessage, SystemMessage, AIMessage
|
14 |
+
from pydantic import BaseModel # Import BaseModel
|
15 |
|
16 |
+
# First message that will pop on the screen
|
17 |
+
st.set_page_config(page_title="Magical Healer")
|
18 |
st.header("Welcome, How can I help you?")
|
19 |
|
20 |
+
# Define the AIMessage class
|
21 |
class AIMessage(BaseModel):
|
22 |
content: str
|
23 |
|
24 |
if "sessionMessages" not in st.session_state:
|
25 |
+
st.session_state["sessionMessages"] = []
|
26 |
+
# General Instruction
|
27 |
if "sessionMessages" not in st.session_state:
|
28 |
+
st.session_state.sessionMessage = [
|
29 |
SystemMessage(content="You are a medievel magical healer known for your peculiar sarcasm")
|
30 |
]
|
31 |
|
32 |
+
# Configure the key
|
33 |
os.environ["GOOGLE_API_KEY"] = keyfile.GOOGLEKEY
|
34 |
|
|
|
35 |
# Create the model
|
36 |
llm = ChatGoogleGenerativeAI(
|
37 |
model="gemini-1.5-pro",
|
38 |
temperature=0.7,
|
39 |
+
convert_system_message_to_human=True
|
40 |
)
|
41 |
|
42 |
+
# User message
|
43 |
def load_answer(question):
|
44 |
st.session_state.sessionMessages.append(HumanMessage(content=question))
|
45 |
assistant_response = llm.invoke(st.session_state.sessionMessages)
|
|
|
54 |
|
55 |
return processed_content
|
56 |
|
57 |
+
# Get user input
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
58 |
def get_text():
|
59 |
+
input_text = st.text_input("You: ", key="input")
|
60 |
return input_text
|
61 |
|
62 |
+
# Implementing
|
63 |
+
user_input = get_text()
|
64 |
+
submit = st.button("Generate")
|
65 |
|
66 |
if submit:
|
67 |
+
resp = load_answer(user_input)
|
68 |
+
st.subheader("Answer:")
|
69 |
+
st.write(resp, key=1)
|
|
|
|
|
|
|
|