alakxender commited on
Commit
d2a74d8
·
1 Parent(s): 6430b7c
Files changed (1) hide show
  1. app.py +60 -19
app.py CHANGED
@@ -1,22 +1,8 @@
 
1
  import gradio as gr
2
- from transformers import Wav2Vec2ForCTC, Wav2Vec2ProcessorWithLM
3
- import torch
4
- import torchaudio
5
- import numpy as np
6
-
7
- # Device and dtype configuration
8
- device = torch.device("cuda" if torch.cuda.is_available() else "cpu")
9
- torch_dtype = torch.float16 if torch.cuda.is_available() else torch.float32
10
-
11
- # Load model and processor with LM
12
- processor = Wav2Vec2ProcessorWithLM.from_pretrained("alakxender/wav2vec2-large-mms-1b-dv-syn-md")
13
- model = Wav2Vec2ForCTC.from_pretrained(
14
- "alakxender/wav2vec2-large-mms-1b-dv-syn-md",
15
- torch_dtype=torch_dtype
16
- ).to(device)
17
-
18
- MAX_LENGTH = 120 # 2 minutes
19
- MIN_LENGTH = 1 # 1 second
20
 
21
  def transcribe(audio_file):
22
  try:
@@ -84,6 +70,61 @@ iface = gr.Interface(
84
  description="Upload an audio file to transcribe Dhivehi speech to text using language model enhanced decoding."
85
  )
86
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
87
  # Launch the interface
88
  if __name__ == "__main__":
89
- iface.launch()
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import spaces
2
  import gradio as gr
3
+ import subprocess
4
+ import sys
5
+ import os
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
6
 
7
  def transcribe(audio_file):
8
  try:
 
70
  description="Upload an audio file to transcribe Dhivehi speech to text using language model enhanced decoding."
71
  )
72
 
73
+
74
+ def install_requirements():
75
+ requirements_path = 'requirements.txt'
76
+
77
+ # Check if requirements.txt exists
78
+ if not os.path.exists(requirements_path):
79
+ print("Error: requirements.txt not found")
80
+ return False
81
+
82
+ try:
83
+ print("Installing requirements...")
84
+ # Using --no-cache-dir to avoid memory issues
85
+ subprocess.check_call([
86
+ sys.executable,
87
+ "-m",
88
+ "pip",
89
+ "install",
90
+ "-r",
91
+ requirements_path,
92
+ "--no-cache-dir"
93
+ ])
94
+ print("Successfully installed all requirements")
95
+ return True
96
+ except subprocess.CalledProcessError as e:
97
+ print(f"Error installing requirements: {e}")
98
+ return False
99
+ except Exception as e:
100
+ print(f"Unexpected error: {e}")
101
+ return False
102
+
103
  # Launch the interface
104
  if __name__ == "__main__":
105
+ success = install_requirements()
106
+ if success:
107
+ print("All requirements installed successfully")
108
+
109
+ from transformers import Wav2Vec2ForCTC, Wav2Vec2ProcessorWithLM
110
+ import torch
111
+ import torchaudio
112
+ import numpy as np
113
+
114
+ # Device and dtype configuration
115
+ device = torch.device("cuda" if torch.cuda.is_available() else "cpu")
116
+ torch_dtype = torch.float16 if torch.cuda.is_available() else torch.float32
117
+
118
+ # Load model and processor with LM
119
+ processor = Wav2Vec2ProcessorWithLM.from_pretrained("alakxender/wav2vec2-large-mms-1b-dv-syn-md")
120
+ model = Wav2Vec2ForCTC.from_pretrained(
121
+ "alakxender/wav2vec2-large-mms-1b-dv-syn-md",
122
+ torch_dtype=torch_dtype
123
+ ).to(device)
124
+
125
+ MAX_LENGTH = 120 # 2 minutes
126
+ MIN_LENGTH = 1 # 1 second
127
+
128
+ iface.launch()
129
+ else:
130
+ print("Failed to install some requirements")