arjunascagnetto commited on
Commit
920c384
1 Parent(s): f85e23b

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +13 -10
app.py CHANGED
@@ -1,15 +1,18 @@
 
 
1
  import gradio as gr
2
- from transformers import GPT2LMHeadModel, GPT2Tokenizer
 
 
 
 
3
 
4
- tokenizer = GPT2Tokenizer.from_pretrained("gpt2")
5
- model = GPT2LMHeadModel.from_pretrained("gpt2")
6
 
7
- def generate_text(prompt):
8
- inputs = tokenizer(prompt, return_tensors="pt").to('cuda')
9
- outputs = model.generate(inputs, do_sample=False, max_length=100)
 
10
 
11
- generated_text = tokenizer.decode(outputs[0], skip_special_tokens=True)
12
- return generated_text
13
 
14
- iface = gr.Interface(fn=generate_text, inputs=[gr.Textbox(label="Enter a prompt")])
15
- iface.launch()
 
1
+
2
+
3
  import gradio as gr
4
+ from transformers import AutoModelForSequenceClassification, AutoTokenizer
5
+
6
+
7
+ model = AutoModelForSequenceClassification.from_pretrained("bert-base-uncased")
8
+ tokenizer = AutoTokenizer.from_pretrained("bert-base-uncased")
9
 
 
 
10
 
11
+ def generate_text(input_text):
12
+ input_ids = tokenizer.encode(input_text, return_tensors="pt")
13
+ output = model.generate(input_ids)
14
+ return tokenizer.decode(output[0], skip_special_tokens=True)
15
 
16
+ interface = gr.Interface(fn=generate_text, inputs="text", outputs="text")
 
17
 
18
+ interface.launch()