Spaces:
Sleeping
Sleeping
Download cpu_fallback.py from ladybug11/stories-we-keep-speech: direct link, hf CLI and curl.
- Browser
- Download file 690 Bytes
-
https://huggingface.co/spaces/ladybug11/stories-we-keep-speech/resolve/main/cpu_fallback.py
- Command line
-
hf download hf://spaces/ladybug11/stories-we-keep-speech/cpu_fallback.py
-
curl -L -o cpu_fallback.py https://huggingface.co/spaces/ladybug11/stories-we-keep-speech/resolve/main/cpu_fallback.py
690 Bytes
| """Use ordinary CPU inference when ZeroGPU declines a short recording.""" | |
| MAX_CPU_SECONDS = 60 | |
| def recognize_with_fallback(gpu, cpu, wave, language, seconds): | |
| try: | |
| return gpu(wave, language), 'gpu' | |
| except Exception as error: | |
| message = str(error).lower() | |
| quota = ('quota' in message or 'runs limit' in message) and ('gpu' in message or 'zerogpu' in message) | |
| if not quota: | |
| raise | |
| if seconds > MAX_CPU_SECONDS: | |
| raise ValueError('The free GPU quota is unavailable. Record a clip of 60 seconds or less to use free CPU transcription, or try the longer recording later.') from None | |
| return cpu(wave, language), 'cpu' | |