Spaces:
Runtime error
Runtime error
Commit
•
f97eb9b
0
Parent(s):
Duplicate from aaaaaabbbbbbbdddddddduuuuulllll/topic2poem
Browse filesCo-authored-by: Abdullah almaedhgy <[email protected]>
- .gitattributes +31 -0
- README.md +14 -0
- app.py +48 -0
- requirements.txt +2 -0
.gitattributes
ADDED
@@ -0,0 +1,31 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
*.7z filter=lfs diff=lfs merge=lfs -text
|
2 |
+
*.arrow filter=lfs diff=lfs merge=lfs -text
|
3 |
+
*.bin filter=lfs diff=lfs merge=lfs -text
|
4 |
+
*.bz2 filter=lfs diff=lfs merge=lfs -text
|
5 |
+
*.ftz filter=lfs diff=lfs merge=lfs -text
|
6 |
+
*.gz filter=lfs diff=lfs merge=lfs -text
|
7 |
+
*.h5 filter=lfs diff=lfs merge=lfs -text
|
8 |
+
*.joblib filter=lfs diff=lfs merge=lfs -text
|
9 |
+
*.lfs.* filter=lfs diff=lfs merge=lfs -text
|
10 |
+
*.model filter=lfs diff=lfs merge=lfs -text
|
11 |
+
*.msgpack filter=lfs diff=lfs merge=lfs -text
|
12 |
+
*.npy filter=lfs diff=lfs merge=lfs -text
|
13 |
+
*.npz filter=lfs diff=lfs merge=lfs -text
|
14 |
+
*.onnx filter=lfs diff=lfs merge=lfs -text
|
15 |
+
*.ot filter=lfs diff=lfs merge=lfs -text
|
16 |
+
*.parquet filter=lfs diff=lfs merge=lfs -text
|
17 |
+
*.pickle filter=lfs diff=lfs merge=lfs -text
|
18 |
+
*.pkl filter=lfs diff=lfs merge=lfs -text
|
19 |
+
*.pb filter=lfs diff=lfs merge=lfs -text
|
20 |
+
*.pt filter=lfs diff=lfs merge=lfs -text
|
21 |
+
*.pth filter=lfs diff=lfs merge=lfs -text
|
22 |
+
*.rar filter=lfs diff=lfs merge=lfs -text
|
23 |
+
saved_model/**/* filter=lfs diff=lfs merge=lfs -text
|
24 |
+
*.tar.* filter=lfs diff=lfs merge=lfs -text
|
25 |
+
*.tflite filter=lfs diff=lfs merge=lfs -text
|
26 |
+
*.tgz filter=lfs diff=lfs merge=lfs -text
|
27 |
+
*.wasm filter=lfs diff=lfs merge=lfs -text
|
28 |
+
*.xz filter=lfs diff=lfs merge=lfs -text
|
29 |
+
*.zip filter=lfs diff=lfs merge=lfs -text
|
30 |
+
*.zst filter=lfs diff=lfs merge=lfs -text
|
31 |
+
*tfevents* filter=lfs diff=lfs merge=lfs -text
|
README.md
ADDED
@@ -0,0 +1,14 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
---
|
2 |
+
title: Topic2poem
|
3 |
+
emoji: 💻
|
4 |
+
colorFrom: pink
|
5 |
+
colorTo: purple
|
6 |
+
sdk: gradio
|
7 |
+
sdk_version: 3.2
|
8 |
+
app_file: app.py
|
9 |
+
pinned: false
|
10 |
+
license: afl-3.0
|
11 |
+
duplicated_from: aaaaaabbbbbbbdddddddduuuuulllll/topic2poem
|
12 |
+
---
|
13 |
+
|
14 |
+
Check out the configuration reference at https://huggingface.co/docs/hub/spaces-config-reference
|
app.py
ADDED
@@ -0,0 +1,48 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
from transformers import BertTokenizer, EncoderDecoderModel
|
2 |
+
import gradio as gr
|
3 |
+
|
4 |
+
tokenizerM = BertTokenizer.from_pretrained("mareloraby/BERTShared-PoetryGen-arV01")
|
5 |
+
bertSharedM = EncoderDecoderModel.from_pretrained("mareloraby/BERTShared-PoetryGen-arV01")
|
6 |
+
# bertSharedM.cuda()
|
7 |
+
|
8 |
+
|
9 |
+
def generate_response(text, k = 70, p = 0.9, nb = 4):
|
10 |
+
prompt = f"{text}"
|
11 |
+
encoded_prompt = tokenizerM.encode_plus(prompt, return_tensors = 'pt')#.to(device)
|
12 |
+
gneration = bertSharedM.generate(
|
13 |
+
input_ids = encoded_prompt.input_ids,
|
14 |
+
attention_mask = encoded_prompt.attention_mask,
|
15 |
+
do_sample = True,
|
16 |
+
top_k= k,
|
17 |
+
top_p = p,
|
18 |
+
num_beams= nb,
|
19 |
+
max_length =130,
|
20 |
+
repetition_penalty = 2.0,
|
21 |
+
no_repeat_ngram_size = 2,
|
22 |
+
early_stopping=True)
|
23 |
+
|
24 |
+
generated_text = tokenizerM.decode(gneration[0], skip_special_tokens=True)
|
25 |
+
bayts = generated_text.split("[BSEP]")
|
26 |
+
while("FSEP" not in bayts[-1]):
|
27 |
+
bayts = bayts[:-1]
|
28 |
+
bayts = bayts[:-1]
|
29 |
+
temp_poem = ''
|
30 |
+
for b in range(len(bayts)):
|
31 |
+
temp_line = bayts[b].split('[FSEP]')
|
32 |
+
temp_poem = temp_poem + temp_line[1] + ' - ' + temp_line[0] +'\n'
|
33 |
+
|
34 |
+
return temp_poem
|
35 |
+
|
36 |
+
iface = gr.Interface(fn=generate_response,
|
37 |
+
title = 'BERTShared - topic based generation',
|
38 |
+
|
39 |
+
inputs=[
|
40 |
+
gr.inputs.Radio(['حزينه','هجاء','عتاب','غزل','مدح','رومنسيه','دينية'],label='Choose Topic'),
|
41 |
+
gr.inputs.Slider(10, 200, step=10,default = 70, label='Top-K'),
|
42 |
+
gr.inputs.Slider(0.10, 0.99, step=0.02, default = 0.90, label='Top-P'),
|
43 |
+
#gr.inputs.Slider(1, 20, step=1, default = 4, label='Beams'),
|
44 |
+
|
45 |
+
],
|
46 |
+
outputs="text")
|
47 |
+
|
48 |
+
iface.launch()
|
requirements.txt
ADDED
@@ -0,0 +1,2 @@
|
|
|
|
|
|
|
1 |
+
transformers
|
2 |
+
torch
|