jonathanjordan21 commited on
Commit
8f3695b
1 Parent(s): fba420b

Add device variable in JSON parser

Browse files
Files changed (1) hide show
  1. README.md +3 -1
README.md CHANGED
@@ -53,6 +53,9 @@ import re
53
  import torch
54
 
55
  def get_komposisi(image_path, image=None):
 
 
 
56
  image = Image.open(image_path).convert('RGB') if image== None else image.convert('RGB')
57
 
58
  task_prompt = "<s_kmpsi>"
@@ -72,7 +75,6 @@ def get_komposisi(image_path, image=None):
72
  return_dict_in_generate=True,
73
  )
74
 
75
-
76
  sequence1 = processor.batch_decode(outputs.sequences)[0]
77
  sequence2 = sequence1.replace(processor.tokenizer.eos_token, "").replace(processor.tokenizer.pad_token, "")
78
  sequence3 = re.sub(r"<.*?>", "", sequence2, count=1).strip() # remove first task start token
 
53
  import torch
54
 
55
  def get_komposisi(image_path, image=None):
56
+
57
+ device = "cuda" if torch.cuda.is_available() else "cpu"
58
+
59
  image = Image.open(image_path).convert('RGB') if image== None else image.convert('RGB')
60
 
61
  task_prompt = "<s_kmpsi>"
 
75
  return_dict_in_generate=True,
76
  )
77
 
 
78
  sequence1 = processor.batch_decode(outputs.sequences)[0]
79
  sequence2 = sequence1.replace(processor.tokenizer.eos_token, "").replace(processor.tokenizer.pad_token, "")
80
  sequence3 = re.sub(r"<.*?>", "", sequence2, count=1).strip() # remove first task start token