created app.py
Browse files
app.py
ADDED
@@ -0,0 +1,20 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
|
2 |
+
|
3 |
+
|
4 |
+
import gradio as gr
|
5 |
+
import tensorflow
|
6 |
+
from transformers import TFGPT2LMHeadModel, GPT2Tokenizer
|
7 |
+
|
8 |
+
tokenizer = GPT2Tokenizer.from_pretrained("gpt2")
|
9 |
+
|
10 |
+
model = TFGPT2LMHeadModel.from_pretrained("gpt2",pad_token_id=tokenizer.eos_token_id)
|
11 |
+
|
12 |
+
def generate_text(inp):
|
13 |
+
input_ids = tokenizer.encode(inp, return_tensors='tf')
|
14 |
+
beam_output = model.generate(input_ids, max_length=109, num_beams=5, no_repeat_ngram_size=2, early_stopping=True)
|
15 |
+
|
16 |
+
output = tokenizer.decode(beam_output[0], skip_special_tokens=True, clean_up_tokenization_spaces=True)
|
17 |
+
|
18 |
+
return ".".join(output.split(".")[:-1]) + "."
|
19 |
+
output_text = gr.outputs.Textbox()
|
20 |
+
gr.Interface(generate_text,"textbox",output_text, title="MAX-GPT",description = "Chat and ask about anything, leave unfinished sentences for autocomplete or just ask questions revolving any topic").launch(share=True)
|