Update app.py
Browse files
app.py
CHANGED
@@ -1,3 +1,4 @@
|
|
|
|
1 |
import gradio as gr
|
2 |
import torch
|
3 |
from PIL import Image
|
@@ -21,16 +22,18 @@ model.gradient_checkpointing_enable()
|
|
21 |
|
22 |
processor = AutoProcessor.from_pretrained(model_id)
|
23 |
|
24 |
-
|
25 |
-
print("กำลังโหลด tokenizer...")
|
26 |
-
base_model, tokenizer = FastVisionModel.from_pretrained(
|
27 |
-
"unsloth/Llama-3.2-11B-Vision-Instruct",
|
28 |
-
# load_in_4bit = True,
|
29 |
-
use_gradient_checkpointing = "unsloth",
|
30 |
-
)
|
31 |
-
|
32 |
# Function to process the image and generate the description
|
33 |
def generate_description(image: Image.Image, instruction: str):
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
34 |
image = image.convert("RGB")
|
35 |
# image = Resize((224, 224))(image)
|
36 |
|
|
|
1 |
+
import spaces
|
2 |
import gradio as gr
|
3 |
import torch
|
4 |
from PIL import Image
|
|
|
22 |
|
23 |
processor = AutoProcessor.from_pretrained(model_id)
|
24 |
|
25 |
+
@spaces.GPU(duration=120)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
26 |
# Function to process the image and generate the description
|
27 |
def generate_description(image: Image.Image, instruction: str):
|
28 |
+
|
29 |
+
FastVisionModel.for_inference(model)
|
30 |
+
print("กำลังโหลด tokenizer...")
|
31 |
+
base_model, tokenizer = FastVisionModel.from_pretrained(
|
32 |
+
"unsloth/Llama-3.2-11B-Vision-Instruct",
|
33 |
+
# load_in_4bit = True,
|
34 |
+
use_gradient_checkpointing = "unsloth",
|
35 |
+
)
|
36 |
+
|
37 |
image = image.convert("RGB")
|
38 |
# image = Resize((224, 224))(image)
|
39 |
|