archana2324 commited on
Commit
369f31d
·
verified ·
1 Parent(s): 951ced6

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +38 -18
app.py CHANGED
@@ -1,40 +1,60 @@
1
- #Generics
2
  import os
3
  import keyfile
4
  import warnings
 
5
  warnings.filterwarnings("ignore")
6
 
7
- #langchain pachages
8
  from langchain_google_genai import ChatGoogleGenerativeAI
9
- from langchain.schema import HumanMessage , SystemMessage , ATMessage
10
 
11
- #first message that will pop on the screen
12
  st.set_page_config(page_title = "Magical Healer")
13
- st.header("welcome, what help do you need?")
14
-
15
-
16
- #general instruction
17
 
 
 
 
 
18
  if "sessionMessages" not in st.session_state:
19
  st.session_state.sessionMessage = [
20
- SystemMessage(content = "You are a medieva magical healer known for your peculiar sarcasm.")
21
  ]
22
-
23
- #configuring the key
24
  os.environ["GOOGLE_API_KEY"] = keyfile.GOOGLEKEY
25
 
26
- #Response function
 
 
 
 
 
 
27
 
 
28
  def load_answer(question):
29
- st.session_state.sessionMessage.append(HumanMessage(content = question))
 
 
30
  assistant_answer = llm.invoke(st.session_state.sessionMessages)
31
- st.session_state.sessionMessages.append(AIMessge(content = assistant_answer))
32
- return assistant_answer.content
33
 
34
- #user msg
35
 
 
36
  def get_text():
37
  input_text = st.text_input("You: ", key = input)
38
- return input_text
 
 
 
 
 
39
 
40
- #implementation
 
 
 
 
1
+ # Generics
2
  import os
3
  import keyfile
4
  import warnings
5
+ import streamlit as st
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 = "Magical Healer")
14
+ st.header("Welcome, What help do you need?")
 
 
 
15
 
16
+ # initializing the sessionMessages
17
+ if "sessionMessages" not in st.session_state:
18
+ st.session_state["sessionMessages"] = []
19
+ # General Instruction
20
  if "sessionMessages" not in st.session_state:
21
  st.session_state.sessionMessage = [
22
+ SystemMessage(content = "You are a medieval magical healer known for your peculiar sarcasm")
23
  ]
24
+
25
+ # Configuring the key
26
  os.environ["GOOGLE_API_KEY"] = keyfile.GOOGLEKEY
27
 
28
+ # Create a model
29
+ llm = ChatGoogleGenerativeAI(
30
+ model="gemini-1.5-pro",
31
+ temperature=0.7,
32
+ convert_system_message_to_human= True
33
+ )
34
+
35
 
36
+ # Response function
37
  def load_answer(question):
38
+ # This is code, where we are adding new message to the model
39
+ st.session_state.sessionMessages.append(HumanMessage(content = question))
40
+ # We will get output from the model
41
  assistant_answer = llm.invoke(st.session_state.sessionMessages)
42
+ # Appending the assistance answer in conversation
43
+ st.session_state.sessionMessages.append(AIMessage(content = assistant_answer))
44
 
45
+ return assistant_answer.content
46
 
47
+ # User message
48
  def get_text():
49
  input_text = st.text_input("You: ", key = input)
50
+ return str(input_text)
51
+
52
+
53
+ # Implementation
54
+ user_input = get_text()
55
+ submit = st.button("Generate")
56
 
57
+ if submit:
58
+ resp = load_answer(user_input)
59
+ st.subheader("Answer: ")
60
+ st.write(resp, key = 1)