Spaces:
Running
on
Zero
Running
on
Zero
wjbmattingly
commited on
Commit
•
0456d74
1
Parent(s):
65a0357
Update app.py
Browse files
app.py
CHANGED
@@ -1,7 +1,6 @@
|
|
1 |
import gradio as gr
|
2 |
from transformers import TrOCRProcessor, VisionEncoderDecoderModel
|
3 |
import torch
|
4 |
-
import spaces
|
5 |
import subprocess
|
6 |
import json
|
7 |
from PIL import Image, ImageDraw
|
@@ -38,11 +37,11 @@ def load_model(model_name):
|
|
38 |
current_model_name = model_name
|
39 |
|
40 |
# Move model to GPU
|
41 |
-
current_model = current_model.to('cuda')
|
42 |
|
43 |
return current_processor, current_model
|
44 |
|
45 |
-
|
46 |
def process_image(image, model_name):
|
47 |
# Save the uploaded image to a temporary file
|
48 |
with tempfile.NamedTemporaryFile(suffix=".jpg", delete=False) as temp_img:
|
@@ -72,7 +71,7 @@ def process_image(image, model_name):
|
|
72 |
|
73 |
# Prepare image for TrOCR
|
74 |
pixel_values = processor(line_image, return_tensors="pt").pixel_values
|
75 |
-
pixel_values = pixel_values.to('cuda')
|
76 |
|
77 |
# Generate (no beam search)
|
78 |
with torch.no_grad():
|
|
|
1 |
import gradio as gr
|
2 |
from transformers import TrOCRProcessor, VisionEncoderDecoderModel
|
3 |
import torch
|
|
|
4 |
import subprocess
|
5 |
import json
|
6 |
from PIL import Image, ImageDraw
|
|
|
37 |
current_model_name = model_name
|
38 |
|
39 |
# Move model to GPU
|
40 |
+
# current_model = current_model.to('cuda')
|
41 |
|
42 |
return current_processor, current_model
|
43 |
|
44 |
+
|
45 |
def process_image(image, model_name):
|
46 |
# Save the uploaded image to a temporary file
|
47 |
with tempfile.NamedTemporaryFile(suffix=".jpg", delete=False) as temp_img:
|
|
|
71 |
|
72 |
# Prepare image for TrOCR
|
73 |
pixel_values = processor(line_image, return_tensors="pt").pixel_values
|
74 |
+
# pixel_values = pixel_values.to('cuda')
|
75 |
|
76 |
# Generate (no beam search)
|
77 |
with torch.no_grad():
|