Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -1,6 +1,7 @@
|
|
1 |
import gradio as gr
|
2 |
from transformers import TrOCRProcessor, VisionEncoderDecoderModel
|
3 |
import torch
|
|
|
4 |
|
5 |
# Dictionary of model names and their corresponding HuggingFace model IDs
|
6 |
MODEL_OPTIONS = {
|
@@ -31,21 +32,20 @@ def load_model(model_name):
|
|
31 |
current_model = VisionEncoderDecoderModel.from_pretrained(model_id)
|
32 |
current_model_name = model_name
|
33 |
|
34 |
-
# Move model to GPU
|
35 |
-
|
36 |
-
current_model = current_model.to('cuda')
|
37 |
|
38 |
return current_processor, current_model
|
39 |
|
|
|
40 |
def process_image(image, model_name):
|
41 |
processor, model = load_model(model_name)
|
42 |
|
43 |
# Prepare image
|
44 |
pixel_values = processor(image, return_tensors="pt").pixel_values
|
45 |
|
46 |
-
# Move input to GPU
|
47 |
-
|
48 |
-
pixel_values = pixel_values.to('cuda')
|
49 |
|
50 |
# Generate (no beam search)
|
51 |
with torch.no_grad():
|
|
|
1 |
import gradio as gr
|
2 |
from transformers import TrOCRProcessor, VisionEncoderDecoderModel
|
3 |
import torch
|
4 |
+
import spaces
|
5 |
|
6 |
# Dictionary of model names and their corresponding HuggingFace model IDs
|
7 |
MODEL_OPTIONS = {
|
|
|
32 |
current_model = VisionEncoderDecoderModel.from_pretrained(model_id)
|
33 |
current_model_name = model_name
|
34 |
|
35 |
+
# Move model to GPU
|
36 |
+
current_model = current_model.to('cuda')
|
|
|
37 |
|
38 |
return current_processor, current_model
|
39 |
|
40 |
+
@spaces.GPU
|
41 |
def process_image(image, model_name):
|
42 |
processor, model = load_model(model_name)
|
43 |
|
44 |
# Prepare image
|
45 |
pixel_values = processor(image, return_tensors="pt").pixel_values
|
46 |
|
47 |
+
# Move input to GPU
|
48 |
+
pixel_values = pixel_values.to('cuda')
|
|
|
49 |
|
50 |
# Generate (no beam search)
|
51 |
with torch.no_grad():
|