Skip to content

Instantly share code, notes, and snippets.

@sanchit-gandhi
Last active November 8, 2024 00:53
Show Gist options
  • Save sanchit-gandhi/781dd7003c5b201bfe16d28634c8d4cf to your computer and use it in GitHub Desktop.
Save sanchit-gandhi/781dd7003c5b201bfe16d28634c8d4cf to your computer and use it in GitHub Desktop.
The Whisper JAX demo can be used as an endpoint through the Gradio Client library. The transcription API takes as input the audio file you want to transcribe, as well as optional arguments such as the task (transcribe or translate) and whether to return timestamps.
from gradio_client import Client
API_URL = "https://sanchit-gandhi-whisper-jax.hf.space/"
# set up the Gradio client
client = Client(API_URL)
def transcribe_audio(audio_path, task="transcribe", return_timestamps=False):
"""Function to transcribe an audio file using the Whisper JAX endpoint."""
if task not in ["transcribe", "translate"]:
raise ValueError("task should be one of 'transcribe' or 'translate'.")
text, runtime = client.predict(
audio_path,
task,
return_timestamps,
api_name="/predict_1",
)
return text
# transcribe an audio file using the Whisper JAX endpoint
output = transcribe_audio("audio.mp3")
# transcribe and return timestamps
output_with_timestamps = transcribe_audio("audio.mp3", return_timestamps=True)
@ashishb
Copy link

ashishb commented Feb 18, 2024

@sanchit-gandhi Any way to increase the timeout? The default seems to be 60 seconds.

@spazm
Copy link

spazm commented Nov 8, 2024

The API_URL seems to only be forwarding gateway. And now the gateway is failing. Where was the service running on the other end?

https://sanchit-gandhi-whisper-jax.hf.space/ is just an nginx container to forward requests to the API_URL stored in the hugging face secret for the project.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment