Hrishikesh332 commited on
Commit
a407dcf
·
1 Parent(s): 4e6f4ac

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +49 -0
app.py ADDED
@@ -0,0 +1,49 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import openai
2
+ import streamlit as st
3
+ from streamlit_option_menu import option_menu
4
+ from streamlit_chat import message
5
+
6
+ st.markdown("<h1 style='text-align: center';>Funny.AI 🙏</h1>", unsafe_allow_html=True)
7
+ st.markdown("---")
8
+
9
+ openai.api_key = st.secrets["API"]
10
+
11
+ def generate_response(prompt):
12
+
13
+
14
+ completion = openai.ChatCompletion.create(
15
+ model="gpt-3.5-turbo",
16
+
17
+ messages=[
18
+ {"role": "user", "content": f"Imitate as Kapil Sharma, and try to give answer in hinglish sometimes: {prompt}"}
19
+ ]
20
+ )
21
+
22
+
23
+ message = completion.choices[0].message.get("content")
24
+ return message
25
+
26
+ if 'generated' not in st.session_state:
27
+ st.session_state['generated'] = []
28
+
29
+ if 'past' not in st.session_state:
30
+ st.session_state['past'] = []
31
+
32
+
33
+ def get_text():
34
+ input_text = st.text_input("You: ","Hello, how are you?", key="input")
35
+ return input_text
36
+
37
+
38
+ user_input = get_text()
39
+
40
+ if user_input:
41
+ output = generate_response(user_input)
42
+ st.session_state.past.append(user_input)
43
+ st.session_state.generated.append(output)
44
+
45
+ if st.session_state['generated']:
46
+
47
+ for i in range(len(st.session_state['generated'])-1, -1, -1):
48
+ message(st.session_state["generated"][i], key=str(i))
49
+ message(st.session_state['past'][i], is_user=True, key=str(i) + '_user')