kmkarakaya commited on
Commit
30016b4
·
1 Parent(s): 66bf2b6

Update app.py

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