gutai123 commited on
Commit
1025314
·
verified ·
1 Parent(s): 0789e3d

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +9 -6
app.py CHANGED
@@ -1,36 +1,39 @@
1
 
2
  import streamlit as st
3
- from langchain_openai import ChatOpenAI
4
  from langchain.schema import AIMessage, HumanMessage, SystemMessage
5
 
6
  # Set up Streamlit page
7
  st.set_page_config(page_title="LangChain Demo", page_icon=":robot:")
8
  st.header("DIBYAJYOTI'S PERSONAL GPT ASSISTANT")
9
 
10
-
11
  if "sessionMessages" not in st.session_state:
12
  st.session_state.sessionMessages = [
13
  SystemMessage(content="You are a helpful assistant.")
14
  ]
15
 
16
- chat = ChatOpenAI(temperature=0)
17
-
18
 
 
19
  def get_text():
20
  input_text = st.text_input("You: ")
21
  return input_text
22
 
23
-
24
  def load_answer(question):
25
  st.session_state.sessionMessages.append(HumanMessage(content=question))
26
 
27
-
28
  assistant_answer = chat.invoke(st.session_state.sessionMessages)
29
 
 
30
  st.session_state.sessionMessages.append(AIMessage(content=assistant_answer.content))
31
 
32
  return assistant_answer.content
33
 
 
34
  user_input = get_text()
35
  submit = st.button('CLICK HERE TO GET YOUR RESPONSE')
36
 
 
1
 
2
  import streamlit as st
3
+ from langchain_huggingface import HuggingFaceLLM
4
  from langchain.schema import AIMessage, HumanMessage, SystemMessage
5
 
6
  # Set up Streamlit page
7
  st.set_page_config(page_title="LangChain Demo", page_icon=":robot:")
8
  st.header("DIBYAJYOTI'S PERSONAL GPT ASSISTANT")
9
 
10
+ # Check for session state and initialize session if not set
11
  if "sessionMessages" not in st.session_state:
12
  st.session_state.sessionMessages = [
13
  SystemMessage(content="You are a helpful assistant.")
14
  ]
15
 
16
+ # Use HuggingFace GPT-2 model (Free and Open-Source)
17
+ chat = HuggingFaceLLM(model="gpt2")
18
 
19
+ # Function to get user input
20
  def get_text():
21
  input_text = st.text_input("You: ")
22
  return input_text
23
 
24
+ # Function to process the chat and load an answer
25
  def load_answer(question):
26
  st.session_state.sessionMessages.append(HumanMessage(content=question))
27
 
28
+ # Get the response from the assistant (HuggingFace GPT-2 model)
29
  assistant_answer = chat.invoke(st.session_state.sessionMessages)
30
 
31
+ # Add the assistant's response to the session state
32
  st.session_state.sessionMessages.append(AIMessage(content=assistant_answer.content))
33
 
34
  return assistant_answer.content
35
 
36
+ # Streamlit UI
37
  user_input = get_text()
38
  submit = st.button('CLICK HERE TO GET YOUR RESPONSE')
39