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