tchans123 commited on
Commit
0c4de91
1 Parent(s): 2dc4a94
Files changed (1) hide show
  1. app.py +12 -6
app.py CHANGED
@@ -1,9 +1,15 @@
1
- from transformers import pipeline
 
2
 
3
- # Load the model from the hub
4
- text_generator = pipeline("text-generation", model="your-username/gpt2-my-deployment")
 
5
 
6
- # Generate text
7
- output = text_generator("Once upon a time", max_length=50)
8
- print(output)
 
 
9
 
 
 
 
1
+ import gradio as gr
2
+ from transformers import GPT2LMHeadModel, GPT2Tokenizer
3
 
4
+ # Load pre-trained model and tokenizer
5
+ model = GPT2LMHeadModel.from_pretrained("gpt2")
6
+ tokenizer = GPT2Tokenizer.from_pretrained("gpt2")
7
 
8
+ def generate_text(input_text):
9
+ input_ids = tokenizer.encode(input_text, return_tensors="pt")
10
+ output = model.generate(input_ids, max_length=50, num_return_sequences=1)
11
+ generated_text = tokenizer.decode(output[0], skip_special_tokens=True)
12
+ return generated_text
13
 
14
+ iface = gr.Interface(fn=generate_text, inputs="text", outputs="text")
15
+ iface.launch()