Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
@@ -11,18 +11,24 @@ import subprocess
|
|
11 |
subprocess.run('pip install --upgrade transformers', shell=True)
|
12 |
subprocess.run('pip install accelerate', shell=True)
|
13 |
|
14 |
-
from transformers import
|
15 |
|
16 |
# Model and tokenizer initialization
|
17 |
model_name = "Qwen/QVQ-72B-Preview"
|
18 |
|
|
|
|
|
|
|
|
|
|
|
19 |
tokenizer = AutoTokenizer.from_pretrained(
|
20 |
model_name,
|
21 |
trust_remote_code=True
|
22 |
)
|
23 |
|
24 |
-
model =
|
25 |
model_name,
|
|
|
26 |
trust_remote_code=True,
|
27 |
device_map="auto",
|
28 |
torch_dtype=torch.float16
|
@@ -42,14 +48,30 @@ def process_image(image, text_input=None):
|
|
42 |
# Convert image to PIL format
|
43 |
image = Image.fromarray(image).convert("RGB")
|
44 |
|
45 |
-
# Prepare
|
46 |
if text_input:
|
47 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
48 |
else:
|
49 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
50 |
|
51 |
# Generate response
|
52 |
-
response = model.chat(tokenizer,
|
53 |
|
54 |
return response
|
55 |
except Exception as e:
|
|
|
11 |
subprocess.run('pip install --upgrade transformers', shell=True)
|
12 |
subprocess.run('pip install accelerate', shell=True)
|
13 |
|
14 |
+
from transformers import AutoConfig, PreTrainedModel, AutoTokenizer
|
15 |
|
16 |
# Model and tokenizer initialization
|
17 |
model_name = "Qwen/QVQ-72B-Preview"
|
18 |
|
19 |
+
config = AutoConfig.from_pretrained(
|
20 |
+
model_name,
|
21 |
+
trust_remote_code=True
|
22 |
+
)
|
23 |
+
|
24 |
tokenizer = AutoTokenizer.from_pretrained(
|
25 |
model_name,
|
26 |
trust_remote_code=True
|
27 |
)
|
28 |
|
29 |
+
model = PreTrainedModel.from_pretrained(
|
30 |
model_name,
|
31 |
+
config=config,
|
32 |
trust_remote_code=True,
|
33 |
device_map="auto",
|
34 |
torch_dtype=torch.float16
|
|
|
48 |
# Convert image to PIL format
|
49 |
image = Image.fromarray(image).convert("RGB")
|
50 |
|
51 |
+
# Prepare inputs
|
52 |
if text_input:
|
53 |
+
messages = [
|
54 |
+
{
|
55 |
+
"role": "user",
|
56 |
+
"content": [
|
57 |
+
{"image": image},
|
58 |
+
{"text": text_input}
|
59 |
+
]
|
60 |
+
}
|
61 |
+
]
|
62 |
else:
|
63 |
+
messages = [
|
64 |
+
{
|
65 |
+
"role": "user",
|
66 |
+
"content": [
|
67 |
+
{"image": image},
|
68 |
+
{"text": "Please describe this image in detail."}
|
69 |
+
]
|
70 |
+
}
|
71 |
+
]
|
72 |
|
73 |
# Generate response
|
74 |
+
response = model.chat(tokenizer, messages=messages)
|
75 |
|
76 |
return response
|
77 |
except Exception as e:
|