BeastGokul commited on
Commit
563c650
·
verified ·
1 Parent(s): 887e65f

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +10 -3
app.py CHANGED
@@ -4,7 +4,7 @@ from transformers import AutoModel, AutoTokenizer
4
  import gradio as gr
5
  from PIL import Image
6
  import traceback
7
- import numpy
8
  # Argument Parsing
9
  parser = argparse.ArgumentParser(description='demo')
10
  parser.add_argument('--device', type=str, default='cuda', help='cuda or mps')
@@ -14,11 +14,18 @@ assert device in ['cuda', 'mps']
14
 
15
  # Load model and tokenizer manually
16
  model_path = 'openbmb/MiniCPM-Llama3-V-2_5'
17
- model = AutoModel.from_pretrained(model_path, trust_remote_code=True, torch_dtype=torch.float16).to(device=device)
 
 
 
 
 
 
 
18
  tokenizer = AutoTokenizer.from_pretrained(model_path, trust_remote_code=True)
19
  model.eval()
20
 
21
- ERROR_MSG = "Error, please retry"
22
  model_name = 'MiniCPM-Llama3-V 2.5'
23
 
24
  def chat(image, msgs, sampling=True, temperature=0.7, stream=False):
 
4
  import gradio as gr
5
  from PIL import Image
6
  import traceback
7
+ import spaces
8
  # Argument Parsing
9
  parser = argparse.ArgumentParser(description='demo')
10
  parser.add_argument('--device', type=str, default='cuda', help='cuda or mps')
 
14
 
15
  # Load model and tokenizer manually
16
  model_path = 'openbmb/MiniCPM-Llama3-V-2_5'
17
+ if 'int4' in model_path:
18
+ if device == 'mps':
19
+ print('Error: running int4 model with bitsandbytes on Mac is not supported right now.')
20
+ exit()
21
+ model = AutoModel.from_pretrained(model_path, trust_remote_code=True)
22
+ else:
23
+ model = AutoModel.from_pretrained(model_path, trust_remote_code=True).to(dtype=torch.float16)
24
+ model = model.to(device=device)
25
  tokenizer = AutoTokenizer.from_pretrained(model_path, trust_remote_code=True)
26
  model.eval()
27
 
28
+
29
  model_name = 'MiniCPM-Llama3-V 2.5'
30
 
31
  def chat(image, msgs, sampling=True, temperature=0.7, stream=False):