Antigravity Agent commited on
Commit
c00f45b
·
1 Parent(s): 6dd81c2

Convert to Gradio Space and optimize for ZeroGPU

Browse files
Files changed (4) hide show
  1. Dockerfile +0 -27
  2. README.md +1 -1
  3. app.py +15 -10
  4. packages.txt +1 -0
Dockerfile DELETED
@@ -1,27 +0,0 @@
1
- FROM python:3.10-slim
2
-
3
- # Install system dependencies
4
- RUN apt-get update && apt-get install -y \
5
- ffmpeg \
6
- git \
7
- && rm -rf /var/lib/apt/lists/*
8
-
9
- # Set working directory
10
- WORKDIR /app
11
-
12
- # Copy requirements and install
13
- COPY requirements.txt .
14
- RUN pip install --no-cache-dir -r requirements.txt
15
-
16
- # Copy application code
17
- COPY . .
18
-
19
- # Expose the Gradio port
20
- EXPOSE 7860
21
-
22
- # Set environment variables for Gradio
23
- ENV GRADIO_SERVER_NAME="0.0.0.0"
24
- ENV GRADIO_SERVER_PORT=7860
25
-
26
- # Run the application
27
- CMD ["python", "app.py"]
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
README.md CHANGED
@@ -3,7 +3,7 @@ title: VoiceScript
3
  emoji: 🏆
4
  colorFrom: purple
5
  colorTo: gray
6
- sdk: docker
7
  pinned: false
8
  ---
9
 
 
3
  emoji: 🏆
4
  colorFrom: purple
5
  colorTo: gray
6
+ sdk: gradio
7
  pinned: false
8
  ---
9
 
app.py CHANGED
@@ -5,16 +5,18 @@ from faster_whisper import WhisperModel
5
  import torch
6
  import spaces
7
 
8
- # Initialize model
9
- # Note: On ZeroGPU, we initialize on CPU or wait for the GPU function
10
- device = "cuda" if torch.cuda.is_available() else "cpu"
11
- compute_type = "float16" if torch.cuda.is_available() else "int8"
12
 
13
- print(f"Initial check - CUDA available: {torch.cuda.is_available()}")
14
- print(f"Loading Whisper Large V3...")
15
-
16
- # Global model variable
17
- model = WhisperModel("large-v3", device=device, compute_type=compute_type)
 
 
 
18
 
19
  def format_timestamp(seconds):
20
  h = int(seconds // 3600)
@@ -39,7 +41,10 @@ def transcribe(audio_path, task="transcribe", language=None):
39
  if audio_path is None:
40
  return "Please upload an audio file.", None
41
 
42
- print(f"Transcribing {audio_path} on {device}...")
 
 
 
43
 
44
  options = {
45
  "task": task,
 
5
  import torch
6
  import spaces
7
 
8
+ # Global cache for the model so we don't reload it if not necessary
9
+ # But on ZeroGPU, it's safer to load it per request or rely on the container state.
10
+ _cached_model = None
 
11
 
12
+ def get_model():
13
+ global _cached_model
14
+ if _cached_model is None:
15
+ device = "cuda" if torch.cuda.is_available() else "cpu"
16
+ compute_type = "float16" if torch.cuda.is_available() else "int8"
17
+ print(f"Loading Whisper Large V3 on {device} ({compute_type})...")
18
+ _cached_model = WhisperModel("large-v3", device=device, compute_type=compute_type)
19
+ return _cached_model
20
 
21
  def format_timestamp(seconds):
22
  h = int(seconds // 3600)
 
41
  if audio_path is None:
42
  return "Please upload an audio file.", None
43
 
44
+ # Get model inside the ZeroGPU context
45
+ model = get_model()
46
+
47
+ print(f"Transcribing {audio_path}...")
48
 
49
  options = {
50
  "task": task,
packages.txt ADDED
@@ -0,0 +1 @@
 
 
1
+ ffmpeg