Spaces:
Sleeping
Sleeping
Update
Browse files
app.py
CHANGED
@@ -1,9 +1,15 @@
|
|
1 |
-
|
|
|
2 |
|
3 |
-
# Load
|
4 |
-
|
|
|
5 |
|
6 |
-
|
7 |
-
|
8 |
-
|
|
|
|
|
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()
|