Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
@@ -1,37 +1,38 @@
|
|
1 |
-
|
2 |
-
|
3 |
-
|
4 |
-
|
5 |
-
|
6 |
-
|
7 |
-
|
8 |
-
|
9 |
-
|
10 |
-
|
11 |
-
|
12 |
-
|
13 |
-
|
14 |
-
|
15 |
-
|
16 |
-
|
17 |
-
|
18 |
-
|
19 |
-
|
20 |
-
|
21 |
-
|
22 |
-
|
23 |
-
|
24 |
-
|
25 |
-
|
26 |
-
|
27 |
-
|
28 |
-
|
29 |
-
|
30 |
-
|
31 |
-
|
32 |
-
|
33 |
-
|
34 |
-
|
35 |
-
|
36 |
-
|
|
|
37 |
demo.launch(share=True)
|
|
|
1 |
+
import gradio
|
2 |
+
from transformers import AutoTokenizer, AutoModelForSeq2SeqLM
|
3 |
+
|
4 |
+
tokenizer = AutoTokenizer.from_pretrained("shkna1368/jahanara")
|
5 |
+
model = AutoModelForSeq2SeqLM.from_pretrained("shkna1368/jahanara")
|
6 |
+
|
7 |
+
def remove_html_tags(text):
|
8 |
+
"""Remove html tags from a string"""
|
9 |
+
import re
|
10 |
+
clean = re.compile('<.*?>')
|
11 |
+
return re.sub(clean, '', text)
|
12 |
+
|
13 |
+
def generate(prompt):
|
14 |
+
input_ids = tokenizer.encode(prompt, return_tensors="pt")
|
15 |
+
#output_ids = model.generate(input_ids, max_length=800, num_beams=20, early_stopping=True)
|
16 |
+
complete_str=""
|
17 |
+
for i in range(0, 2):
|
18 |
+
outputs = model.generate(input_ids, do_sample=True, max_new_tokens=2500,early_stopping=False)
|
19 |
+
inp = tokenizer.decode(outputs[0])
|
20 |
+
complete_str=complete_str+inp+'\n'+"------"+'\n'
|
21 |
+
|
22 |
+
clear_text=remove_html_tags(complete_str)
|
23 |
+
return clear_text
|
24 |
+
|
25 |
+
demo=gradio.Interface (
|
26 |
+
fn=generate,
|
27 |
+
inputs=gradio.Textbox(value="دەتوانی بە شێوازی مەولەوی شیعری من پێسەم زانا تۆ پڕ مەیلەنی لە کتێبی دیوانی مەولەوی شیعرێکم بۆ بنووسیت",lines=2, placeholder="شیعرێک", rtl=True),
|
28 |
+
outputs=gradio.Textbox(lines=2, placeholder="",rtl=True),
|
29 |
+
title='Kurdish Poem Generator',
|
30 |
+
description='Kurdish poem generator '
|
31 |
+
|
32 |
+
)
|
33 |
+
|
34 |
+
|
35 |
+
|
36 |
+
|
37 |
+
|
38 |
demo.launch(share=True)
|