-
Notifications
You must be signed in to change notification settings - Fork 533
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add Replicate demo and API #42
Open
chenxwh
wants to merge
8
commits into
Vaibhavs10:main
Choose a base branch
from
chenxwh:main
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 1 commit
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
3dd373d
replicate
chenxwh 3c49506
Merge branch 'Vaibhavs10:main' into main
chenxwh 0da829e
add diarise_audio
chenxwh e499ed6
Merge branch 'Vaibhavs10:main' into main
chenxwh 1cd3472
fix diarise_audio params typo
chenxwh 9cac00c
add a set of langauges options
chenxwh 9350efc
Merge remote-tracking branch 'upstream/main' into main
chenxwh 6a4fbf5
use pget for weight
chenxwh File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
|
@@ -16,6 +16,9 @@ Not convinced? Here are some benchmarks we ran on a free [Google Colab T4 GPU](/ | |||||
| Faster Whisper (`fp16` + `beam_size [1]`) | ~9.23 (*9 min 23 sec*) | | ||||||
| Faster Whisper (`8-bit` + `beam_size [1]`) | ~8 (*8 min 15 sec*) | | ||||||
|
||||||
Try the Relicate demo here: [![Replicate](https://replicate.com/cjwbw/insanely-fast-whisper/badge)](https://replicate.com/cjwbw/insanely-fast-whisper) | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
|
||||||
|
||||||
## 🆕 Blazingly fast transcriptions via your terminal! ⚡️ | ||||||
|
||||||
We've added a CLI to enable fast transcriptions. Here's how you can use it: | ||||||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
# Configuration for Cog ⚙️ | ||
# Reference: https://github.com/replicate/cog/blob/main/docs/yaml.md | ||
|
||
build: | ||
gpu: true | ||
system_packages: | ||
- "ffmpeg" | ||
- "ninja-build" | ||
python_version: "3.11" | ||
python_packages: | ||
- "torch==2.0.1" | ||
- "tqdm==4.66.1" | ||
- "more-itertools==10.1.0" | ||
- "transformers==4.35.0" | ||
- "ffmpeg-python==0.2.0" | ||
- "openai-whisper==20231106" | ||
- "optimum==1.14.0" | ||
run: | ||
- pip install packaging | ||
- pip install flash-attn --no-build-isolation | ||
|
||
predict: "predict.py:Predictor" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
from typing import Any | ||
import torch | ||
from transformers import ( | ||
WhisperFeatureExtractor, | ||
WhisperTokenizerFast, | ||
WhisperForConditionalGeneration, | ||
pipeline, | ||
) | ||
from cog import BasePredictor, Input, Path | ||
|
||
|
||
class Predictor(BasePredictor): | ||
def setup(self): | ||
"""Loads whisper models into memory to make running multiple predictions efficient""" | ||
model_cache = "model_cache" | ||
local_files_only = True # set to true after the model is cached to model_cache | ||
model_id = "openai/whisper-large-v3" | ||
torch_dtype = torch.float16 | ||
device = "cuda:0" | ||
model = WhisperForConditionalGeneration.from_pretrained( | ||
model_id, | ||
torch_dtype=torch_dtype, | ||
cache_dir=model_cache, | ||
local_files_only=local_files_only, | ||
).to(device) | ||
|
||
tokenizer = WhisperTokenizerFast.from_pretrained( | ||
model_id, cache_dir=model_cache, local_files_only=local_files_only | ||
) | ||
feature_extractor = WhisperFeatureExtractor.from_pretrained( | ||
model_id, cache_dir=model_cache, local_files_only=local_files_only | ||
) | ||
|
||
self.pipe = pipeline( | ||
"automatic-speech-recognition", | ||
model=model, | ||
tokenizer=tokenizer, | ||
feature_extractor=feature_extractor, | ||
model_kwargs={"use_flash_attention_2": True}, | ||
torch_dtype=torch_dtype, | ||
device=device, | ||
) | ||
|
||
def predict( | ||
self, | ||
audio: Path = Input(description="Audio file"), | ||
task: str = Input( | ||
choices=["transcribe", "translate"], | ||
default="transcribe", | ||
description="Task to perform: transcribe or translate to another language. (default: transcribe).", | ||
), | ||
language: str = Input( | ||
default=None, | ||
description="Optional. Language spoken in the audio, specify None to perform language detection.", | ||
), | ||
batch_size: int = Input( | ||
default=24, | ||
description="Number of parallel batches you want to compute. Reduce if you face OOMs. (default: 24).", | ||
), | ||
return_timestamps: bool = Input( | ||
default=True, | ||
description="Return timestamps information when set to True.", | ||
), | ||
) -> Any: | ||
"""Transcribes and optionally translates a single audio file""" | ||
|
||
outputs = self.pipe( | ||
str(audio), | ||
chunk_length_s=30, | ||
batch_size=batch_size, | ||
generate_kwargs={"task": task, "language": language}, | ||
return_timestamps=return_timestamps, | ||
) | ||
return outputs |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That redirects to https://replicate.com/vaibhavs10/incredibly-fast-whisper .
Does it help you track incoming users?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No that's just a leftover old URL that redirects to the renamed model.