Spaces:
Sleeping
Sleeping
Commit
·
fee56a4
1
Parent(s):
225974b
Update app.py
Browse files
app.py
CHANGED
|
@@ -4,18 +4,28 @@
|
|
| 4 |
import streamlit as st
|
| 5 |
|
| 6 |
|
| 7 |
-
from langchain.
|
| 8 |
|
| 9 |
-
|
| 10 |
-
def load_answer(question):
|
| 11 |
-
llm = OpenAI(model_name="text-davinci-003",temperature=0)
|
| 12 |
-
answer=llm(question)
|
| 13 |
-
return answer
|
| 14 |
|
| 15 |
|
| 16 |
#App UI starts here
|
| 17 |
st.set_page_config(page_title="LangChain Demo", page_icon=":robot:")
|
| 18 |
-
st.header("
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 19 |
|
| 20 |
#Gets the user input
|
| 21 |
def get_text():
|
|
@@ -24,14 +34,11 @@ def get_text():
|
|
| 24 |
|
| 25 |
|
| 26 |
user_input=get_text()
|
| 27 |
-
|
| 28 |
-
|
| 29 |
-
submit = st.button('Generate')
|
| 30 |
-
|
| 31 |
#If generate button is clicked
|
| 32 |
if submit:
|
| 33 |
-
|
| 34 |
st.subheader("Answer:")
|
| 35 |
|
| 36 |
-
st.write(response)
|
| 37 |
|
|
|
|
| 4 |
import streamlit as st
|
| 5 |
|
| 6 |
|
| 7 |
+
from langchain.chat_models import ChatOpenAI
|
| 8 |
|
| 9 |
+
from langchain.schema import (AIMessage,HumanMessage,SystemMessage)
|
|
|
|
|
|
|
|
|
|
|
|
|
| 10 |
|
| 11 |
|
| 12 |
#App UI starts here
|
| 13 |
st.set_page_config(page_title="LangChain Demo", page_icon=":robot:")
|
| 14 |
+
st.header("GetRoastedGPT")
|
| 15 |
+
|
| 16 |
+
if "sessionMessages" not in st.session_state:
|
| 17 |
+
st.session_state.sessionMessages = [
|
| 18 |
+
SystemMessage(content= "You are an assistant which roasts every input")
|
| 19 |
+
]
|
| 20 |
+
|
| 21 |
+
def load_answer(question):
|
| 22 |
+
|
| 23 |
+
st.session_state.sessionMessages.append(HumanMessage(content=question))
|
| 24 |
+
|
| 25 |
+
AIans= chat(st.session_state.sessionMessages)
|
| 26 |
+
st.session_state.sessionMessages.append(AIMessage(content=AIans.content))
|
| 27 |
+
|
| 28 |
+
return AIans.content
|
| 29 |
|
| 30 |
#Gets the user input
|
| 31 |
def get_text():
|
|
|
|
| 34 |
|
| 35 |
|
| 36 |
user_input=get_text()
|
| 37 |
+
submit = st.button('Roast me')
|
|
|
|
|
|
|
|
|
|
| 38 |
#If generate button is clicked
|
| 39 |
if submit:
|
| 40 |
+
response= load_answer(user_input)
|
| 41 |
st.subheader("Answer:")
|
| 42 |
|
| 43 |
+
st.write(response,key=1)
|
| 44 |
|