CrispStrobe commited on
Commit
438216c
·
1 Parent(s): a08eefe

Integrate CrispASR backend

Browse files
Files changed (2) hide show
  1. app.py +50 -5
  2. build.sh +14 -2
app.py CHANGED
@@ -28,18 +28,35 @@ class LogCapture(io.StringIO):
28
  # Set up logging
29
  logging.basicConfig(level=logging.INFO, format='%(asctime)s - %(levelname)s - %(message)s')
30
 
31
- # Clone and install faster-whisper from GitHub
32
  try:
33
- subprocess.run(["git", "clone", "https://github.com/SYSTRAN/faster-whisper.git"], check=True)
34
- subprocess.run(["pip", "install", "-e", "./faster-whisper"], check=True)
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
35
  except subprocess.CalledProcessError as e:
36
- logging.error(f"Error during faster-whisper installation: {e}")
37
  sys.exit(1)
38
 
39
  sys.path.append("./faster-whisper")
 
40
 
41
  from faster_whisper import WhisperModel
42
  from faster_whisper.transcribe import BatchedInferencePipeline
 
43
 
44
  # Check for CUDA availability
45
  device = "cuda:0" if torch.cuda.is_available() else "cpu"
@@ -522,6 +539,8 @@ def get_model_options(pipeline_type):
522
  return ["cstr/whisper-large-v3-turbo-german-int8_float32","SYSTRAN/faster-whisper-large-v1", "GalaktischeGurke/primeline-whisper-large-v3-german-ct2"]
523
  elif pipeline_type == "transformers":
524
  return ["cstr/whisper-large-v3-turbo-german-int8_float32","openai/whisper-large-v3", "openai/whisper-large-v2", "openai/whisper-medium", "openai/whisper-small"]
 
 
525
  else:
526
  return []
527
 
@@ -638,6 +657,19 @@ def transcribe_audio(audio_input, audio_url, proxy_url, proxy_username, proxy_pa
638
  return_timestamps=True,
639
  device=device,
640
  )
 
 
 
 
 
 
 
 
 
 
 
 
 
641
  else:
642
  error_msg = "Invalid pipeline type"
643
  logging.error(error_msg)
@@ -656,6 +688,19 @@ def transcribe_audio(audio_input, audio_url, proxy_url, proxy_username, proxy_pa
656
  elif pipeline_type == "faster-sequenced":
657
  segments, info = model_or_pipeline.transcribe(audio_path)
658
  segments = list(segments) # Exhaust the generator
 
 
 
 
 
 
 
 
 
 
 
 
 
659
  else:
660
  result = model_or_pipeline(audio_path)
661
  segments = result["chunks"]
@@ -732,7 +777,7 @@ with gr.Blocks() as iface:
732
 
733
  with gr.Row():
734
  pipeline_type = gr.Dropdown(
735
- choices=["faster-batched", "faster-sequenced", "transformers"],
736
  label="Pipeline Type",
737
  value="faster-batched"
738
  )
 
28
  # Set up logging
29
  logging.basicConfig(level=logging.INFO, format='%(asctime)s - %(levelname)s - %(message)s')
30
 
31
+ # Clone and install dependencies from GitHub
32
  try:
33
+ if not os.path.exists("./faster-whisper"):
34
+ subprocess.run(["git", "clone", "https://github.com/SYSTRAN/faster-whisper.git"], check=True)
35
+ subprocess.run(["pip", "install", "-e", "./faster-whisper"], check=True)
36
+
37
+ if not os.path.exists("./CrispASR"):
38
+ logging.info("Cloning CrispASR...")
39
+ subprocess.run(["git", "clone", "https://github.com/CrispStrobe/CrispASR.git"], check=True)
40
+ logging.info("Building CrispASR...")
41
+ os.makedirs("./CrispASR/build", exist_ok=True)
42
+ subprocess.run([
43
+ "cmake", "..",
44
+ "-DCMAKE_PLATFORM_NO_VERSIONED_SONAME=ON",
45
+ "-DWHISPER_BUILD_TESTS=OFF",
46
+ "-DWHISPER_BUILD_EXAMPLES=OFF"
47
+ ], cwd="./CrispASR/build", check=True)
48
+ subprocess.run(["make", "-j4"], cwd="./CrispASR/build", check=True)
49
+
50
  except subprocess.CalledProcessError as e:
51
+ logging.error(f"Error during dependency installation: {e}")
52
  sys.exit(1)
53
 
54
  sys.path.append("./faster-whisper")
55
+ sys.path.append("./CrispASR/python")
56
 
57
  from faster_whisper import WhisperModel
58
  from faster_whisper.transcribe import BatchedInferencePipeline
59
+ import crispasr
60
 
61
  # Check for CUDA availability
62
  device = "cuda:0" if torch.cuda.is_available() else "cpu"
 
539
  return ["cstr/whisper-large-v3-turbo-german-int8_float32","SYSTRAN/faster-whisper-large-v1", "GalaktischeGurke/primeline-whisper-large-v3-german-ct2"]
540
  elif pipeline_type == "transformers":
541
  return ["cstr/whisper-large-v3-turbo-german-int8_float32","openai/whisper-large-v3", "openai/whisper-large-v2", "openai/whisper-medium", "openai/whisper-small"]
542
+ elif pipeline_type == "crispasr":
543
+ return ["auto", "ggml-base.en.bin", "canary-1b-v2.gguf", "parakeet-tdt-0.6b-v3.gguf", "qwen3-asr-0.6b.gguf"]
544
  else:
545
  return []
546
 
 
657
  return_timestamps=True,
658
  device=device,
659
  )
