GPT-2 / app.py
Malek-AI's picture
Update app.py
31cfa27 verified
raw
history blame
641 Bytes
import gradio as gr
from transformers import pipeline
used_model = 'openai-community/gpt2'
pipe = pipeline(task='text-generation', model=used_model)
def generate_alternatives(text):
items = pipe(text, max_length=50, num_return_sequences=5)
texts = []
for item in items:
texts.append(str(items.index(item) + 1) + '. ' + item['generated_text'])
texts.append(str('') + 150 * '-')
return '\n'.join(texts)
gradio_app = gr.Interface(
generate_alternatives,
inputs="text", #Please insert the text that you want to enhance",
outputs="text" #The generated alternatives"
)
if __name__ == "__main__":
gradio_app.launch()