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

Upload app.py

Browse files
Files changed (1) hide show
  1. app.py +37 -0
app.py ADDED
@@ -0,0 +1,37 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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)