Walterchamy commited on
Commit
5614071
1 Parent(s): 706b97e

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +62 -32
app.py CHANGED
@@ -100,49 +100,49 @@ For contact information:
100
  - Email: [email protected]
101
  - P.O. Box 3172, Arusha
102
  """
103
- client = OpenAI()
104
 
105
- def generate_response(user_input):
106
- response = client.completions.create(
107
- model="gpt-3.5-turbo",
108
- messages=[
109
- {"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},
110
- {"role": "assistant", "content": "Hi, how can i assist you today?"},
111
- {"role": "user", "content": user_input},
112
- ]
113
- )
114
  #return response['choices'][0]['message']['content']
115
- return response.choices[0].message.content
116
 
117
- def text_to_speech(text):
118
  # Create a text-to-speech object
119
- tts = gTTS(text=text, lang=('en'))
120
  # # Save the audio file
121
- tts.save('output.mp3')
122
 
123
  # # Play the audio file
124
- st.audio("output.mp3")
125
 
126
- def main():
127
 
128
- col1, col2 = st.columns([1, 4])
129
 
130
- with col1:
131
- st.image('logo.png', caption=None, width=200, use_column_width=200)
132
 
133
- with col2:
134
- st.markdown("<h4 style='text-align: center; color: white;'>KILIMANJARO INTERNATIONAL INSTITUTE FOR TELECOMMUNICATION, ELECTRONICS & COMPUTERS</h4>", unsafe_allow_html=True)
135
- st.header("KIITEC VIRTUAL ASSISTANT")
136
- st.write("Welcome for questions concerning kiitec insitution")
137
- user_input = st.text_input("Enter your question:")
138
- if st.button("Answer"):
139
- with st.spinner("Generating Response...."):
140
- response_text = generate_response(user_input)
141
- st.write("Answer:", response_text)
142
- text_to_speech(response_text)
143
 
144
- if __name__ == '__main__':
145
- main()
146
 
147
 
148
 
@@ -189,4 +189,34 @@ if __name__ == '__main__':
189
  # text_to_speech(response_text)
190
 
191
  #if __name__ == '__main__':
192
- # main()
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
100
  - Email: [email protected]
101
  - P.O. Box 3172, Arusha
102
  """
103
+ #client = OpenAI()
104
 
105
+ #def generate_response(user_input):
106
+ # response = client.completions.create(
107
+ # model="gpt-3.5-turbo",
108
+ # messages=[
109
+ # {"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},
110
+ # {"role": "assistant", "content": "Hi, how can i assist you today?"},
111
+ # {"role": "user", "content": user_input},
112
+ # ]
113
+ # )
114
  #return response['choices'][0]['message']['content']
115
+ #return response.choices[0].message.content
116
 
117
+ #def text_to_speech(text):
118
  # Create a text-to-speech object
119
+ # tts = gTTS(text=text, lang=('en'))
120
  # # Save the audio file
121
+ # tts.save('output.mp3')
122
 
123
  # # Play the audio file
124
+ # st.audio("output.mp3")
125
 
126
+ #def main():
127
 
128
+ # col1, col2 = st.columns([1, 4])
129
 
130
+ # with col1:
131
+ # st.image('logo.png', caption=None, width=200, use_column_width=200)
132
 
133
+ # with col2:
134
+ # st.markdown("<h4 style='text-align: center; color: white;'>KILIMANJARO INTERNATIONAL INSTITUTE FOR TELECOMMUNICATION, ELECTRONICS & COMPUTERS</h4>", unsafe_allow_html=True)
135
+ # st.header("KIITEC VIRTUAL ASSISTANT")
136
+ # st.write("Welcome for questions concerning kiitec insitution")
137
+ # user_input = st.text_input("Enter your question:")
138
+ # if st.button("Answer"):
139
+ # with st.spinner("Generating Response...."):
140
+ # response_text = generate_response(user_input)
141
+ # st.write("Answer:", response_text)
142
+ # text_to_speech(response_text)
143
 
144
+ #if __name__ == '__main__':
145
+ # main()
146
 
147
 
148
 
 
189
  # text_to_speech(response_text)
190
 
191
  #if __name__ == '__main__':
192
+ # main()
193
+ import streamlit as st
194
+ from openai import OpenAI
195
+ client = OpenAI()
196
+
197
+ def generate_response(user_input):
198
+ response = client.chat.completions.create(
199
+ model="gpt-3.5-turbo",
200
+ messages=[
201
+ {"role": "system", "content": "i have create a streamlit app of question and answering and i'm using chatgpt by using openaiAPI but gives me the error provided"},
202
+ {"role": "user", "content": user_input}
203
+ ],
204
+ temperature=0.7,
205
+ max_tokens=100,
206
+ top_p=1.0,
207
+ frequency_penalty=0.0,
208
+ presence_penalty=0.0
209
+ )
210
+ return response['choices'][0]['message']['content']
211
+
212
+ def main():
213
+ st.title("Question and Answering with OpenAI")
214
+ st.write("Ask a question and get an answer!")
215
+ user_input = st.text_input("Enter your question:")
216
+ if st.button("Answer"):
217
+ with st.spinner("Generating Response..."):
218
+ response_text = generate_response(user_input)
219
+ st.write("Answer:", response_text)
220
+
221
+ if __name__ == '__main__':
222
+ main()