Spaces:
Runtime error
Runtime error
jonathanjordan21
commited on
Commit
•
f130d9b
1
Parent(s):
4d531d5
Code change : Load model before prediction for faster inference
Browse files
app.py
CHANGED
@@ -6,18 +6,17 @@ import torch
|
|
6 |
|
7 |
from transformers import DonutProcessor, VisionEncoderDecoderModel
|
8 |
|
9 |
-
|
10 |
-
|
11 |
-
# Check GPU
|
12 |
-
device = "cuda" if torch.cuda.is_available() else "cpu"
|
13 |
|
14 |
-
|
15 |
-
|
16 |
|
17 |
-
|
18 |
-
|
19 |
|
20 |
|
|
|
21 |
# Define Json Parser
|
22 |
def get_komposisi(image_path, image=None):
|
23 |
image = Image.open(image_path).convert('RGB') if image== None else image.convert('RGB')
|
@@ -50,9 +49,6 @@ def predict(inp):
|
|
50 |
return out
|
51 |
|
52 |
|
53 |
-
def upload_file(files):
|
54 |
-
file_paths = [file.name for file in files]
|
55 |
-
return file_paths
|
56 |
|
57 |
gr.Interface(fn=predict,
|
58 |
inputs=gr.Image(type="pil"),
|
|
|
6 |
|
7 |
from transformers import DonutProcessor, VisionEncoderDecoderModel
|
8 |
|
9 |
+
# Check GPU
|
10 |
+
device = "cuda" if torch.cuda.is_available() else "cpu"
|
|
|
|
|
11 |
|
12 |
+
# Load processor
|
13 |
+
processor = DonutProcessor.from_pretrained("jonathanjordan21/donut_fine_tuning_food_composition_id")
|
14 |
|
15 |
+
# Load model
|
16 |
+
model = VisionEncoderDecoderModel.from_pretrained("jonathanjordan21/donut_fine_tuning_food_composition_id")
|
17 |
|
18 |
|
19 |
+
def predict(inp):
|
20 |
# Define Json Parser
|
21 |
def get_komposisi(image_path, image=None):
|
22 |
image = Image.open(image_path).convert('RGB') if image== None else image.convert('RGB')
|
|
|
49 |
return out
|
50 |
|
51 |
|
|
|
|
|
|
|
52 |
|
53 |
gr.Interface(fn=predict,
|
54 |
inputs=gr.Image(type="pil"),
|