Spaces:
Running
on
Zero
Running
on
Zero
feat: 试了一下 internVL2 这个模型还可以
Browse files
app.py
CHANGED
@@ -2,13 +2,23 @@ import torch
|
|
2 |
import gradio as gr
|
3 |
from transformers import AutoModel, pipeline, AutoTokenizer
|
4 |
|
5 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
6 |
|
7 |
|
8 |
def predict(input_img, questions):
|
9 |
try:
|
10 |
predictions = inference(question=questions, image=input_img)
|
11 |
-
return str(predictions
|
12 |
except Exception as e:
|
13 |
# 捕获异常,并将错误信息转换为字符串
|
14 |
error_message = str(e)
|
@@ -19,9 +29,7 @@ def predict(input_img, questions):
|
|
19 |
gradio_app = gr.Interface(
|
20 |
predict,
|
21 |
inputs=[
|
22 |
-
gr.Image(
|
23 |
-
label="Select A Image", sources=["upload", "webcam"], type="pil"
|
24 |
-
),
|
25 |
"text",
|
26 |
],
|
27 |
outputs="text",
|
|
|
2 |
import gradio as gr
|
3 |
from transformers import AutoModel, pipeline, AutoTokenizer
|
4 |
|
5 |
+
path = "radna/Triton-InternVL2-2B"
|
6 |
+
model = (
|
7 |
+
AutoModel.from_pretrained(
|
8 |
+
path, torch_dtype=torch.bfloat16, low_cpu_mem_usage=True, trust_remote_code=True
|
9 |
+
)
|
10 |
+
.eval()
|
11 |
+
.cuda()
|
12 |
+
)
|
13 |
+
|
14 |
+
tokenizer = AutoTokenizer.from_pretrained(path, trust_remote_code=True)
|
15 |
+
inference = pipeline(task="visual-question-answering", model=model, tokenizer=tokenizer)
|
16 |
|
17 |
|
18 |
def predict(input_img, questions):
|
19 |
try:
|
20 |
predictions = inference(question=questions, image=input_img)
|
21 |
+
return str(predictions)
|
22 |
except Exception as e:
|
23 |
# 捕获异常,并将错误信息转换为字符串
|
24 |
error_message = str(e)
|
|
|
29 |
gradio_app = gr.Interface(
|
30 |
predict,
|
31 |
inputs=[
|
32 |
+
gr.Image(label="Select A Image", sources=["upload", "webcam"], type="pil"),
|
|
|
|
|
33 |
"text",
|
34 |
],
|
35 |
outputs="text",
|