Vihang28 commited on
Commit
678aa20
1 Parent(s): d16b4fd

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +12 -7
app.py CHANGED
@@ -5,9 +5,14 @@ from os import path
5
  import requests
6
  import openai
7
 
 
 
8
  r = sr.Recognizer()
9
 
10
- def record_text(audio_file):
 
 
 
11
  sound = audio_file
12
  sound_type = sound.split(".")
13
  if sound_type[-1] == 'mp3':
@@ -34,22 +39,22 @@ def record_text(audio_file):
34
  except sr.UnknownValueError:
35
  print("Google Speech Recognition could not understand audio")
36
 
37
- return MyText
38
 
39
- def message_and_history(audio_file, history, api_key):
40
  history = history or []
41
  input_text = "Type and press Enter"
42
- output_text = record_text(audio_file)
43
 
44
  if len(input_text) == 0:
45
- input_text = "Apply proper punctuation on the given paragraph."
46
  history.append((input_text, output_text))
47
  else:
48
  history.append((input_text, output_text))
49
 
50
  return history, history
51
 
52
- prompt = "Type and press Enter"
53
  block = gr.Blocks(theme=gr.themes.Glass(primary_hue="slate"))
54
  with block:
55
  gr.Markdown("""<h1><center>Audio Recognition - Ask and Learn about an Audio</center></h1> """)
@@ -64,6 +69,6 @@ with block:
64
  state = gr.State()
65
 
66
  upload_button.click(message_and_history, inputs=[aud_input, state, api_input], outputs=[chatbot, state])
67
- message.submit(message_and_history, inputs=[aud_input, state, api_input], outputs=[chatbot, state])
68
  message.submit(lambda: None, None, message, queue=False)
69
  block.launch(share=True)
 
5
  import requests
6
  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':
 
39
  except sr.UnknownValueError:
40
  print("Google Speech Recognition could not understand audio")
41
 
42
+ return (MyText,prompt)
43
 
44
+ def message_and_history(audio_file,input, history, api_key):
45
  history = history or []
46
  input_text = "Type and press Enter"
47
+ output_text = record_text(audio_file,input)
48
 
49
  if len(input_text) == 0:
50
+ input_text = "Speech from the video."
51
  history.append((input_text, output_text))
52
  else:
53
  history.append((input_text, output_text))
54
 
55
  return history, history
56
 
57
+
58
  block = gr.Blocks(theme=gr.themes.Glass(primary_hue="slate"))
59
  with block:
60
  gr.Markdown("""<h1><center>Audio Recognition - Ask and Learn about an Audio</center></h1> """)
 
69
  state = gr.State()
70
 
71
  upload_button.click(message_and_history, inputs=[aud_input, state, api_input], outputs=[chatbot, state])
72
+ message.submit(message_and_history, inputs=[aud_input,message, state, api_input], outputs=[chatbot, state])
73
  message.submit(lambda: None, None, message, queue=False)
74
  block.launch(share=True)