File size: 824 Bytes
65519f3
31cfa27
65519f3
00a1167
31cfa27
 
00a1167
31cfa27
 
 
00a1167
 
31cfa27
 
00a1167
62eca8c
 
 
 
00a1167
 
 
 
 
 
 
31cfa27
00a1167
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
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'])
    # separator
    texts.append(str('') + 15 * '-')
  return '\n'.join(texts)

# Gradio UI
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)