Spaces:
Running
Running
File size: 2,083 Bytes
71b4b2d |
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 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 |
import gradio as gr
from transformers import pipeline
def generate_text(
model,
text,
min_length,
max_length,
do_not_truncate,
):
pipe = pipeline(
'text-generation',
model='MesonWarrior/gpt2-bugro',
tokenizer='MesonWarrior/gpt2-bugro',
min_length=min_length,
max_length=max_length,
use_auth_token="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"
)
return pipe(text)[0]['generated_text']
def interface():
with gr.Row():
with gr.Column():
with gr.Row():
model = gr.Dropdown(
["Бугро", "Юморески", "Калик"], label="Model", value="Бугро",
)
text = gr.Textbox(lines=7, label="Input text")
output = gr.Textbox(lines=12, label="Output text")
with gr.Row():
with gr.Column():
min_length = gr.Slider(
minimum=0, maximum=128, value=32, step=1,
label="Min Length",
)
max_length = gr.Slider(
minimum=0, maximum=512, value=96, step=1,
label="Max Length",
)
do_not_truncate = gr.Checkbox(
True,
label="Do not truncate"
)
with gr.Column():
with gr.Row():
generate_btn = gr.Button(
"Generate", variant="primary", label="Generate",
)
generate_btn.click(
fn=generate_text,
inputs=[
model,
text,
min_length,
max_length,
do_not_truncate
],
outputs=output,
)
with gr.Blocks(
title="GPT2 VK") as demo:
gr.Markdown("""
## GPT2 VK
Файнтюны модели [ai-forever/rugpt3medium_based_on_gpt2](https://huggingface.co/ai-forever/rugpt3medium_based_on_gpt2) по вашим любимым пабликам ВКонтакте.
""")
interface()
demo.queue().launch() |