Spaces:
Runtime error
Runtime error
suvankarmaity
commited on
Commit
•
8aaa5db
1
Parent(s):
b972c1f
Upload 4 files
Browse files- README.md +6 -6
- app.py +64 -0
- env-sample.txt +1 -0
- requirements.txt +0 -0
README.md
CHANGED
@@ -1,13 +1,13 @@
|
|
1 |
---
|
2 |
title: ChatModelApp
|
3 |
-
emoji:
|
4 |
-
colorFrom:
|
5 |
-
colorTo:
|
6 |
sdk: streamlit
|
7 |
-
sdk_version: 1.
|
8 |
app_file: app.py
|
9 |
pinned: false
|
10 |
-
license: mit
|
11 |
---
|
12 |
|
13 |
-
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,64 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
|
2 |
+
import streamlit as st
|
3 |
+
|
4 |
+
#As Langchain team has been working aggresively on improving the tool, we can see a lot of changes happening every weeek,
|
5 |
+
#As a part of it, the below import has been depreciated
|
6 |
+
#from langchain.chat_models import ChatOpenAI
|
7 |
+
|
8 |
+
#New import from langchain, which replaces the above
|
9 |
+
from langchain_openai import ChatOpenAI
|
10 |
+
|
11 |
+
#import os
|
12 |
+
#os.environ["OPENAI_API_KEY"] = "sk-PLfFw23dd932dfg34446dftyvvdfgdfgmvXr2dL8hVowXdt"
|
13 |
+
|
14 |
+
|
15 |
+
from langchain.schema import (
|
16 |
+
AIMessage,
|
17 |
+
HumanMessage,
|
18 |
+
SystemMessage
|
19 |
+
)
|
20 |
+
|
21 |
+
# From here down is all the StreamLit UI
|
22 |
+
st.set_page_config(page_title="LangChain Demo", page_icon=":robot:")
|
23 |
+
st.header("Hey, I'm your Chat GPT")
|
24 |
+
|
25 |
+
|
26 |
+
|
27 |
+
if "sessionMessages" not in st.session_state:
|
28 |
+
st.session_state.sessionMessages = [
|
29 |
+
SystemMessage(content="You are a helpful assistant.")
|
30 |
+
]
|
31 |
+
|
32 |
+
|
33 |
+
|
34 |
+
def load_answer(question):
|
35 |
+
|
36 |
+
st.session_state.sessionMessages.append(HumanMessage(content=question))
|
37 |
+
|
38 |
+
assistant_answer = chat.invoke(st.session_state.sessionMessages )
|
39 |
+
|
40 |
+
st.session_state.sessionMessages.append(AIMessage(content=assistant_answer.content))
|
41 |
+
|
42 |
+
return assistant_answer.content
|
43 |
+
|
44 |
+
|
45 |
+
def get_text():
|
46 |
+
input_text = st.text_input("You: ")
|
47 |
+
return input_text
|
48 |
+
|
49 |
+
|
50 |
+
chat = ChatOpenAI(temperature=0)
|
51 |
+
|
52 |
+
|
53 |
+
|
54 |
+
|
55 |
+
user_input=get_text()
|
56 |
+
submit = st.button('Generate')
|
57 |
+
|
58 |
+
if submit:
|
59 |
+
|
60 |
+
response = load_answer(user_input)
|
61 |
+
st.subheader("Answer:")
|
62 |
+
|
63 |
+
st.write(response)
|
64 |
+
|
env-sample.txt
ADDED
@@ -0,0 +1 @@
|
|
|
|
|
1 |
+
OPENAI_API_KEY=""
|
requirements.txt
ADDED
Binary file (246 Bytes). View file
|
|