Spaces:
Sleeping
Sleeping
MatheusHRV
commited on
Commit
•
fcf3944
1
Parent(s):
0d8a4a4
Upload 4 files
Browse files- README.md +6 -5
- app.py +55 -0
- env-sample.txt +1 -0
- requirements.txt +5 -0
README.md
CHANGED
@@ -1,12 +1,13 @@
|
|
1 |
---
|
2 |
-
title:
|
3 |
-
emoji:
|
4 |
-
colorFrom:
|
5 |
colorTo: red
|
6 |
sdk: streamlit
|
7 |
-
sdk_version: 1.
|
8 |
app_file: app.py
|
9 |
pinned: false
|
10 |
---
|
11 |
|
12 |
-
Check out the configuration reference at
|
|
|
|
1 |
---
|
2 |
+
title: ChatModelApp
|
3 |
+
emoji: ⚡
|
4 |
+
colorFrom: gray
|
5 |
colorTo: red
|
6 |
sdk: streamlit
|
7 |
+
sdk_version: 1.21.0
|
8 |
app_file: app.py
|
9 |
pinned: false
|
10 |
---
|
11 |
|
12 |
+
Check out the configuration reference at.
|
13 |
+
https://huggingface.co/docs/hub/spaces-config-reference
|
app.py
ADDED
@@ -0,0 +1,55 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
|
2 |
+
import streamlit as st
|
3 |
+
|
4 |
+
|
5 |
+
from langchain.chat_models import ChatOpenAI
|
6 |
+
from langchain.schema import (
|
7 |
+
AIMessage,
|
8 |
+
HumanMessage,
|
9 |
+
SystemMessage
|
10 |
+
)
|
11 |
+
|
12 |
+
# From here down is all the StreamLit UI
|
13 |
+
st.set_page_config(page_title="LangChain Demo", page_icon=":robot:")
|
14 |
+
st.header("Hey, I'm your Chat GPT")
|
15 |
+
|
16 |
+
|
17 |
+
|
18 |
+
if "sessionMessages" not in st.session_state:
|
19 |
+
st.session_state.sessionMessages = [
|
20 |
+
SystemMessage(content="You are a helpful assistant.")
|
21 |
+
]
|
22 |
+
|
23 |
+
|
24 |
+
|
25 |
+
def load_answer(question):
|
26 |
+
|
27 |
+
st.session_state.sessionMessages.append(HumanMessage(content=question))
|
28 |
+
|
29 |
+
assistant_answer = chat(st.session_state.sessionMessages )
|
30 |
+
|
31 |
+
st.session_state.sessionMessages.append(AIMessage(content=assistant_answer.content))
|
32 |
+
|
33 |
+
return assistant_answer.content
|
34 |
+
|
35 |
+
|
36 |
+
def get_text():
|
37 |
+
input_text = st.text_input("You: ", key= input)
|
38 |
+
return input_text
|
39 |
+
|
40 |
+
|
41 |
+
chat = ChatOpenAI(temperature=0)
|
42 |
+
|
43 |
+
|
44 |
+
|
45 |
+
|
46 |
+
user_input=get_text()
|
47 |
+
submit = st.button('Generate')
|
48 |
+
|
49 |
+
if submit:
|
50 |
+
|
51 |
+
response = load_answer(user_input)
|
52 |
+
st.subheader("Answer:")
|
53 |
+
|
54 |
+
st.write(response,key= 1)
|
55 |
+
|
env-sample.txt
ADDED
@@ -0,0 +1 @@
|
|
|
|
|
1 |
+
OPENAI_API_KEY=""
|
requirements.txt
ADDED
@@ -0,0 +1,5 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
streamlit==1.29.0
|
2 |
+
langchain==0.0.351
|
3 |
+
openai==1.5.0
|
4 |
+
streamlit-chat==0.0.2.2
|
5 |
+
python-dotenv==1.0.0
|