-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathchat_gpt.py
More file actions
28 lines (18 loc) · 707 Bytes
/
chat_gpt.py
File metadata and controls
28 lines (18 loc) · 707 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
import openai
import speech_recognition as sr
choice = input('do you want to ask question text or speech: ')
question =""
if choice == 'speech':
r = sr.Recognizer()
with sr.Microphone(device_index=0) as source:
audio = r.listen(source, phrase_time_limit=5)
question_json = r.recognize_google(audio)
if choice == 'text':
print()
question = input('Enter your question: ')
openai.api_key = 'YOUR_OPENAI_API_KEY'
answer = openai.Completion.create(
model = 'text-davinci-003',
prompt = question
)['choices'][0]['text']
print('\nanswer found! answer is written below {}'.format(answer))