Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -4,19 +4,20 @@ from transformers import pipeline
|
|
| 4 |
|
| 5 |
pipe = pipeline('text-generation', framework='pt', model='akhooli/ap2023', tokenizer='akhooli/ap2023')
|
| 6 |
#gc.collect()
|
| 7 |
-
|
| 8 |
def sayPoetry(prompt):
|
| 9 |
gen = pipe(prompt, max_length=96, temperature = 0.95)[0]["generated_text"]
|
| 10 |
poetry =""
|
| 11 |
for line in gen.split('.')[:-1]:
|
| 12 |
-
poetry += line
|
| 13 |
return poetry
|
| 14 |
|
| 15 |
-
|
| 16 |
-
|
|
|
|
| 17 |
title='Arabic Poetry Generation Demo (updated Jan. 2023)',
|
| 18 |
description = "a simple demo of AI generated poetry based on 1M poems fine-tuned using AraGPT2 (be patient, runs on cpu)",
|
| 19 |
-
examples=
|
| 20 |
,theme = 'darkhuggingface')
|
| 21 |
|
| 22 |
poetry.launch()
|
|
|
|
| 4 |
|
| 5 |
pipe = pipeline('text-generation', framework='pt', model='akhooli/ap2023', tokenizer='akhooli/ap2023')
|
| 6 |
#gc.collect()
|
| 7 |
+
samples = [['أنت'],['لولا كتاب'],['ألا ليت'],['يا قدس'],['عيد بأية حال'],['لكل شيء إذا ما'],['.']]
|
| 8 |
def sayPoetry(prompt):
|
| 9 |
gen = pipe(prompt, max_length=96, temperature = 0.95)[0]["generated_text"]
|
| 10 |
poetry =""
|
| 11 |
for line in gen.split('.')[:-1]:
|
| 12 |
+
poetry += line + "\n"
|
| 13 |
return poetry
|
| 14 |
|
| 15 |
+
input_prompt = gr.inputs.Textbox(label="Enter your prompt or select from examples:", placeholder="أنا الذي", lines=1)
|
| 16 |
+
output_text = gr.outputs.Textbox(label="Generated Poetry:", lines=4)
|
| 17 |
+
poetry = gr.Interface(fn=sayPoetry, inputs=input_prompt, outputs=output_text, allow_flagging='never',
|
| 18 |
title='Arabic Poetry Generation Demo (updated Jan. 2023)',
|
| 19 |
description = "a simple demo of AI generated poetry based on 1M poems fine-tuned using AraGPT2 (be patient, runs on cpu)",
|
| 20 |
+
examples=samples,
|
| 21 |
,theme = 'darkhuggingface')
|
| 22 |
|
| 23 |
poetry.launch()
|