Spaces:
Sleeping
Sleeping
Update app.py
Browse filesTry to deploy InternVL3
app.py
CHANGED
@@ -1,7 +1,28 @@
|
|
1 |
import gradio as gr
|
|
|
|
|
|
|
2 |
|
3 |
-
|
4 |
-
|
|
|
|
|
5 |
|
6 |
-
|
7 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
import gradio as gr
|
2 |
+
from transformers import AutoProcessor, AutoModelForVision2Seq
|
3 |
+
from PIL import Image
|
4 |
+
import torch
|
5 |
|
6 |
+
# 模型和处理器(InternVL3)
|
7 |
+
model_id = "OpenGVLab/InternVL3-14B"
|
8 |
+
processor = AutoProcessor.from_pretrained(model_id)
|
9 |
+
model = AutoModelForVision2Seq.from_pretrained(model_id, torch_dtype=torch.float16, device_map="auto")
|
10 |
|
11 |
+
# 推理函数
|
12 |
+
def infer(image, prompt):
|
13 |
+
inputs = processor(prompt=prompt, images=image, return_tensors="pt").to("cuda")
|
14 |
+
output = model.generate(**inputs, max_new_tokens=256)
|
15 |
+
response = processor.decode(output[0], skip_special_tokens=True)
|
16 |
+
return response
|
17 |
+
|
18 |
+
# Gradio UI
|
19 |
+
gr.Interface(
|
20 |
+
fn=infer,
|
21 |
+
inputs=[
|
22 |
+
gr.Image(type="pil", label="Upload Image"),
|
23 |
+
gr.Textbox(label="Your Prompt", placeholder="Ask a question about the image...")
|
24 |
+
],
|
25 |
+
outputs="text",
|
26 |
+
title="InternVL3-14B Visual Chat",
|
27 |
+
description="Upload an image and enter a prompt. InternVL3-14B will answer accordingly."
|
28 |
+
).launch()
|