Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
@@ -6,8 +6,9 @@ default_lang = "en"
|
|
6 |
|
7 |
# ChatGPT
|
8 |
from pyChatGPT import ChatGPT
|
9 |
-
import whisper
|
10 |
-
whisper_model = whisper.load_model("small")
|
|
|
11 |
import os
|
12 |
session_token = os.environ.get('SessionToken')
|
13 |
|
@@ -45,6 +46,30 @@ def chat_hf(audio, custom_token, language):
|
|
45 |
return whisper_text, gpt_response, fp.name
|
46 |
|
47 |
# whisper
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
48 |
def translate(audio):
|
49 |
print("""
|
50 |
β
|
@@ -52,22 +77,10 @@ def translate(audio):
|
|
52 |
β
|
53 |
""")
|
54 |
|
55 |
-
|
56 |
-
|
57 |
-
|
58 |
-
|
59 |
-
|
60 |
-
_, probs = whisper_model.detect_language(mel)
|
61 |
-
|
62 |
-
transcript_options = whisper.DecodingOptions(task="transcribe", fp16 = False)
|
63 |
-
|
64 |
-
transcription = whisper.decode(whisper_model, mel, transcript_options)
|
65 |
-
|
66 |
-
print("language spoken: " + transcription.language)
|
67 |
-
print("transcript: " + transcription.text)
|
68 |
-
print("βββββββββββββββββββββββββββββββββββββββββββ")
|
69 |
-
|
70 |
-
return transcription.text
|
71 |
|
72 |
with gr.Blocks() as blocks:
|
73 |
gr.Markdown("<h1 style='text-align: center; margin-bottom: 1rem'>"
|
@@ -87,7 +100,7 @@ with gr.Blocks() as blocks:
|
|
87 |
submit = gr.Button("Submit", variant="primary")
|
88 |
with gr.Column():
|
89 |
text1 = gr.Textbox(label="Speech to Text")
|
90 |
-
text2 = gr.Textbox(label="
|
91 |
audio = gr.Audio(label="Output", interactive=False)
|
92 |
#gr.Markdown(info)
|
93 |
#gr.Markdown("<center>"
|
|
|
6 |
|
7 |
# ChatGPT
|
8 |
from pyChatGPT import ChatGPT
|
9 |
+
#import whisper
|
10 |
+
#whisper_model = whisper.load_model("small")
|
11 |
+
whisper = gr.Interface.load(name="spaces/sanchit-gandhi/whisper-large-v2")
|
12 |
import os
|
13 |
session_token = os.environ.get('SessionToken')
|
14 |
|
|
|
46 |
return whisper_text, gpt_response, fp.name
|
47 |
|
48 |
# whisper
|
49 |
+
#def translate(audio):
|
50 |
+
# print("""
|
51 |
+
# β
|
52 |
+
# Sending audio to Whisper ...
|
53 |
+
# β
|
54 |
+
# """)
|
55 |
+
#
|
56 |
+
# audio = whisper.load_audio(audio)
|
57 |
+
# audio = whisper.pad_or_trim(audio)
|
58 |
+
#
|
59 |
+
# mel = whisper.log_mel_spectrogram(audio).to(whisper_model.device)
|
60 |
+
#
|
61 |
+
# _, probs = whisper_model.detect_language(mel)
|
62 |
+
#
|
63 |
+
# transcript_options = whisper.DecodingOptions(task="transcribe", fp16 = False)
|
64 |
+
#
|
65 |
+
# transcription = whisper.decode(whisper_model, mel, transcript_options)
|
66 |
+
#
|
67 |
+
# print("language spoken: " + transcription.language)
|
68 |
+
# print("transcript: " + transcription.text)
|
69 |
+
# print("βββββββββββββββββββββββββββββββββββββββββββ")
|
70 |
+
#
|
71 |
+
# return transcription.text
|
72 |
+
|
73 |
def translate(audio):
|
74 |
print("""
|
75 |
β
|
|
|
77 |
β
|
78 |
""")
|
79 |
|
80 |
+
text_result = whisper(audio, None, "transcribe", fn_index=0)
|
81 |
+
print(text_result)
|
82 |
+
return text_result
|
83 |
+
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
84 |
|
85 |
with gr.Blocks() as blocks:
|
86 |
gr.Markdown("<h1 style='text-align: center; margin-bottom: 1rem'>"
|
|
|
100 |
submit = gr.Button("Submit", variant="primary")
|
101 |
with gr.Column():
|
102 |
text1 = gr.Textbox(label="Speech to Text")
|
103 |
+
text2 = gr.Textbox(label="ChatGPT response")
|
104 |
audio = gr.Audio(label="Output", interactive=False)
|
105 |
#gr.Markdown(info)
|
106 |
#gr.Markdown("<center>"
|