import gradio as gr from transformers import AutoTokenizer, TFGPT2LMHeadModel review_model = TFGPT2LMHeadModel.from_pretrained("kmkarakaya/turkishReviews-ds") review_tokenizer = AutoTokenizer.from_pretrained("kmkarakaya/turkishReviews-ds") def generate_review(prompt): if prompt=="": prompt = " " input_ids = review_tokenizer.encode(prompt, return_tensors='tf') context_length = 40 output = review_model.generate( input_ids, do_sample=True, max_length=context_length, top_k=10, no_repeat_ngram_size=2, early_stopping=True ) return(review_tokenizer.decode(output[0], skip_special_tokens=True)) title="Turkish Review Generator: A GPT2 based Text Generator Trained with a Custom Dataset" description= """Generate a review in Turkish by providing a prompt or selecting an example prompt below. Generation takes 15-20 seconds on average. Enjoy! ![visitor badge](https://visitor-badge.glitch.me/badge?page_id=Auto_Review_Generation_in_Turkish) """ #
NOTE: Examples can sometimes generate ERROR. When you see ERROR on the screen just click SUBMIT. Model will generate text in 15-20 secs.
article = """On YouTube:
On Medium:
""" examples=["Bir hafta önce aldığım cep telefonu çalışmıyor.", "Tatil için yaptığım rezervasyonu iptal edemiyorum.", "Geçen ay sipariş verdiğim ayakkabı gelmedi.", "Abone olduğum spor salonu kapandı.", "Buzdolabından garip sesler geliyor.", "Otel tam bir fiyasko."] demo = gr.Interface(fn=generate_review, inputs= gr.Textbox(lines=5, label="Prompt", placeholder="enter or select a prompt below..."), outputs= gr.Textbox(lines=5, label="Generated Review", placeholder="genereated review will be here..."), examples=examples, title=title, description= description, article = article, #cache_examples = False allow_flagging="manual", flagging_options=["good","moderate", "non-sense", ] #flagging_dir='./flags' ) demo.launch()