Walterchamy commited on
Commit
1824341
1 Parent(s): 4be82b7

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +60 -11
app.py CHANGED
@@ -2,7 +2,11 @@ import os
2
  import openai
3
  from gtts import gTTS
4
  import streamlit as st
5
- openai.api_key = os.getenv("OPENAI_API_KEY")
 
 
 
 
6
 
7
 
8
 
@@ -97,29 +101,74 @@ For contact information:
97
  - P.O. Box 3172, Arusha
98
  """
99
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
100
  def generate_response(user_input):
101
- response = openai.ChatCompletion.create(
102
- model="gpt-3.5-turbo",
103
  messages=[
104
  {"role": "system", "content": "All your answers should be in Swahili or English. Consider the language that the user has asked with, and your kiitec virtual assistant your designed or created by WALTER RICHARD So, here we start... Your virtual assistant of DON BOSCO KIITEC. You will reply to the queries that the user might ask!\n\n" + KIITEC_CONTENT},
105
- {"role": "assistant", "content": "Hi, how can i assist you today?"},
106
  {"role": "user", "content": user_input},
107
  ]
108
  )
109
- return response['choices'][0]['message']['content']
110
-
111
 
112
  def text_to_speech(text):
113
  # Create a text-to-speech object
114
- tts = gTTS(text=text, lang=('en'))
115
  # Save the audio file
116
  tts.save('output.mp3')
117
 
118
  # Play the audio file
119
- st.audio("output.mp3")
120
 
121
  def main():
122
-
123
  col1, col2 = st.columns([1, 4])
124
 
125
  with col1:
@@ -128,7 +177,7 @@ def main():
128
  with col2:
129
  st.markdown("<h4 style='text-align: center; color: white;'>KILIMANJARO INTERNATIONAL INSTITUTE FOR TELECOMMUNICATION, ELECTRONICS & COMPUTERS</h4>", unsafe_allow_html=True)
130
  st.header("KIITEC VIRTUAL ASSISTANT")
131
- st.write("Welcome for questions concerning kiitec insitution")
132
  user_input = st.text_input("Enter your question:")
133
  if st.button("Answer"):
134
  with st.spinner("Generating Response...."):
@@ -137,4 +186,4 @@ def main():
137
  text_to_speech(response_text)
138
 
139
  if __name__ == '__main__':
140
- main()
 
2
  import openai
3
  from gtts import gTTS
4
  import streamlit as st
5
+ from openai import OpenAI
6
+
7
+ client = OpenAI(
8
+ api_key=os.environ['OPENAI_API_KEY'], # this is also the default, it can be omitted
9
+ )
10
 
11
 
12
 
 
101
  - P.O. Box 3172, Arusha
102
  """
103
 
104
+ #def generate_response(user_input):
105
+ # response = openai.ChatCompletion.create(
106
+ # model="gpt-3.5-turbo",
107
+ # messages=[
108
+ # {"role": "system", "content": "All your answers should be in Swahili or English. Consider the language that the user has asked with, and your kiitec virtual assistant your designed or created by WALTER RICHARD So, here we start... Your virtual assistant of DON BOSCO KIITEC. You will reply to the queries that the user might ask!\n\n" + KIITEC_CONTENT},
109
+ # {"role": "assistant", "content": "Hi, how can i assist you today?"},
110
+ # {"role": "user", "content": user_input},
111
+ # ]
112
+ # )
113
+ # return response['choices'][0]['message']['content']
114
+ #
115
+
116
+ #def text_to_speech(text):
117
+ # # Create a text-to-speech object
118
+ # tts = gTTS(text=text, lang=('en'))
119
+ # # Save the audio file
120
+ # tts.save('output.mp3')
121
+ #
122
+ # # Play the audio file
123
+ # st.audio("output.mp3")
124
+ #
125
+ #def main():
126
+ #
127
+ # col1, col2 = st.columns([1, 4])
128
+ #
129
+ # with col1:
130
+ # st.image('logo.png', caption=None, width=200, use_column_width=200)
131
+ #
132
+ # with col2:
133
+ # st.markdown("<h4 style='text-align: center; color: white;'>KILIMANJARO INTERNATIONAL INSTITUTE FOR TELECOMMUNICATION, ELECTRONICS & COMPUTERS</h4>", unsafe_allow_html=True)
134
+ # st.header("KIITEC VIRTUAL ASSISTANT")
135
+ # st.write("Welcome for questions concerning kiitec insitution")
136
+ # user_input = st.text_input("Enter your question:")
137
+ # if st.button("Answer"):
138
+ # with st.spinner("Generating Response...."):
139
+ # response_text = generate_response(user_input)
140
+ # st.write("Answer:", response_text)
141
+ # text_to_speech(response_text)
142
+ #
143
+ #if __name__ == '__main__':
144
+ # main()
145
+
146
+
147
+
148
+ # create OpenAI client
149
+ client = OpenAI()
150
+
151
  def generate_response(user_input):
152
+ response = client.completions.create(
153
+ model='gpt-3.5-turbo',
154
  messages=[
155
  {"role": "system", "content": "All your answers should be in Swahili or English. Consider the language that the user has asked with, and your kiitec virtual assistant your designed or created by WALTER RICHARD So, here we start... Your virtual assistant of DON BOSCO KIITEC. You will reply to the queries that the user might ask!\n\n" + KIITEC_CONTENT},
156
+ {"role": "assistant", "content": "Hi, how can I assist you today?"},
157
  {"role": "user", "content": user_input},
158
  ]
159
  )
160
+ return response.choices[0].message.content
 
161
 
162
  def text_to_speech(text):
163
  # Create a text-to-speech object
164
+ tts = gTTS(text=text, lang='en')
165
  # Save the audio file
166
  tts.save('output.mp3')
167
 
168
  # Play the audio file
169
+ st.audio("output.mp3")
170
 
171
  def main():
 
172
  col1, col2 = st.columns([1, 4])
173
 
174
  with col1:
 
177
  with col2:
178
  st.markdown("<h4 style='text-align: center; color: white;'>KILIMANJARO INTERNATIONAL INSTITUTE FOR TELECOMMUNICATION, ELECTRONICS & COMPUTERS</h4>", unsafe_allow_html=True)
179
  st.header("KIITEC VIRTUAL ASSISTANT")
180
+ st.write("Welcome for questions concerning kiitec institution")
181
  user_input = st.text_input("Enter your question:")
182
  if st.button("Answer"):
183
  with st.spinner("Generating Response...."):
 
186
  text_to_speech(response_text)
187
 
188
  if __name__ == '__main__':
189
+ main()