Spaces:
Build error
Build error
Upload folder using huggingface_hub
Browse files- Dockerfile +3 -2
- config.py +1 -1
- services/transcriber.py +17 -13
Dockerfile
CHANGED
|
@@ -4,7 +4,6 @@ RUN apt-get update && \
|
|
| 4 |
apt-get install -y --no-install-recommends ffmpeg && \
|
| 5 |
rm -rf /var/lib/apt/lists/*
|
| 6 |
|
| 7 |
-
# Create non-root user (HF Spaces requirement)
|
| 8 |
RUN useradd -m -u 1000 user
|
| 9 |
USER user
|
| 10 |
ENV PATH="/home/user/.local/bin:$PATH"
|
|
@@ -13,9 +12,11 @@ WORKDIR /home/user/app
|
|
| 13 |
COPY --chown=user:user requirements.txt .
|
| 14 |
RUN pip install --no-cache-dir --user -r requirements.txt
|
| 15 |
|
|
|
|
|
|
|
|
|
|
| 16 |
COPY --chown=user:user . .
|
| 17 |
RUN mkdir -p temp_jobs static
|
| 18 |
|
| 19 |
EXPOSE 7860
|
| 20 |
-
|
| 21 |
CMD ["python", "main.py"]
|
|
|
|
| 4 |
apt-get install -y --no-install-recommends ffmpeg && \
|
| 5 |
rm -rf /var/lib/apt/lists/*
|
| 6 |
|
|
|
|
| 7 |
RUN useradd -m -u 1000 user
|
| 8 |
USER user
|
| 9 |
ENV PATH="/home/user/.local/bin:$PATH"
|
|
|
|
| 12 |
COPY --chown=user:user requirements.txt .
|
| 13 |
RUN pip install --no-cache-dir --user -r requirements.txt
|
| 14 |
|
| 15 |
+
# Install faster-whisper separately (lighter than full whisperx)
|
| 16 |
+
RUN pip install --no-cache-dir --user faster-whisper || echo "faster-whisper install skipped"
|
| 17 |
+
|
| 18 |
COPY --chown=user:user . .
|
| 19 |
RUN mkdir -p temp_jobs static
|
| 20 |
|
| 21 |
EXPOSE 7860
|
|
|
|
| 22 |
CMD ["python", "main.py"]
|
config.py
CHANGED
|
@@ -26,7 +26,7 @@ AUDIO_CHANNELS = 1
|
|
| 26 |
|
| 27 |
# === TRANSCRIPTION: HuggingFace Free GPU API ===
|
| 28 |
# This uses HF's free Inference API with GPU — no local model needed!
|
| 29 |
-
HF_API_URL = "https://api-inference.huggingface.co/models/openai/whisper-
|
| 30 |
HF_TOKEN = os.getenv("HF_TOKEN", "") # Optional: set for higher rate limits
|
| 31 |
# Fallback to local faster-whisper if HF API fails
|
| 32 |
WHISPER_MODEL_SIZE = os.getenv("WHISPER_MODEL", "tiny")
|
|
|
|
| 26 |
|
| 27 |
# === TRANSCRIPTION: HuggingFace Free GPU API ===
|
| 28 |
# This uses HF's free Inference API with GPU — no local model needed!
|
| 29 |
+
HF_API_URL = "https://api-inference.huggingface.co/models/openai/whisper-small"
|
| 30 |
HF_TOKEN = os.getenv("HF_TOKEN", "") # Optional: set for higher rate limits
|
| 31 |
# Fallback to local faster-whisper if HF API fails
|
| 32 |
WHISPER_MODEL_SIZE = os.getenv("WHISPER_MODEL", "tiny")
|
services/transcriber.py
CHANGED
|
@@ -26,27 +26,31 @@ def transcribe_audio(
|
|
| 26 |
device: str = "cpu",
|
| 27 |
progress_callback=None,
|
| 28 |
) -> List[Dict]:
|
| 29 |
-
"""Transcribe audio
|
| 30 |
|
| 31 |
-
# Try
|
| 32 |
try:
|
| 33 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 34 |
segments = _transcribe_hf_api(audio_path, output_dir, source_language, progress_callback)
|
| 35 |
if segments and len(segments) > 0:
|
| 36 |
logger.info(f"HF API transcription success: {len(segments)} segments")
|
| 37 |
return segments
|
| 38 |
except Exception as e:
|
| 39 |
-
logger.
|
| 40 |
|
| 41 |
-
|
| 42 |
-
|
| 43 |
-
|
| 44 |
-
return _transcribe_local(audio_path, output_dir, source_language, progress_callback)
|
| 45 |
-
except Exception as e2:
|
| 46 |
-
logger.error(f"Local fallback also failed: {e2}")
|
| 47 |
-
raise RuntimeError(
|
| 48 |
-
"Transcription failed. HF API may be overloaded. "
|
| 49 |
-
"Try again in a few minutes or set HF_TOKEN env var for priority access."
|
| 50 |
)
|
| 51 |
|
| 52 |
|
|
|
|
| 26 |
device: str = "cpu",
|
| 27 |
progress_callback=None,
|
| 28 |
) -> List[Dict]:
|
| 29 |
+
"""Transcribe audio. Chain: HF API (GPU) → local faster-whisper → error."""
|
| 30 |
|
| 31 |
+
# Try local faster-whisper FIRST (more reliable on Spaces)
|
| 32 |
try:
|
| 33 |
+
import faster_whisper
|
| 34 |
+
logger.info("Using local faster-whisper (tiny model, CPU)...")
|
| 35 |
+
return _transcribe_local(audio_path, output_dir, source_language, progress_callback)
|
| 36 |
+
except ImportError:
|
| 37 |
+
logger.info("faster-whisper not available, trying HF API...")
|
| 38 |
+
except Exception as e:
|
| 39 |
+
logger.warning(f"Local transcription failed: {e}. Trying HF API...")
|
| 40 |
+
|
| 41 |
+
# Fallback: HuggingFace Inference API (free GPU)
|
| 42 |
+
try:
|
| 43 |
+
logger.info("Attempting HuggingFace API transcription (whisper-small)...")
|
| 44 |
segments = _transcribe_hf_api(audio_path, output_dir, source_language, progress_callback)
|
| 45 |
if segments and len(segments) > 0:
|
| 46 |
logger.info(f"HF API transcription success: {len(segments)} segments")
|
| 47 |
return segments
|
| 48 |
except Exception as e:
|
| 49 |
+
logger.error(f"HF API also failed: {e}")
|
| 50 |
|
| 51 |
+
raise RuntimeError(
|
| 52 |
+
"Transcription failed with all methods. "
|
| 53 |
+
"The audio file may be too large or the service is overloaded. Try again."
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 54 |
)
|
| 55 |
|
| 56 |
|