Vihang28 commited on
Commit
12d3854
1 Parent(s): 1f38dc2

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +41 -7
app.py CHANGED
@@ -7,12 +7,10 @@ import openai
7
 
8
  prompt = "Type and press Enter"
9
 
10
- r = sr.Recognizer()
11
 
12
-
13
- def record_text(audio_file,prompt):
14
- if len(prompt) == 0:
15
- prompt = "Apply proper punctuations, upper case and lower case to the provided text."
16
  sound = audio_file
17
  sound_type = sound.split(".")
18
  if sound_type[-1] == 'mp3':
@@ -32,12 +30,48 @@ def record_text(audio_file,prompt):
32
 
33
  MyText = r.recognize_google(audio2, language="en-US", key=None, show_all=False)
34
  MyText = MyText.lower()
35
- return (MyText,prompt)
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
36
 
37
  def message_and_history(audio_file,input, history, api_key):
38
  history = history or []
39
  input_text = "Type and press Enter"
40
- output_text = record_text(audio_file,input)
41
 
42
  if len(input_text) == 0:
43
  input_text = "Speech from the video."
 
7
 
8
  prompt = "Type and press Enter"
9
 
 
10
 
11
+ def record_text(audio_file):
12
+ r = sr.Recognizer()
13
+
 
14
  sound = audio_file
15
  sound_type = sound.split(".")
16
  if sound_type[-1] == 'mp3':
 
30
 
31
  MyText = r.recognize_google(audio2, language="en-US", key=None, show_all=False)
32
  MyText = MyText.lower()
33
+ return (MyText)
34
+
35
+
36
+ def api_calling(audio_file, prompt, api_key):
37
+ audio_text = record_text(audio_file)
38
+ if len(prompt) == 0:
39
+ prompt = "Apply proper punctuations, upper case and lower case to the provided text."
40
+
41
+ headers = {
42
+ "Content-Type": "application/json",
43
+ "Authorization": f"Bearer {api_key}"
44
+ }
45
+ payload = {
46
+ "model": "gpt-3.5-turbo",
47
+ "messages": [
48
+ {
49
+ "role": "user",
50
+ "content": [
51
+ {
52
+ "type": "text",
53
+ "text": prompt
54
+ },
55
+ {
56
+ "type": "text",
57
+ "text": audio_text
58
+ }
59
+ }
60
+ ]
61
+ }
62
+ ],
63
+ "max_tokens": 1000
64
+ }
65
+ response = requests.post("https://api.openai.com/v1/chat/completions", headers=headers, json=payload)
66
+ audio_text_res = response.json()
67
+ return audio_text_res
68
+
69
+
70
 
71
  def message_and_history(audio_file,input, history, api_key):
72
  history = history or []
73
  input_text = "Type and press Enter"
74
+ output_text = api_calling(audio_file,input,api_key)
75
 
76
  if len(input_text) == 0:
77
  input_text = "Speech from the video."