Spaces:
Sleeping
Sleeping
Commit
·
5426c44
1
Parent(s):
0407a53
Updated with OCR model and Gradio integration
Browse files
app.py
CHANGED
@@ -1,5 +1,6 @@
|
|
1 |
import gradio as gr
|
2 |
from transformers import AutoTokenizer, AutoProcessor, AutoModel
|
|
|
3 |
|
4 |
repo_id = "OpenGVLab/InternVL2-1B"
|
5 |
|
@@ -8,9 +9,13 @@ tokenizer = AutoTokenizer.from_pretrained(repo_id, trust_remote_code=True)
|
|
8 |
processor = AutoProcessor.from_pretrained(repo_id, trust_remote_code=True)
|
9 |
model = AutoModel.from_pretrained(repo_id, trust_remote_code=True)
|
10 |
|
|
|
|
|
|
|
|
|
11 |
def analyze_image(image):
|
12 |
img = image.convert("RGB")
|
13 |
-
inputs = processor(images=img, text="describe this image", return_tensors="pt")
|
14 |
outputs = model.generate(**inputs)
|
15 |
return tokenizer.decode(outputs[0], skip_special_tokens=True)
|
16 |
|
|
|
1 |
import gradio as gr
|
2 |
from transformers import AutoTokenizer, AutoProcessor, AutoModel
|
3 |
+
import torch
|
4 |
|
5 |
repo_id = "OpenGVLab/InternVL2-1B"
|
6 |
|
|
|
9 |
processor = AutoProcessor.from_pretrained(repo_id, trust_remote_code=True)
|
10 |
model = AutoModel.from_pretrained(repo_id, trust_remote_code=True)
|
11 |
|
12 |
+
# Move model to the appropriate device
|
13 |
+
device = torch.device("cuda" if torch.cuda.is_available() else "cpu")
|
14 |
+
model.to(device)
|
15 |
+
|
16 |
def analyze_image(image):
|
17 |
img = image.convert("RGB")
|
18 |
+
inputs = processor(images=img, text="describe this image", return_tensors="pt").to(device)
|
19 |
outputs = model.generate(**inputs)
|
20 |
return tokenizer.decode(outputs[0], skip_special_tokens=True)
|
21 |
|