liltom-eth
commited on
Commit
·
11a6467
1
Parent(s):
dc6df17
Upload code/inference.py with huggingface_hub
Browse files- code/inference.py +19 -11
code/inference.py
CHANGED
@@ -45,17 +45,25 @@ def predict_fn(data, model_and_tokenizer):
|
|
45 |
temperature = data.pop("temperature", 0.2)
|
46 |
conv_mode = data.pop("conv_mode", "llava_v1")
|
47 |
|
48 |
-
|
49 |
-
|
50 |
-
|
51 |
-
|
52 |
-
|
53 |
-
|
54 |
-
|
55 |
-
|
56 |
-
|
57 |
-
|
58 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
59 |
|
60 |
if image_file.startswith("http") or image_file.startswith("https"):
|
61 |
response = requests.get(image_file)
|
|
|
45 |
temperature = data.pop("temperature", 0.2)
|
46 |
conv_mode = data.pop("conv_mode", "llava_v1")
|
47 |
|
48 |
+
if conv_mode == "raw":
|
49 |
+
# use raw_prompt as prompt
|
50 |
+
prompt = raw_prompt
|
51 |
+
stop_str = "###"
|
52 |
+
else:
|
53 |
+
conv = conv_templates[conv_mode].copy()
|
54 |
+
roles = conv.roles
|
55 |
+
inp = f"{roles[0]}: {raw_prompt}"
|
56 |
+
inp = (
|
57 |
+
DEFAULT_IM_START_TOKEN
|
58 |
+
+ DEFAULT_IMAGE_TOKEN
|
59 |
+
+ DEFAULT_IM_END_TOKEN
|
60 |
+
+ "\n"
|
61 |
+
+ inp
|
62 |
+
)
|
63 |
+
conv.append_message(conv.roles[0], inp)
|
64 |
+
conv.append_message(conv.roles[1], None)
|
65 |
+
prompt = conv.get_prompt()
|
66 |
+
stop_str = conv.sep if conv.sep_style != SeparatorStyle.TWO else conv.sep2
|
67 |
|
68 |
if image_file.startswith("http") or image_file.startswith("https"):
|
69 |
response = requests.get(image_file)
|