czd358121692 commited on
Commit
4a639bf
1 Parent(s): 105210f

Add gpu enabling

Browse files
Files changed (1) hide show
  1. app.py +8 -2
app.py CHANGED
@@ -35,8 +35,13 @@ def initialize_models():
35
  global kosmos_model, kosmos_processor, zephyr_pipe, audio_model, audio_config
36
  try:
37
  print("Loading Kosmos-2...")
38
- kosmos_model = AutoModelForVision2Seq.from_pretrained("microsoft/kosmos-2-patch14-224")
39
- kosmos_processor = AutoProcessor.from_pretrained("microsoft/kosmos-2-patch14-224")
 
 
 
 
 
40
  if torch.cuda.is_available():
41
  kosmos_model = kosmos_model.to("cuda")
42
  except Exception as e:
@@ -260,6 +265,7 @@ def get_image_examples():
260
 
261
  return examples
262
 
 
263
  def infer(image_in, api_status):
264
  if image_in is None:
265
  raise gr.Error("Please provide an image of architecture")
 
35
  global kosmos_model, kosmos_processor, zephyr_pipe, audio_model, audio_config
36
  try:
37
  print("Loading Kosmos-2...")
38
+ kosmos_model = AutoModelForVision2Seq.from_pretrained(
39
+ "microsoft/kosmos-2-patch14-224",
40
+ device_map="auto",
41
+ torch_dtype=torch.float16
42
+ )
43
+ kosmos_processor = AutoProcessor.from_pretrained(
44
+ "microsoft/kosmos-2-patch14-224")
45
  if torch.cuda.is_available():
46
  kosmos_model = kosmos_model.to("cuda")
47
  except Exception as e:
 
265
 
266
  return examples
267
 
268
+ @spaces.GPU(enable_queue=True)
269
  def infer(image_in, api_status):
270
  if image_in is None:
271
  raise gr.Error("Please provide an image of architecture")