Spaces:
Sleeping
Sleeping
Commit
·
f30cae6
1
Parent(s):
997c6e7
Create app.py
Browse files
app.py
ADDED
@@ -0,0 +1,58 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import openai
|
2 |
+
import streamlit as st
|
3 |
+
from PIL import Image
|
4 |
+
from streamlit_option_menu import option_menu
|
5 |
+
from streamlit_chat import message
|
6 |
+
|
7 |
+
st.markdown("<h1 style='text-align: center';>Verse.AI 🙏</h1>", unsafe_allow_html=True)
|
8 |
+
st.markdown("---")
|
9 |
+
|
10 |
+
openai.api_key = st.secrets["API"]
|
11 |
+
|
12 |
+
def generate_response(prompt):
|
13 |
+
|
14 |
+
|
15 |
+
completion = openai.ChatCompletion.create(
|
16 |
+
model="gpt-3.5-turbo",
|
17 |
+
|
18 |
+
messages=[
|
19 |
+
{"role": "user", "content": f"Reply in a professional manner : {prompt}"}
|
20 |
+
]
|
21 |
+
)
|
22 |
+
|
23 |
+
|
24 |
+
message = completion.choices[0].message.get("content")
|
25 |
+
return message
|
26 |
+
|
27 |
+
if 'generated' not in st.session_state:
|
28 |
+
st.session_state['generated'] = []
|
29 |
+
|
30 |
+
if 'past' not in st.session_state:
|
31 |
+
st.session_state['past'] = []
|
32 |
+
|
33 |
+
|
34 |
+
def get_text():
|
35 |
+
input_text = st.text_input("You: ","Hello, how are you?", key="input")
|
36 |
+
return input_text
|
37 |
+
|
38 |
+
|
39 |
+
user_input = get_text()
|
40 |
+
|
41 |
+
if user_input:
|
42 |
+
output = generate_response(user_input)
|
43 |
+
st.session_state.past.append(user_input)
|
44 |
+
st.session_state.generated.append(output)
|
45 |
+
|
46 |
+
if st.session_state['generated']:
|
47 |
+
|
48 |
+
for i in range(len(st.session_state['generated'])-1, -1, -1):
|
49 |
+
message(st.session_state["generated"][i], key=str(i))
|
50 |
+
message(st.session_state['past'][i], is_user=True, key=str(i) + '_user')
|
51 |
+
|
52 |
+
|
53 |
+
|
54 |
+
|
55 |
+
|
56 |
+
|
57 |
+
|
58 |
+
|