Spaces:
Paused
Paused
deepakaitcs
commited on
Commit
·
23d1aea
1
Parent(s):
ac04983
chat model
Browse files- SimpleAppFirst.txt +42 -0
- app.py +21 -16
SimpleAppFirst.txt
ADDED
@@ -0,0 +1,42 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
## Difference between Open AI and hugging face
|
2 |
+
|
3 |
+
import streamlit as st
|
4 |
+
|
5 |
+
|
6 |
+
from dotenv import load_dotenv
|
7 |
+
load_dotenv()
|
8 |
+
from langchain_openai import OpenAI
|
9 |
+
llm = OpenAI()
|
10 |
+
|
11 |
+
def load_Answer(inputtext):
|
12 |
+
result= llm(inputtext)
|
13 |
+
return result
|
14 |
+
|
15 |
+
st.set_page_config(
|
16 |
+
page_title="My Chat GPT",
|
17 |
+
page_icon="🧊",
|
18 |
+
layout="wide",
|
19 |
+
initial_sidebar_state="expanded",
|
20 |
+
menu_items={
|
21 |
+
'Get Help': 'https://www.extremelycoolapp.com/help',
|
22 |
+
'Report a bug': "https://www.extremelycoolapp.com/bug",
|
23 |
+
'About': "# This is a header. This is an *extremely* cool app!"
|
24 |
+
}
|
25 |
+
)
|
26 |
+
|
27 |
+
st.header('This is a header')
|
28 |
+
|
29 |
+
def get_text():
|
30 |
+
i= st.text_input("You: ", key="input")
|
31 |
+
return i
|
32 |
+
|
33 |
+
user_input = get_text()
|
34 |
+
|
35 |
+
response = load_Answer(user_input)
|
36 |
+
|
37 |
+
submit = st.button("Submit")
|
38 |
+
|
39 |
+
if submit:
|
40 |
+
st.subheader("Answer:")
|
41 |
+
st.write(response)
|
42 |
+
|
app.py
CHANGED
@@ -1,16 +1,8 @@
|
|
1 |
-
|
2 |
-
|
3 |
import streamlit as st
|
4 |
-
|
5 |
-
|
6 |
from dotenv import load_dotenv
|
7 |
load_dotenv()
|
8 |
-
from langchain_openai import OpenAI
|
9 |
-
llm = OpenAI()
|
10 |
-
|
11 |
-
def load_Answer(inputtext):
|
12 |
-
result= llm(inputtext)
|
13 |
-
return result
|
14 |
|
15 |
st.set_page_config(
|
16 |
page_title="My Chat GPT",
|
@@ -23,20 +15,33 @@ st.set_page_config(
|
|
23 |
'About': "# This is a header. This is an *extremely* cool app!"
|
24 |
}
|
25 |
)
|
26 |
-
|
27 |
st.header('This is a header')
|
28 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
29 |
def get_text():
|
30 |
i= st.text_input("You: ", key="input")
|
31 |
return i
|
32 |
|
33 |
user_input = get_text()
|
34 |
|
35 |
-
|
36 |
-
|
37 |
-
submit = st.button("Submit")
|
38 |
|
39 |
if submit:
|
40 |
-
|
|
|
41 |
st.write(response)
|
42 |
-
|
|
|
1 |
+
from langchain_openai.chat_models import ChatOpenAI
|
2 |
+
from langchain.schema import HumanMessage, SystemMessage, AIMessage
|
3 |
import streamlit as st
|
|
|
|
|
4 |
from dotenv import load_dotenv
|
5 |
load_dotenv()
|
|
|
|
|
|
|
|
|
|
|
|
|
6 |
|
7 |
st.set_page_config(
|
8 |
page_title="My Chat GPT",
|
|
|
15 |
'About': "# This is a header. This is an *extremely* cool app!"
|
16 |
}
|
17 |
)
|
|
|
18 |
st.header('This is a header')
|
19 |
|
20 |
+
|
21 |
+
chatModel = ChatOpenAI(temperature=.8,model="gpt-3.5-turbo", max_tokens=30)
|
22 |
+
|
23 |
+
if "sessionMessages" not in st.session_state:
|
24 |
+
print("No Session message")
|
25 |
+
st.session_state.sessionMessages = [
|
26 |
+
SystemMessage("You are a comedian who answers to query in comedy")
|
27 |
+
]
|
28 |
+
|
29 |
+
|
30 |
+
def load_answers(input):
|
31 |
+
st.session_state.sessionMessages.append(HumanMessage(content=input))
|
32 |
+
result =chatModel(st.session_state.sessionMessages)
|
33 |
+
st.session_state.sessionMessages.append(AIMessage(content=result.content))
|
34 |
+
return result.content
|
35 |
+
|
36 |
def get_text():
|
37 |
i= st.text_input("You: ", key="input")
|
38 |
return i
|
39 |
|
40 |
user_input = get_text()
|
41 |
|
42 |
+
submit=st.button("submit")
|
|
|
|
|
43 |
|
44 |
if submit:
|
45 |
+
response = load_answers(user_input)
|
46 |
+
st.subheader("Answer: ")
|
47 |
st.write(response)
|
|