ariG23498 HF Staff commited on
Commit
0cac19f
·
verified ·
1 Parent(s): 0e97d22

Upload google_gemma-3-27b-it_1.py with huggingface_hub

Browse files
Files changed (1) hide show
  1. google_gemma-3-27b-it_1.py +10 -30
google_gemma-3-27b-it_1.py CHANGED
@@ -11,11 +11,10 @@
11
  # ///
12
 
13
  try:
14
- # Load model directly
15
- from transformers import AutoProcessor, AutoModelForImageTextToText
16
 
17
- processor = AutoProcessor.from_pretrained("google/gemma-3-27b-it")
18
- model = AutoModelForImageTextToText.from_pretrained("google/gemma-3-27b-it")
19
  messages = [
20
  {
21
  "role": "user",
@@ -25,16 +24,7 @@ try:
25
  ]
26
  },
27
  ]
28
- inputs = processor.apply_chat_template(
29
- messages,
30
- add_generation_prompt=True,
31
- tokenize=True,
32
- return_dict=True,
33
- return_tensors="pt",
34
- ).to(model.device)
35
-
36
- outputs = model.generate(**inputs, max_new_tokens=40)
37
- print(processor.decode(outputs[0][inputs["input_ids"].shape[-1]:]))
38
  with open('google_gemma-3-27b-it_1.txt', 'w', encoding='utf-8') as f:
39
  f.write('Everything was good in google_gemma-3-27b-it_1.txt')
40
  except Exception as e:
@@ -48,13 +38,11 @@ except Exception as e:
48
 
49
  with open('google_gemma-3-27b-it_1.txt', 'a', encoding='utf-8') as f:
50
  import traceback
51
- f.write('''
52
- ```CODE:
53
- # Load model directly
54
- from transformers import AutoProcessor, AutoModelForImageTextToText
55
 
56
- processor = AutoProcessor.from_pretrained("google/gemma-3-27b-it")
57
- model = AutoModelForImageTextToText.from_pretrained("google/gemma-3-27b-it")
58
  messages = [
59
  {
60
  "role": "user",
@@ -64,17 +52,9 @@ messages = [
64
  ]
65
  },
66
  ]
67
- inputs = processor.apply_chat_template(
68
- messages,
69
- add_generation_prompt=True,
70
- tokenize=True,
71
- return_dict=True,
72
- return_tensors="pt",
73
- ).to(model.device)
74
-
75
- outputs = model.generate(**inputs, max_new_tokens=40)
76
- print(processor.decode(outputs[0][inputs["input_ids"].shape[-1]:]))
77
  ```
 
78
  ERROR:
79
  ''')
80
  traceback.print_exc(file=f)
 
11
  # ///
12
 
13
  try:
14
+ # Use a pipeline as a high-level helper
15
+ from transformers import pipeline
16
 
17
+ pipe = pipeline("image-text-to-text", model="google/gemma-3-27b-it")
 
18
  messages = [
19
  {
20
  "role": "user",
 
24
  ]
25
  },
26
  ]
27
+ pipe(text=messages)
 
 
 
 
 
 
 
 
 
28
  with open('google_gemma-3-27b-it_1.txt', 'w', encoding='utf-8') as f:
29
  f.write('Everything was good in google_gemma-3-27b-it_1.txt')
30
  except Exception as e:
 
38
 
39
  with open('google_gemma-3-27b-it_1.txt', 'a', encoding='utf-8') as f:
40
  import traceback
41
+ f.write('''```CODE:
42
+ # Use a pipeline as a high-level helper
43
+ from transformers import pipeline
 
44
 
45
+ pipe = pipeline("image-text-to-text", model="google/gemma-3-27b-it")
 
46
  messages = [
47
  {
48
  "role": "user",
 
52
  ]
53
  },
54
  ]
55
+ pipe(text=messages)
 
 
 
 
 
 
 
 
 
56
  ```
57
+
58
  ERROR:
59
  ''')
60
  traceback.print_exc(file=f)