acecalisto3 commited on
Commit
877de4c
1 Parent(s): 0d3f166

Create utils.py

Browse files
Files changed (1) hide show
  1. gemmacode/utils.py +19 -0
gemmacode/utils.py ADDED
@@ -0,0 +1,19 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import torch
2
+
3
+ def generate_code(model, tokenizer, idea):
4
+ input_text = f"""
5
+ # Idea: {idea}
6
+
7
+ # Code:
8
+ """
9
+ input_ids = tokenizer.encode(input_text, return_tensors="pt")
10
+ output_sequences = model.generate(
11
+ input_ids=input_ids,
12
+ max_length=1024,
13
+ num_return_sequences=1,
14
+ no_repeat_ngram_size=2,
15
+ early_stopping=True,
16
+ )
17
+ generated_code = tokenizer.decode(output_sequences[0], skip_special_tokens=True)
18
+
19
+ return generated_code