Update app.py
Browse files
app.py
CHANGED
|
@@ -1,23 +1,25 @@
|
|
| 1 |
import gradio as gr
|
| 2 |
from transformers import pipeline
|
| 3 |
|
| 4 |
-
|
| 5 |
-
|
| 6 |
-
pipe = pipeline(task='text-generation', model=used_model)
|
| 7 |
|
| 8 |
def generate_alternatives(text):
|
| 9 |
-
items =
|
| 10 |
texts = []
|
| 11 |
for item in items:
|
| 12 |
texts.append(str(items.index(item) + 1) + '. ' + item['generated_text'])
|
| 13 |
-
|
|
|
|
| 14 |
return '\n'.join(texts)
|
| 15 |
|
| 16 |
-
|
| 17 |
-
|
| 18 |
-
|
| 19 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 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)
|
|
|
|
|
|