Update app.py
Browse files
app.py
CHANGED
@@ -1,3 +1,23 @@
|
|
1 |
import gradio as gr
|
|
|
2 |
|
3 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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()
|