kmkarakaya commited on
Commit
0fd7b28
·
1 Parent(s): 76c900b
Files changed (1) hide show
  1. app.py +39 -0
app.py ADDED
@@ -0,0 +1,39 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import tensorflow as tf
2
+ !pip install transformers[sentencepiece] -q
3
+ from transformers import AutoTokenizer, TFGPT2LMHeadModel
4
+ !pip install gradio -q
5
+ import gradio as gr
6
+
7
+ review_model = TFGPT2LMHeadModel.from_pretrained("kmkarakaya/turkishReviews-ds")
8
+ review_tokenizer = AutoTokenizer.from_pretrained("kmkarakaya/turkishReviews-ds")
9
+
10
+ def generate_review(prompt):
11
+
12
+ input_ids = review_tokenizer.encode(prompt, return_tensors='tf')
13
+ context_length = 40
14
+ output = review_model.generate(
15
+ input_ids,
16
+ do_sample=True,
17
+ max_length=context_length,
18
+ top_k=10,
19
+ no_repeat_ngram_size=2,
20
+ early_stopping=True
21
+ )
22
+
23
+ return(review_tokenizer.decode(output[0], skip_special_tokens=True))
24
+
25
+ demo = gr.Interface(fn=generate_review,
26
+ inputs="text",
27
+ outputs="text",
28
+ examples=[
29
+ "Bir hafta önce aldığım cep telefonu",
30
+ "Tatil için rezervasyon yaptırdım.",
31
+ "Henüz alalı bir"],
32
+ title="Review Generator",
33
+ description= """
34
+ Generate a review in Turkish by providing a prompt.
35
+ Generation takes 15 seconds on average.
36
+ Full Code is here: https://youtube.com/playlist?list=PLQflnv_s49v9d9w-L0S8XUXXdNks7vPBL
37
+ """
38
+ )
39
+ demo.launch()