Update app.py
Browse files1234567891011121314151617181920212223import gradio as grfrom transformers import pipelineused_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()12345678910111213141516171819202122232425import gradio as grfrom transformers import pipelinepipeline = 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'])# separatortexts.append(str('') + 15 * '-')return '\n'.join(texts)# Gradio UIexamples=[['Today I got out of bed and went to school']]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)
app.py+14-12