mail-generator / app.py
amanneo's picture
feat: Added required files
3f13a29
raw
history blame
1.06 kB
import gradio as gr
from transformers import pipeline
model_tag = "amanneo/distilgpt2-emailgen-finetuned-custom-mail"
tokenizer_tag = "distilgpt2"
generator = pipeline(
'text-generation',
model=model_tag,
do_sample=False,
early_stopping=True,
tokenizer=tokenizer_tag
)
generation_args = {
"min_length": 4,
"max_length": 64,
"length_penalty": 0.5,
"no_repeat_ngram_size": 2,
"do_sample": False,
"num_beams": 4,
"early_stopping": True,
"repetition_penalty": 3.5,
}
# Main function
def text_generator(seed_text,min_n,max_n):
generation_args["min_length"] = min_n
generation_args["max_length"] = max_n
prompt = seed_text
result = generator(
prompt,
**generation_args,
)
return result[0]['generated_text']
iface = gr.Interface(
fn=text_generator,
inputs=["text","slider","slider"],
outputs="text",
title="Text Generator",
live=False
)
iface.launch(debug=True)