sagar007 commited on
Commit
d45486e
·
verified ·
1 Parent(s): 893dc50

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +24 -2
app.py CHANGED
@@ -1,9 +1,12 @@
 
 
 
 
1
  import torch
2
  import librosa
3
  from transformers import pipeline, WhisperProcessor, WhisperForConditionalGeneration, AutoModelForCausalLM, AutoProcessor
4
  from gtts import gTTS
5
  import gradio as gr
6
- import spaces
7
  from PIL import Image
8
  import os
9
  import io
@@ -37,6 +40,26 @@ def load_whisper():
37
  print(f"Error loading Whisper model: {e}")
38
  return None, None
39
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
40
  # Load sarvam-2b for text generation within a GPU-decorated function
41
  @spaces.GPU
42
  def load_sarvam():
@@ -269,7 +292,6 @@ custom_suggestions = """
269
  </div>
270
  </div>
271
  """
272
-
273
  # Create Gradio interface
274
  with gr.Blocks(css=custom_css, theme=gr.themes.Base().set(
275
  body_background_fill="#0b0f19",
 
1
+ # Import spaces first to avoid CUDA initialization issues
2
+ import spaces
3
+
4
+ # Then import other libraries
5
  import torch
6
  import librosa
7
  from transformers import pipeline, WhisperProcessor, WhisperForConditionalGeneration, AutoModelForCausalLM, AutoProcessor
8
  from gtts import gTTS
9
  import gradio as gr
 
10
  from PIL import Image
11
  import os
12
  import io
 
40
  print(f"Error loading Whisper model: {e}")
41
  return None, None
42
 
43
+ # Load sarvam-2b for text generation within a GPU-decorated function
44
+ @spaces.GPU
45
+ def load_sarvam():
46
+ return load_pipeline('sarvamai/sarvam-2b-v0.5')
47
+
48
+ # Load Phi-3.5-vision-instruct model
49
+ @spaces.GPU
50
+ def load_vision_model():
51
+ try:
52
+ model_id = "microsoft/Phi-3.5-vision-instruct"
53
+ model = AutoModelForCausalLM.from_pretrained(
54
+ model_id, trust_remote_code=True, torch_dtype=torch.float16, use_flash_attention_2=False
55
+ )
56
+ processor = AutoProcessor.from_pretrained(model_id, trust_remote_code=True, num_crops=16)
57
+ return model, processor
58
+ except Exception as e:
59
+ print(f"Error loading vision model: {e}")
60
+ return None, None
61
+
62
+
63
  # Load sarvam-2b for text generation within a GPU-decorated function
64
  @spaces.GPU
65
  def load_sarvam():
 
292
  </div>
293
  </div>
294
  """
 
295
  # Create Gradio interface
296
  with gr.Blocks(css=custom_css, theme=gr.themes.Base().set(
297
  body_background_fill="#0b0f19",