File size: 641 Bytes
65519f3
31cfa27
65519f3
31cfa27
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
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()