Spaces:
Runtime error
Runtime error
Satyam-Singh
commited on
Commit
•
e643b9e
1
Parent(s):
8562d5d
Create gemma_model.py
Browse files- gemma_model.py +10 -0
gemma_model.py
ADDED
@@ -0,0 +1,10 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
from transformers import AutoModelForCausalLM, AutoTokenizer
|
2 |
+
|
3 |
+
model_name = "google/gemma-2b-it"
|
4 |
+
tokenizer = AutoTokenizer.from_pretrained(model_name)
|
5 |
+
model = AutoModelForCausalLM.from_pretrained(model_name)
|
6 |
+
|
7 |
+
def generate_text(prompt):
|
8 |
+
inputs = tokenizer.encode(prompt, return_tensors="pt")
|
9 |
+
outputs = model.generate(inputs, max_length=50)
|
10 |
+
return tokenizer.decode(outputs[0], skip_special_tokens=True)
|