shkna1368 commited on
Commit
c9c4669
·
verified ·
1 Parent(s): c8b1d16

Update app.py

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