kmkarakaya's picture
Update app.py
0da53db
raw
history blame
2.65 kB
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):
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.
Generation takes 15-20 seconds on average.
You can share your experience by Flagging.
Enjoy!"""
article = """<p style='text-align: center'>On YouTube:</p>
<p style='text-align: center'><a href='https://youtube.com/playlist?list=PLQflnv_s49v9d9w-L0S8XUXXdNks7vPBL' target='_blank'>How to Train a Hugging Face Causal Language Model from Scratch with a Custom Dataset and a Custom Tokenizer?</a></p>
<p style='text-align: center'><a href='https://youtube.com/playlist?list=PLQflnv_s49v8aajw6m9MRNbAAbL63flKD' target='_blank'>Hugging Face kütüphanesini kullanarak bir GPT2 Transformer Dil Modelini Kendi Veri Setimizle nasıl eğitip kullanabiliriz? (in Turkish)</a></p>
<p style='text-align: center'>On Medium:</p>
<p style='text-align: center'><a href='https://medium.com/deep-learning-with-keras/how-to-train-a-hugging-face-causal-language-model-from-scratch-8d08d038168f' target='_blank'>How to Train a Hugging Face Causal Language Model from Scratch with a Custom Dataset and a Custom Tokenizer?</a></p>"""
examples=["Bir hafta önce aldığım cep telefonu",
"Tatil için rezervasyon yaptırdım",
"Geçen ay sipariş verdiğim",
"Spor salonuna abone oldum"]
demo = gr.Interface(fn=generate_review,
inputs= gr.Textbox(lines=5, placeholder="enter or select a prompt below..."),
outputs= gr.Textbox(lines=5, placeholder="genereated review will be here..."),
examples=examples,
title=title,
description= description,
article = article,
allow_flagging="manual",
flagging_options=["reasonable", "non-sense", "moderate"],
enable_queue=True
)
demo.launch('share=True')