abouuuud Aaaaaaaabdualh commited on
Commit
da12c0c
0 Parent(s):

Duplicate from Aaaaaaaabdualh/poetry

Browse files

Co-authored-by: Taieeeeee <Aaaaaaaabdualh@users.noreply.huggingface.co>

Files changed (4) hide show
  1. .gitattributes +33 -0
  2. README.md +14 -0
  3. app.py +53 -0
  4. requirements.txt +3 -0
.gitattributes ADDED
@@ -0,0 +1,33 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
+ *.mlmodel filter=lfs diff=lfs merge=lfs -text
11
+ *.model filter=lfs diff=lfs merge=lfs -text
12
+ *.msgpack filter=lfs diff=lfs merge=lfs -text
13
+ *.npy filter=lfs diff=lfs merge=lfs -text
14
+ *.npz filter=lfs diff=lfs merge=lfs -text
15
+ *.onnx filter=lfs diff=lfs merge=lfs -text
16
+ *.ot filter=lfs diff=lfs merge=lfs -text
17
+ *.parquet filter=lfs diff=lfs merge=lfs -text
18
+ *.pb filter=lfs diff=lfs merge=lfs -text
19
+ *.pickle filter=lfs diff=lfs merge=lfs -text
20
+ *.pkl filter=lfs diff=lfs merge=lfs -text
21
+ *.pt filter=lfs diff=lfs merge=lfs -text
22
+ *.pth filter=lfs diff=lfs merge=lfs -text
23
+ *.rar filter=lfs diff=lfs merge=lfs -text
24
+ *.safetensors filter=lfs diff=lfs merge=lfs -text
25
+ saved_model/**/* filter=lfs diff=lfs merge=lfs -text
26
+ *.tar.* filter=lfs diff=lfs merge=lfs -text
27
+ *.tflite filter=lfs diff=lfs merge=lfs -text
28
+ *.tgz filter=lfs diff=lfs merge=lfs -text
29
+ *.wasm filter=lfs diff=lfs merge=lfs -text
30
+ *.xz filter=lfs diff=lfs merge=lfs -text
31
+ *.zip filter=lfs diff=lfs merge=lfs -text
32
+ *.zst filter=lfs diff=lfs merge=lfs -text
33
+ *tfevents* filter=lfs diff=lfs merge=lfs -text
README.md ADDED
@@ -0,0 +1,14 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ ---
2
+ title: Arabic Poetry Generator
3
+ emoji: 🐠
4
+ colorFrom: blue
5
+ colorTo: red
6
+ sdk: gradio
7
+ sdk_version: 3.6
8
+ app_file: app.py
9
+ pinned: true
10
+ license: cc-by-nc-4.0
11
+ duplicated_from: Aaaaaaaabdualh/poetry
12
+ ---
13
+
14
+ Check out the configuration reference at https://huggingface.co/docs/hub/spaces-config-reference
app.py ADDED
@@ -0,0 +1,53 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import gc
2
+ import gradio as gr
3
+ from transformers import pipeline, set_seed
4
+
5
+ pipe = pipeline('text-generation', framework='pt', model='akhooli/ap2023', tokenizer='akhooli/ap2023')
6
+ #gc.collect()
7
+ samples = [['أنت'
8
+ ,1.0, 50, 1.0, 1.0, 114],['هل غادر'
9
+ ,1.0, 50, 1.0, 1.0, 114 ],['ألا ليت'
10
+ ,1.0, 50, 1.0, 1.0, 114 ],['يا قدس'
11
+ ,1.0, 50, 1.0, 1.0, 114],['عيد بأية حال'
12
+ ,1.0, 50, 1.0, 1.0, 114],['لكل شيء إذا ما'
13
+ ,1.0, 50, 1.0, 1.0, 114 ],['.'
14
+ ,1.0, 50, 1.0, 1.0, 114]]
15
+
16
+ notes = """
17
+ - Enter a short prompt or select (click) one of the examples and click SEND
18
+ - Adjust parameters (temperture, top k, top p and penalty) through the slider (keep close to default values).
19
+ - For the same seed (randomness), the same output is regenerated if other parameters are fixed. Seed should be 0 or more (not empty)
20
+ - Clear and enter new prompt or select another example and SEND to regenerate
21
+ - The '.' means start a new line from no prompt (your prompt need not be long)
22
+ - Be patient: this runs on CPU (free tier)
23
+ - Feedback (Twitter): @akhooli (https://twitter.com/akhooli/status/1611025232201977859)
24
+ - Note/Disclaimer: may generate unaccepted or inappropriate content. Use at your own risk.
25
+ """
26
+ def sayPoetry(prompt, temp=1.0, topk = 50, topp = 1.0, penalty=1.0, seed=114):
27
+ if not int(seed) >= 0: seed=114
28
+ set_seed(seed)
29
+ gen = pipe(prompt, max_length=96, do_sample=True, temperature=temp, top_k=topk, top_p=topp, repetition_penalty=penalty,
30
+ min_length = 64, no_repeat_ngram_size = 3, return_full_text=True,
31
+ num_beams=5, num_return_sequences=1)[0]["generated_text"]
32
+ poetry =""
33
+ for line in gen.split('.')[:-1]:
34
+ poetry += line #+ "\n"
35
+ return poetry
36
+ poetry = gr.Interface(fn=sayPoetry,
37
+ inputs=[
38
+ gr.Textbox(label="Enter short prompt or select from examples:"),
39
+ gr.Slider(0.70, 1.2, step=0.01,value=1.0, label='control temperature'),
40
+ gr.Slider(25, 100, step=1,value=50, label='control top k'),
41
+ gr.Slider(0.80, 1.0, step=0.01,value=1.0, label='control top p'),
42
+ gr.Slider(0.90, 1.50, step=0.01,value=1.0, label='control penalty'),
43
+ gr.Number(value=139750, precision=0, label='Seed'),
44
+ ],
45
+ outputs=[gr.Textbox(label="Generated Poetry:")],
46
+
47
+ allow_flagging='never',
48
+ title='Arabic Poetry Generation Demo (updated Jan. 2023)',
49
+ description = "A simple demo of AI generated poetry based on 1M poems fine-tuned using AraGPT2 (be patient, runs on cpu)",
50
+ examples=samples,
51
+ cache_examples=False,
52
+ article = notes)
53
+ poetry.launch()
requirements.txt ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ transformers
2
+ gradio #==3.0.2
3
+ torch