tanish1407 commited on
Commit
72e0907
·
1 Parent(s): 14bd173

first commit

Browse files
Files changed (2) hide show
  1. app3.py +51 -0
  2. requirements.text +4 -0
app3.py ADDED
@@ -0,0 +1,51 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import os
2
+ import openai
3
+ import streamlit as st
4
+ import speech_recognition as sr
5
+ import pyttsx3
6
+
7
+ openai.api_key = "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"
8
+ r = sr.Recognizer()
9
+
10
+ def verify_news(prompt):
11
+ prompt_text = f"{prompt} : "
12
+ response = openai.Completion.create(
13
+ model="text-davinci-003", prompt=prompt_text, temperature=0, max_tokens=1000
14
+ )
15
+ return response["choices"][0]["text"]
16
+
17
+ def text_input():
18
+ prompt = st.text_input("HEY THERE! LET ME KNOW WHAT YOU WANT ")
19
+ return prompt
20
+
21
+ def voice_input():
22
+ with sr.Microphone() as source:
23
+ r.adjust_for_ambient_noise(source)
24
+ st.write("Speak now!")
25
+ audio = r.listen(source)
26
+ text = r.recognize_google(audio).lower()
27
+ return text
28
+
29
+ def text_to_speech(text):
30
+ engine = pyttsx3.init()
31
+ engine.say(text)
32
+ engine.runAndWait()
33
+
34
+ def main():
35
+ st.title("VOICE-GPT")
36
+
37
+ prompt = ""
38
+ option = st.radio("Choose Input Method", ("Text Input", "Voice Input"))
39
+ if option == "Text Input":
40
+ prompt = text_input()
41
+ else:
42
+ prompt = voice_input()
43
+
44
+ if st.button("Go"):
45
+ result = verify_news(prompt)
46
+ st.write(result)
47
+ text_to_speech(result)
48
+
49
+
50
+ if __name__ == "__main__":
51
+ main()
requirements.text ADDED
@@ -0,0 +1,4 @@
 
 
 
 
 
1
+ openai
2
+ streamlit
3
+ speechrecognition
4
+ pyttsx3