Views
No views yet
lamm-mit/Cephalo-Gemma-3-4b-it-04-15-2025.1import torch
2from transformers import AutoProcessor, Gemma3ForConditionalGeneration
3from transformers.image_utils import load_image
4from PIL import Image as PILImage
5
6ckpt = "lamm-mit/Cephalo-Gemma-3-4b-it-04-16-2025"
7model = Gemma3ForConditionalGeneration.from_pretrained(
8 ckpt, device_map="auto", torch_dtype=torch.bfloat16,
9)
10processor = AutoProcessor.from_pretrained(ckpt)
11
12image=PILImage.open(f'./spiderweb.png').convert("RGB")
13messages = [
14 {
15 "role": "system",
16 "content": [
17 {"type": "text", "text": "You are a materials scientist."}
18 ],
19 "role": "user",
20 "content": [
21 {"type": "image", "image": image},
22 {"type": "text", "text": "What does this image show? Provide a detailed analysis."}
23 ]
24 }
25]
26inputs = processor.apply_chat_template(
27 messages, add_generation_prompt=True, tokenize=True,
28 return_dict=True, return_tensors="pt"
29).to(model.device)
30
31input_len = inputs["input_ids"].shape[-1]
32
33generation = model.generate(**inputs, max_new_tokens=512, do_sample=False)
34generation = generation[0][input_len:]
35
36decoded = processor.decode(generation, skip_special_tokens=True)
37print(decoded)
1The image shows a spider's web, which is a structure of silk, in a red-lit, glass-enclosed cube. The web is the result of a spider's natural behavior and is a complex, three-dimensional pattern. The cube, which is a 3D-printed structure, is the environment in which the spider has created the web. The red lighting and the glass enclosure are used to highlight the web and the cube, and the lighting and the cube's material (glass) are used to show the web's structure.
2
3The spider's web is a natural and intricate design, and the cube is a man-made, 3D-printed structure. The image is a combination of the natural and the artificial, and the red lighting and the glass enclosure are used to show the web and the cube in a new and interesting way.
4
5The image is a reminder of the beauty and complexity of the natural world and the possibilities of the artificial world. The spider's web is a natural and intricate design, and the cube is a man-made, 3D-printed structure. The image is a combination of the natural and the artificial, and the red lighting and the glass enclosure are used to show the web and the cube in a new and interesting way.1@article{Buehler_Cephalo_2024_journal,
2 title={Cephalo: Multi-Modal Vision-Language Models for Bio-Inspired Materials Analysis and Design},
3 author={Markus J. Buehler},
4 journal={Advanced Functional Materials},
5 year={2024},
6 volume={34},
7 issue={49},
8 doi={2409531},
9 url={https://advanced.onlinelibrary.wiley.com/doi/full/10.1002/adfm.202409531}
10}