Malek-AI commited on
Commit
00a1167
1 Parent(s): 31cfa27

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +14 -12
app.py CHANGED
@@ -1,23 +1,25 @@
1
  import gradio as gr
2
  from transformers import pipeline
3
 
4
- used_model = 'openai-community/gpt2'
5
-
6
- pipe = pipeline(task='text-generation', model=used_model)
7
 
8
  def generate_alternatives(text):
9
- items = pipe(text, max_length=50, num_return_sequences=5)
10
  texts = []
11
  for item in items:
12
  texts.append(str(items.index(item) + 1) + '. ' + item['generated_text'])
13
- texts.append(str('') + 150 * '-')
 
14
  return '\n'.join(texts)
15
 
16
- gradio_app = gr.Interface(
17
- generate_alternatives,
18
- inputs="text", #Please insert the text that you want to enhance",
19
- outputs="text" #The generated alternatives"
 
 
 
 
 
20
  )
21
-
22
- if __name__ == "__main__":
23
- gradio_app.launch()
 
1
  import gradio as gr
2
  from transformers import pipeline
3
 
4
+ pipeline = pipeline(task='text-generation', model='openai-community/gpt2')
 
 
5
 
6
  def generate_alternatives(text):
7
+ items = pipeline(text, max_length=150, num_return_sequences=2)
8
  texts = []
9
  for item in items:
10
  texts.append(str(items.index(item) + 1) + '. ' + item['generated_text'])
11
+ # separator
12
+ texts.append(str('') + 15 * '-')
13
  return '\n'.join(texts)
14
 
15
+ # Gradio UI
16
+ examples=[['Today I got out of bed and went to school']]
17
+ ui = gr.Interface(
18
+ generate_alternatives,
19
+ inputs="text",
20
+ outputs="text",
21
+ title="GPT-2 Test - Zircon.tech",
22
+ description="Enter some text to let GPT-2 give enhanced version of it!",
23
+ examples=examples
24
  )
25
+ ui.launch(debug=True)