amanm10000 commited on
Commit
bc5a064
1 Parent(s): 08815d2

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +13 -0
app.py ADDED
@@ -0,0 +1,13 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import gradio as gr
2
+ from transformers import AutoTokenizer, AutoModelForCausalLM
3
+
4
+ tokenizer = AutoTokenizer.from_pretrained("gpt2")
5
+ model = AutoModelForCausalLM.from_pretrained("gpt2")
6
+
7
+ def generate(text):
8
+ inputs = tokenizer.encode(text, return_tensors='pt')
9
+ outputs = model.generate(inputs, max_length=100, do_sample=True)
10
+ generated = tokenizer.decode(outputs[0], skip_special_tokens=True)
11
+ return generated
12
+
13
+ gr.Interface(fn=generate, inputs="text", outputs="text").launch()