Spaces:
Runtime error
Runtime error
File size: 1,640 Bytes
2ab7ea7 9ae6a25 2ab7ea7 9ae6a25 678d74f 2ab7ea7 9ae6a25 2ab7ea7 2b9df4c 2ab7ea7 |
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 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 |
from transformers import pipeline, set_seed
import gradio as gr
import nltk
nltk.download('punkt')
classifier = pipeline('text-generation', model='arputtick/GPT_Neo_1.3B_eco_feminist_2')
set_seed(42)
def generate_text(text, gen_length):
gen_text = classifier(text, max_length=gen_length)[0]['generated_text']
sentences = nltk.sent_tokenize(gen_text)
if sentences[-1][-1] == ".":
output = sentences
else:
output = sentences[:-1]
return " ".join(output)
Instructuction = "Browse the internet to download any unique image"
title="Eco-Feminist Text Generation"
description = "Start writing a peice of text in the input box\
and see how well the text generation language model\
is able to generate new text that uniquely completes your sentences."
article = """
- Write a text in the input box and specify the length of text.
- Also you can select a quick example to continue.
- Click submit button to generate new text.
- Click clear button to try new text generation.
"""
# Gradio app design
interface = gr.Interface(
generate_text,
inputs = ['text', gr.Slider(20, 200, value=80, step=1)],
outputs='text',
title = title,
description = description,
article = article,
allow_flagging = "never",
#theme = "peach",
#live = False,
examples=[["Agriculture is very fundamental to",
50], ["I will tell a story about",
100]]
)
interface.launch() |