Yori6789 commited on
Commit
b4ca10c
·
1 Parent(s): f615357
Files changed (1) hide show
  1. app.py +24 -0
app.py ADDED
@@ -0,0 +1,24 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from transformers import GPT2Tokenizer, GPT2LMHeadModel
2
+ import torch
3
+
4
+ # Initialize the tokenizer and model
5
+ tokenizer = GPT2Tokenizer.from_pretrained("gpt2")
6
+ model = GPT2LMHeadModel.from_pretrained("gpt2")
7
+
8
+ # Set the model to evaluation mode
9
+ model.eval()
10
+
11
+ # Prompt text
12
+ prompt = "face generating code"
13
+
14
+ # Encode the prompt text
15
+ input_ids = tokenizer.encode(prompt, return_tensors="pt")
16
+
17
+ # Generate text
18
+ with torch.no_grad():
19
+ output = model.generate(input_ids=input_ids, max_length=500)
20
+
21
+ # Decode the generated text
22
+ generated_text = tokenizer.decode(output[0], skip_special_tokens=True)
23
+
24
+ print(generated_text)