File size: 1,401 Bytes
2cfeb94
 
 
 
a50edcb
2f068c3
6db59ad
64c7e4d
 
 
 
 
6db59ad
 
2cfeb94
bb1772f
50c95fd
2cfeb94
2e62955
50c95fd
64c7e4d
6db59ad
2cfeb94
 
50c95fd
64c7e4d
6db59ad
2cfeb94
2f068c3
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
import gc 
import gradio as gr
from transformers import pipeline

pipe = pipeline('text-generation', framework='pt', model='akhooli/ap2023', tokenizer='akhooli/ap2023')
#gc.collect()
samples = [['أنت', 0.95],['لولا كتاب'],['ألا ليت'],['يا قدس'],['عيد بأية حال'],['لكل شيء إذا ما'],['.']]
notes = """
- Enter a short prompt or select one of the examples 
- generate poetry 
- be patient: this runs on CPU (free tier)
"""
def sayPoetry(prompt, temp):
    gen = pipe(prompt, max_length=96, temperature = temp)[0]["generated_text"]
    poetry =""
    for line in gen.split('.')[:-1]:
        poetry += line + "\n"
    return poetry
tempreature = gr.Slider(0.70, 1.0, value=0.94, step=0.01),                
input_prompt = gr.inputs.Textbox(label="Enter your prompt or select from examples:", placeholder="أنا الذي", lines=1)
output_text = gr.outputs.Textbox(label="Generated Poetry:")
poetry = gr.Interface(fn=sayPoetry, inputs=[input_prompt, temperature], outputs=output_text, allow_flagging='never',
                   title='Arabic Poetry Generation Demo (updated Jan. 2023)',
                   description = "a simple demo of AI generated poetry based on 1M poems fine-tuned using AraGPT2 (be patient, runs on cpu)",
                   examples=samples,
                article = notes,
                   theme = 'darkhuggingface')

poetry.launch()