divakaivan commited on
Commit
538698d
·
verified ·
1 Parent(s): d38a10a

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +12 -3
app.py CHANGED
@@ -1,20 +1,29 @@
1
  from transformers import pipeline
2
  import gradio as gr
3
  from gtts import gTTS
 
4
 
5
  # Load the Whisper model for speech-to-text
6
  pipe = pipeline(model="openai/whisper-small")
7
 
8
  # Load the text generation model
9
- text_pipe = pipeline("text2text-generation", model="google/flan-t5-base")
 
 
 
 
 
 
 
 
10
 
11
  def transcribe(audio):
12
  # Transcribe the audio to text
13
  text = pipe(audio)["text"]
14
 
15
  # Generate a response from the transcribed text
16
- lm_response = text_pipe(text)[0]["generated_text"]
17
-
18
  # Convert the response text to speech
19
  tts = gTTS(lm_response, lang='ko')
20
 
 
1
  from transformers import pipeline
2
  import gradio as gr
3
  from gtts import gTTS
4
+ import openai
5
 
6
  # Load the Whisper model for speech-to-text
7
  pipe = pipeline(model="openai/whisper-small")
8
 
9
  # Load the text generation model
10
+ # text_pipe = pipeline("text2text-generation", model="google/flan-t5-base")
11
+
12
+ def generate_gpt_response(text):
13
+ response = openai.Completion.create(
14
+ engine="text-davinci-003", # Use the appropriate GPT-3 engine
15
+ prompt=text,
16
+ max_tokens=150
17
+ )
18
+ return response.choices[0].text.strip()
19
 
20
  def transcribe(audio):
21
  # Transcribe the audio to text
22
  text = pipe(audio)["text"]
23
 
24
  # Generate a response from the transcribed text
25
+ # lm_response = text_pipe(text)[0]["generated_text"]
26
+ lm_response = generate_gpt_response(text)
27
  # Convert the response text to speech
28
  tts = gTTS(lm_response, lang='ko')
29