Axolotlily commited on
Commit
4101c6e
1 Parent(s): f979cc3

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +21 -15
app.py CHANGED
@@ -1,19 +1,25 @@
 
 
1
  import gradio as gr
2
- from aitextgen import aitextgen
3
 
4
- ai = aitextgen(model="EleutherAI/gpt-neo-2.7B")
 
5
 
6
- def ai_text(inp):
7
- generated_text = ai.generate_one(max_length=1001, prompt = inp, no_repeat_ngram_size=3)
8
- print(type(generated_text))
 
 
9
  return generated_text
10
-
11
- examples = [
12
- ["Artificial intelligence will"],
13
- ["Probably everyone likes Turtles and Axolotls."],
14
- ["Mars, Joyce and Venus had their first day at Blazing Inventions Academy in North Point, Hong Kong. The following day, while Mars, Joyce and Venus are eating breakfast in the Academy’s hall, a green gas spreads from North Point throughout the world."]
15
- ]
16
-
17
- output_text = gr.outputs.Textbox()
18
- gr.Interface(ai_text,"textbox", output_text, title="Text Generator GPT-NEO-2.7B",
19
- description="Copy or type text. Submit and the machine will generate text.", examples=examples).launch(share=False)
 
 
 
1
+ from transformers import AutoTokenizer, AutoModelForCausalLM
2
+ import torch
3
  import gradio as gr
 
4
 
5
+ tokenizer = AutoTokenizer.from_pretrained("gpt2")
6
+ model = AutoModelForCausalLM.from_pretrained("gpt2")
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, max_length=100)
12
+ generated_text = tokenizer.batch_decode(outputs, skip_special_tokens=True)
13
  return generated_text
14
+
15
+ title = "Text Generator Demo GPT2"
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()