ecarbo commited on
Commit
306cf09
1 Parent(s): 553008c

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +25 -0
app.py ADDED
@@ -0,0 +1,25 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from transformers import AutoTokenizer, AutoModelForCausalLM
2
+ import torch
3
+ import gradio as gr
4
+
5
+ tokenizer = AutoTokenizer.from_pretrained("EleutherAI/gpt-neo-1.3B")
6
+ model = AutoModelForCausalLM.from_pretrained("EleutherAI/gpt-neo-1.3B")
7
+
8
+ def text_generation(input_text, seed):
9
+ input_ids = tokenizer(input_text, return_tensors="pt").input_ids
10
+ torch.manual_seed(seed) # Max value: 18446744073709551615
11
+ outputs = model.generate(input_ids, do_sample=True, min_length=50, max_length=200)
12
+ generated_text = tokenizer.batch_decode(outputs, skip_special_tokens=True)
13
+ return generated_text
14
+
15
+ title = "Text Generator Demo GPT-Neo"
16
+ description = "Text Generator Application by ecarbo"
17
+
18
+ gr.Interface(
19
+ text_generation,
20
+ [gr.inputs.Textbox(lines=2, label="Enter input text"), gr.inputs.Number(default=10, label="Enter seed number")],
21
+ [gr.outputs.Textbox(type="auto", label="Text Generated")],
22
+ title=title,
23
+ description=description,
24
+ theme="huggingface"
25
+ ).launch()