Update app.py
Browse files
app.py
CHANGED
|
@@ -1,32 +1,42 @@
|
|
|
|
|
| 1 |
import streamlit as st
|
| 2 |
-
from langchain.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 3 |
|
| 4 |
-
#Function to return the response
|
| 5 |
def load_answer(question):
|
| 6 |
-
llm = OpenAI(model_name="gpt-3.5-turbo",temperature=0)
|
| 7 |
-
answer=llm(question)
|
| 8 |
-
return answer
|
| 9 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 10 |
|
| 11 |
-
#App UI starts here
|
| 12 |
-
st.set_page_config(page_title="Entz's LLM LangChain-gpt-3.5-turbo", page_icon=":ant:")
|
| 13 |
-
st.header("Entz's LLM LangChain Base Model")
|
| 14 |
|
| 15 |
-
|
| 16 |
-
|
| 17 |
-
input_text = st.text_input("Enter your question: ", key="input")
|
| 18 |
return input_text
|
| 19 |
|
|
|
|
| 20 |
|
| 21 |
-
user_input
|
| 22 |
-
|
| 23 |
|
| 24 |
-
submit = st.button('Entz AI Answer')
|
| 25 |
-
|
| 26 |
-
#If generate button is clicked
|
| 27 |
if submit:
|
|
|
|
|
|
|
|
|
|
| 28 |
|
| 29 |
-
st.
|
| 30 |
-
|
| 31 |
-
st.write(response)
|
| 32 |
|
|
|
|
| 1 |
+
|
| 2 |
import streamlit as st
|
| 3 |
+
from langchain.chat_models import ChatOpenAI
|
| 4 |
+
from langchain.schema import SystemMessage, HumanMessage, AIMessage
|
| 5 |
+
|
| 6 |
+
# From here down is all the StreamLit UI.
|
| 7 |
+
st.set_page_config(page_title="Entz's LLM LangChain-OpenAI", page_icon=":ant:")
|
| 8 |
+
st.header("Role Play: A 5-Years Old Cute Girl")
|
| 9 |
+
|
| 10 |
+
# put a presumptions for ai to the streamlit session state
|
| 11 |
+
# st.session_state provides a way to store and persist data between reruns,
|
| 12 |
+
# effectively allowing the app to remember information like user inputs, selections, variables
|
| 13 |
+
if "presumptions" not in st.session_state:
|
| 14 |
+
st.session_state.presumptions = [
|
| 15 |
+
SystemMessage(content="You are a 5 years old girl, who can only speak simple words, and is a huge fan of Barbie and toy kitchen sets.")
|
| 16 |
+
]
|
| 17 |
|
|
|
|
| 18 |
def load_answer(question):
|
|
|
|
|
|
|
|
|
|
| 19 |
|
| 20 |
+
st.session_state.presumptions.append(HumanMessage(content=question))
|
| 21 |
+
assistant_answer = chat(st.session_state.presumptions )
|
| 22 |
+
# store the new answer the presumption list
|
| 23 |
+
st.session_state.presumptions.append(AIMessage(content=assistant_answer.content))
|
| 24 |
+
return assistant_answer.content
|
| 25 |
|
|
|
|
|
|
|
|
|
|
| 26 |
|
| 27 |
+
def get_text():
|
| 28 |
+
input_text = st.text_input("Ask me question please~ : ", key= input)
|
|
|
|
| 29 |
return input_text
|
| 30 |
|
| 31 |
+
chat = ChatOpenAI(temperature=0)
|
| 32 |
|
| 33 |
+
user_input=get_text()
|
| 34 |
+
submit = st.button('Little girl answers: ')
|
| 35 |
|
|
|
|
|
|
|
|
|
|
| 36 |
if submit:
|
| 37 |
+
|
| 38 |
+
response = load_answer(user_input)
|
| 39 |
+
st.subheader("Answer:")
|
| 40 |
|
| 41 |
+
st.write(response,key= 1)
|
|
|
|
|
|
|
| 42 |
|