|
import gradio as gr |
|
from transformers import pipeline |
|
|
|
pipeline = pipeline(task='text-generation', model='openai-community/gpt2') |
|
|
|
def generate_alternatives(text): |
|
items = pipeline(text, max_length=150, num_return_sequences=2) |
|
texts = [] |
|
for item in items: |
|
texts.append(str(items.index(item) + 1) + '. ' + item['generated_text']) |
|
|
|
texts.append(str('') + 15 * '-') |
|
return '\n'.join(texts) |
|
|
|
|
|
examples=[['Today I got out of bed and went to school'], |
|
['My name is Teven and I am'], |
|
['My name is Mariama, my favorite']] |
|
|
|
ui = gr.Interface( |
|
generate_alternatives, |
|
inputs="text", |
|
outputs="text", |
|
title="GPT-2 Test - Zircon.tech", |
|
description="Enter some text to let GPT-2 give enhanced version of it!", |
|
examples=examples |
|
) |
|
ui.launch(debug=True) |