660
+ elif pipeline_type == "crispasr":
661
+ actual_model_path = model_id
662
+ if model_id == "auto":
663
+ # For demo purposes, we'll auto-resolve a decent model if 'auto' is picked
664
+ # In a real CLI it would prompt, here we just pick qwen3-asr-0.6b
665
+ actual_model_path = "qwen3-asr-0.6b.gguf"
666
+
667
+ # Check if it's a local file, if not try to ensure it's in cache
668
+ if not os.path.exists(actual_model_path):
669
+ logging.info(f"Ensuring model {actual_model_path} is in cache...")
670
+ actual_model_path = crispasr.cache_ensure_file(actual_model_path)
671
+
672
+ model_or_pipeline = crispasr.CrispASR(actual_model_path)
673
  else:
674
  error_msg = "Invalid pipeline type"
675
  logging.error(error_msg)
 
688
  elif pipeline_type == "faster-sequenced":
689
  segments, info = model_or_pipeline.transcribe(audio_path)
690
  segments = list(segments) # Exhaust the generator
691
+ elif pipeline_type == "crispasr":
692
+ # crispasr.transcribe returns a list of Segment objects
693
+ logging.info(f"Transcribing with CrispASR: {audio_path}")
694
+ raw_segments = model_or_pipeline.transcribe(audio_path)
695
+ # Map crispasr segments to the format expected by the downstream loop
696
+ segments = []
697
+ for s in raw_segments:
698
+ segments.append({
699
+ "start": s.start,
700
+ "end": s.end,
701
+ "text": s.text,
702
+ "timestamp": (s.start, s.end) # for transformers-style compatibility
703
+ })
704
  else:
705
  result = model_or_pipeline(audio_path)
706
  segments = result["chunks"]
 
777
 
778
  with gr.Row():
779
  pipeline_type = gr.Dropdown(
780
+ choices=["faster-batched", "faster-sequenced", "transformers", "crispasr"],
781
  label="Pipeline Type",
782
  value="faster-batched"
783
  )
build.sh CHANGED
@@ -1,5 +1,17 @@
 
 
1
  echo "downloading faster-whisper from git..."
2
  git clone https://github.com/SYSTRAN/faster-whisper.git
3
  cd faster-whisper
4
- echo "pip installing..."
5
- pip install .
 
 
 
 
 
 
 
 
 
 
 
1
+ #!/bin/bash
2
+ # Clone and install faster-whisper
3
  echo "downloading faster-whisper from git..."
4
  git clone https://github.com/SYSTRAN/faster-whisper.git
5
  cd faster-whisper
6
+ pip install .
7
+ cd ..
8
+
9
+ # Clone and build CrispASR
10
+ echo "downloading CrispASR from git..."
11
+ git clone https://github.com/CrispStrobe/CrispASR.git
12
+ cd CrispASR
13
+ mkdir build
14
+ cd build
15
+ cmake .. -DCMAKE_PLATFORM_NO_VERSIONED_SONAME=ON -DWHISPER_BUILD_TESTS=OFF -DWHISPER_BUILD_EXAMPLES=OFF
16
+ make -j$(nproc)
17
+ cd ../..