Upload stepfun-ai_GELab-Zero-4B-preview_1.py with huggingface_hub
Browse files
stepfun-ai_GELab-Zero-4B-preview_1.py
CHANGED
|
@@ -25,6 +25,25 @@ try:
|
|
| 25 |
|
| 26 |
processor = AutoProcessor.from_pretrained("stepfun-ai/GELab-Zero-4B-preview")
|
| 27 |
model = AutoModelForVision2Seq.from_pretrained("stepfun-ai/GELab-Zero-4B-preview")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 28 |
with open('stepfun-ai_GELab-Zero-4B-preview_1.txt', 'w', encoding='utf-8') as f:
|
| 29 |
f.write('Everything was good in stepfun-ai_GELab-Zero-4B-preview_1.txt')
|
| 30 |
except Exception as e:
|
|
@@ -44,6 +63,25 @@ from transformers import AutoProcessor, AutoModelForVision2Seq
|
|
| 44 |
|
| 45 |
processor = AutoProcessor.from_pretrained("stepfun-ai/GELab-Zero-4B-preview")
|
| 46 |
model = AutoModelForVision2Seq.from_pretrained("stepfun-ai/GELab-Zero-4B-preview")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 47 |
```
|
| 48 |
|
| 49 |
ERROR:
|
|
|
|
| 25 |
|
| 26 |
processor = AutoProcessor.from_pretrained("stepfun-ai/GELab-Zero-4B-preview")
|
| 27 |
model = AutoModelForVision2Seq.from_pretrained("stepfun-ai/GELab-Zero-4B-preview")
|
| 28 |
+
messages = [
|
| 29 |
+
{
|
| 30 |
+
"role": "user",
|
| 31 |
+
"content": [
|
| 32 |
+
{"type": "image", "url": "https://huggingface.co/datasets/huggingface/documentation-images/resolve/main/p-blog/candy.JPG"},
|
| 33 |
+
{"type": "text", "text": "What animal is on the candy?"}
|
| 34 |
+
]
|
| 35 |
+
},
|
| 36 |
+
]
|
| 37 |
+
inputs = processor.apply_chat_template(
|
| 38 |
+
messages,
|
| 39 |
+
add_generation_prompt=True,
|
| 40 |
+
tokenize=True,
|
| 41 |
+
return_dict=True,
|
| 42 |
+
return_tensors="pt",
|
| 43 |
+
).to(model.device)
|
| 44 |
+
|
| 45 |
+
outputs = model.generate(**inputs, max_new_tokens=40)
|
| 46 |
+
print(processor.decode(outputs[0][inputs["input_ids"].shape[-1]:]))
|
| 47 |
with open('stepfun-ai_GELab-Zero-4B-preview_1.txt', 'w', encoding='utf-8') as f:
|
| 48 |
f.write('Everything was good in stepfun-ai_GELab-Zero-4B-preview_1.txt')
|
| 49 |
except Exception as e:
|
|
|
|
| 63 |
|
| 64 |
processor = AutoProcessor.from_pretrained("stepfun-ai/GELab-Zero-4B-preview")
|
| 65 |
model = AutoModelForVision2Seq.from_pretrained("stepfun-ai/GELab-Zero-4B-preview")
|
| 66 |
+
messages = [
|
| 67 |
+
{
|
| 68 |
+
"role": "user",
|
| 69 |
+
"content": [
|
| 70 |
+
{"type": "image", "url": "https://huggingface.co/datasets/huggingface/documentation-images/resolve/main/p-blog/candy.JPG"},
|
| 71 |
+
{"type": "text", "text": "What animal is on the candy?"}
|
| 72 |
+
]
|
| 73 |
+
},
|
| 74 |
+
]
|
| 75 |
+
inputs = processor.apply_chat_template(
|
| 76 |
+
messages,
|
| 77 |
+
add_generation_prompt=True,
|
| 78 |
+
tokenize=True,
|
| 79 |
+
return_dict=True,
|
| 80 |
+
return_tensors="pt",
|
| 81 |
+
).to(model.device)
|
| 82 |
+
|
| 83 |
+
outputs = model.generate(**inputs, max_new_tokens=40)
|
| 84 |
+
print(processor.decode(outputs[0][inputs["input_ids"].shape[-1]:]))
|
| 85 |
```
|
| 86 |
|
| 87 |
ERROR:
|