jsbeaudry commited on
Commit
aed667b
·
verified ·
1 Parent(s): 53e911a

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +30 -48
app.py CHANGED
@@ -1,64 +1,46 @@
1
  from transformers import pipeline
2
  import gradio as gr
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
3
 
4
- pipe = pipeline(model="jsbeaudry/creole-speech-to-text")
5
 
6
  def transcribe(audio):
 
7
  text = pipe(audio)["text"]
8
  return text
9
 
10
 
11
  iface = gr.Interface(
12
  fn=transcribe,
13
- inputs=gr.Audio(type="filepath"),
14
  outputs="text",
15
  title="Whisper medium Creole",
16
  description="Realtime demo for Haitian Creole speech recognition using a fine-tuned medium small model.",
17
  )
18
 
19
- iface.launch()
20
-
21
-
22
-
23
- # from transformers import pipeline
24
- # import gradio as gr
25
-
26
- # import torch
27
- # from transformers import AutoModelForSpeechSeq2Seq, AutoProcessor, pipeline
28
- # from datasets import load_dataset
29
-
30
-
31
- # device = "cuda:0" if torch.cuda.is_available() else "cpu"
32
- # torch_dtype = torch.float16 if torch.cuda.is_available() else torch.float32
33
-
34
- # model_id = "jsbeaudry/creole-speech-to-text"
35
-
36
- # model = AutoModelForSpeechSeq2Seq.from_pretrained(
37
- # model_id, torch_dtype=torch_dtype, low_cpu_mem_usage=True, use_safetensors=True
38
- # )
39
- # model.to(device)
40
-
41
- # processor = AutoProcessor.from_pretrained(model_id)
42
-
43
- # pipe = pipeline(
44
- # "automatic-speech-recognition",
45
- # model=model,
46
- # tokenizer=processor.tokenizer,
47
- # feature_extractor=processor.feature_extractor,
48
- # torch_dtype=torch_dtype,
49
- # device=device,
50
- # )
51
- # def transcribe(audio):
52
- # # Use the 'whisper' pipeline defined in the previous cell
53
- # text = pipe(audio)["text"]
54
- # return text
55
-
56
- # iface = gr.Interface(
57
- # fn=transcribe,
58
- # inputs=gr.Audio(type="filepath"),
59
- # outputs="text",
60
- # title="Whisper medium Creole",
61
- # description="Realtime demo for Haitian Creole speech recognition using a fine-tuned medium small model.",
62
- # )
63
-
64
- # iface.launch()
 
1
  from transformers import pipeline
2
  import gradio as gr
3
+ from unsloth import FastModel
4
+ from transformers import WhisperForConditionalGeneration
5
+ import torch
6
+
7
+
8
+ model, tokenizer = FastModel.from_pretrained(
9
+ model_name = "jsbeaudry/creole-speech-to-text",
10
+ dtype = None, # Leave as None for auto detection
11
+ load_in_4bit = False, # Set to True to do 4bit quantization which reduces memory
12
+ auto_model = WhisperForConditionalGeneration,
13
+ whisper_language = "Haitian",
14
+ whisper_task = "transcribe",
15
+ # token = "hf_...", # use one if using gated models like meta-llama/Llama-2-7b-hf
16
+ )
17
+ # Reuse the previously created pipeline object
18
+ # pipe = pipeline(model) # This line caused the error
19
+
20
+ # Initialize the pipeline correctly
21
+ pipe = pipeline(
22
+ "automatic-speech-recognition",
23
+ model=model,
24
+ tokenizer=tokenizer.tokenizer,
25
+ feature_extractor=tokenizer.feature_extractor,
26
+ processor=tokenizer,
27
+ return_language=True,
28
+ torch_dtype=torch.float16
29
+ )
30
 
 
31
 
32
  def transcribe(audio):
33
+ # Use the 'pipe' pipeline
34
  text = pipe(audio)["text"]
35
  return text
36
 
37
 
38
  iface = gr.Interface(
39
  fn=transcribe,
40
+ inputs=gr.Audio(type="filepath"),
41
  outputs="text",
42
  title="Whisper medium Creole",
43
  description="Realtime demo for Haitian Creole speech recognition using a fine-tuned medium small model.",
44
  )
45
 
46
+ iface.launch()