hmarzan commited on
Commit
421d199
1 Parent(s): 4954695

Fixes to Gradio App. Calling half when using CUDA devices.

Browse files
Files changed (1) hide show
  1. app.py +7 -3
app.py CHANGED
@@ -25,10 +25,12 @@ model = DonutModel.from_pretrained(
25
  ignore_mismatched_sizes=True,
26
  )
27
 
28
- device = "cuda" if torch.cuda.is_available() else "cpu"
 
 
 
 
29
 
30
- model = model.to(device)
31
- model.eval()
32
 
33
  task_name = "matricula"
34
  task_prompt = f"<s_{task_name}>"
@@ -38,6 +40,8 @@ def predict_matricula(model, task_name, image):
38
  image = image.resize(size=(1280, 960),
39
  resample=Image.Resampling.NEAREST)
40
 
 
 
41
  result = model.inference(image=image, prompt=f"<s_{task_name}>")["predictions"][0]
42
  return result
43
 
 
25
  ignore_mismatched_sizes=True,
26
  )
27
 
28
+ #device = "cuda" if torch.cuda.is_available() else "cpu"
29
+
30
+ if has_cuda:
31
+ model.half()
32
+ model = model.to("cuda")
33
 
 
 
34
 
35
  task_name = "matricula"
36
  task_prompt = f"<s_{task_name}>"
 
40
  image = image.resize(size=(1280, 960),
41
  resample=Image.Resampling.NEAREST)
42
 
43
+ model.eval()
44
+
45
  result = model.inference(image=image, prompt=f"<s_{task_name}>")["predictions"][0]
46
  return result
47