Luis J Camargo commited on
Commit
9ef9cfe
·
1 Parent(s): 0afb51d

gpu fixes

Browse files
Files changed (1) hide show
  1. app.py +5 -7
app.py CHANGED
@@ -1,4 +1,5 @@
1
  # app.py
 
2
  import gradio as gr
3
  import torch
4
  import numpy as np
@@ -7,7 +8,6 @@ from transformers.models.whisper.modeling_whisper import WhisperEncoder
7
  import torch.nn as nn
8
  from safetensors.torch import load_file
9
  from huggingface_hub import hf_hub_download
10
- import os
11
 
12
  # === CUSTOM MODEL CLASSES ===
13
  class WhisperEncoderOnlyConfig(WhisperConfig):
@@ -49,13 +49,12 @@ AutoModel.register(WhisperEncoderOnlyConfig, WhisperEncoderOnlyForClassification
49
  # === LOAD MODEL ===
50
  MODEL_REPO = "tachiwin/language_classification_enconly_model_2"
51
 
52
- print("Loading model...")
53
  processor = WhisperProcessor.from_pretrained(MODEL_REPO)
54
  config = WhisperEncoderOnlyConfig.from_pretrained(MODEL_REPO)
55
  model = WhisperEncoderOnlyForClassification(config)
56
 
57
  # Load weights from safetensors
58
- from huggingface_hub import hf_hub_download
59
  weights_path = hf_hub_download(repo_id=MODEL_REPO, filename="model.safetensors")
60
  state_dict = load_file(weights_path)
61
  model.load_state_dict(state_dict)
@@ -63,7 +62,6 @@ model.eval()
63
 
64
  print("Model loaded successfully!")
65
 
66
-
67
  # === INFERENCE FUNCTION ===
68
  def predict_language(audio):
69
  if audio is None:
@@ -113,9 +111,8 @@ def predict_language(audio):
113
  {f"{code_idx}": code_conf}
114
  )
115
 
116
-
117
  # === UI COMPONENTS ===
118
- with gr.Blocks(theme=gr.themes.Soft(primary_hue="indigo", secondary_hue="blue")) as demo:
119
  gr.HTML(
120
  """
121
  <div style="text-align: center; padding: 30px; background: linear-gradient(135deg, #4f46e5 0%, #3b82f6 100%); color: white; border-radius: 15px; margin-bottom: 25px; box-shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.1);">
@@ -171,4 +168,5 @@ with gr.Blocks(theme=gr.themes.Soft(primary_hue="indigo", secondary_hue="blue"))
171
  )
172
 
173
  if __name__ == "__main__":
174
- demo.launch()
 
 
1
  # app.py
2
+ import os
3
  import gradio as gr
4
  import torch
5
  import numpy as np
 
8
  import torch.nn as nn
9
  from safetensors.torch import load_file
10
  from huggingface_hub import hf_hub_download
 
11
 
12
  # === CUSTOM MODEL CLASSES ===
13
  class WhisperEncoderOnlyConfig(WhisperConfig):
 
49
  # === LOAD MODEL ===
50
  MODEL_REPO = "tachiwin/language_classification_enconly_model_2"
51
 
52
+ print("Loading model on CPU...")
53
  processor = WhisperProcessor.from_pretrained(MODEL_REPO)
54
  config = WhisperEncoderOnlyConfig.from_pretrained(MODEL_REPO)
55
  model = WhisperEncoderOnlyForClassification(config)
56
 
57
  # Load weights from safetensors
 
58
  weights_path = hf_hub_download(repo_id=MODEL_REPO, filename="model.safetensors")
59
  state_dict = load_file(weights_path)
60
  model.load_state_dict(state_dict)
 
62
 
63
  print("Model loaded successfully!")
64
 
 
65
  # === INFERENCE FUNCTION ===
66
  def predict_language(audio):
67
  if audio is None:
 
111
  {f"{code_idx}": code_conf}
112
  )
113
 
 
114
  # === UI COMPONENTS ===
115
+ with gr.Blocks() as demo:
116
  gr.HTML(
117
  """
118
  <div style="text-align: center; padding: 30px; background: linear-gradient(135deg, #4f46e5 0%, #3b82f6 100%); color: white; border-radius: 15px; margin-bottom: 25px; box-shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.1);">
 
168
  )
169
 
170
  if __name__ == "__main__":
171
+ demo.launch(theme=gr.themes.Soft(primary_hue="indigo", secondary_hue="blue"))
172
+