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