Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
|
@@ -5,7 +5,7 @@ import time
|
|
| 5 |
|
| 6 |
# from elevenlabs import set_api_key
|
| 7 |
|
| 8 |
-
|
| 9 |
import whisper
|
| 10 |
|
| 11 |
|
|
@@ -91,7 +91,26 @@ remember to not to include question number.
|
|
| 91 |
""")
|
| 92 |
|
| 93 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 94 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 95 |
|
| 96 |
def convert_tuples_to_list(tuples_list):
|
| 97 |
result = []
|
|
@@ -128,8 +147,11 @@ def run_text_prompt(message, chat_history):
|
|
| 128 |
def run_audio_prompt(audio, chat_history):
|
| 129 |
if audio is None:
|
| 130 |
return None, chat_history
|
|
|
|
|
|
|
| 131 |
|
| 132 |
-
|
|
|
|
| 133 |
_, chat_history = run_text_prompt(message_transcription, chat_history)
|
| 134 |
return None, chat_history
|
| 135 |
|
|
@@ -164,9 +186,9 @@ with gr.Blocks(title="hi") as app2:
|
|
| 164 |
# fn = run_audio_prompt,
|
| 165 |
# inputs = [audio, chatbot],
|
| 166 |
# outputs = [audio, chatbot]
|
| 167 |
-
|
| 168 |
-
send_audio_button = gr.Button("Send Audio", interactive=True)
|
| 169 |
-
send_audio_button.click(run_audio_prompt, [audio, chatbot], [audio, chatbot])
|
| 170 |
|
| 171 |
demo = gr.TabbedInterface([app2], [ "Interview"])
|
| 172 |
|
|
|
|
| 5 |
|
| 6 |
# from elevenlabs import set_api_key
|
| 7 |
|
| 8 |
+
import requests
|
| 9 |
import whisper
|
| 10 |
|
| 11 |
|
|
|
|
| 91 |
""")
|
| 92 |
|
| 93 |
|
| 94 |
+
from gradio_client import Client
|
| 95 |
+
API_URL = "https://sanchit-gandhi-whisper-jax.hf.space/"
|
| 96 |
+
|
| 97 |
+
# set up the Gradio client
|
| 98 |
+
client = Client(API_URL)
|
| 99 |
+
|
| 100 |
|
| 101 |
+
def transcribe_audio(audio_path, task="transcribe", return_timestamps=False):
|
| 102 |
+
"""Function to transcribe an audio file using the Whisper JAX endpoint."""
|
| 103 |
+
if task not in ["transcribe", "translate"]:
|
| 104 |
+
raise ValueError("task should be one of 'transcribe' or 'translate'.")
|
| 105 |
+
|
| 106 |
+
text, runtime = client.predict(
|
| 107 |
+
audio_path,
|
| 108 |
+
task,
|
| 109 |
+
return_timestamps,
|
| 110 |
+
api_name="/predict_1",
|
| 111 |
+
)
|
| 112 |
+
return text
|
| 113 |
+
|
| 114 |
|
| 115 |
def convert_tuples_to_list(tuples_list):
|
| 116 |
result = []
|
|
|
|
| 147 |
def run_audio_prompt(audio, chat_history):
|
| 148 |
if audio is None:
|
| 149 |
return None, chat_history
|
| 150 |
+
|
| 151 |
+
message_transcription = transcribe_audio(audio)
|
| 152 |
|
| 153 |
+
|
| 154 |
+
# message_transcription = model.transcribe(audio)["text"]
|
| 155 |
_, chat_history = run_text_prompt(message_transcription, chat_history)
|
| 156 |
return None, chat_history
|
| 157 |
|
|
|
|
| 186 |
# fn = run_audio_prompt,
|
| 187 |
# inputs = [audio, chatbot],
|
| 188 |
# outputs = [audio, chatbot]
|
| 189 |
+
audio.change(run_audio_prompt, [audio, chatbot], [audio, chatbot])
|
| 190 |
+
# send_audio_button = gr.Button("Send Audio", interactive=True)
|
| 191 |
+
# send_audio_button.click(run_audio_prompt, [audio, chatbot], [audio, chatbot])
|
| 192 |
|
| 193 |
demo = gr.TabbedInterface([app2], [ "Interview"])
|
| 194 |
|