akhooli commited on
Commit
2cfeb94
1 Parent(s): 2e3162f

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +21 -0
app.py ADDED
@@ -0,0 +1,21 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import gc
2
+ import gradio as gr
3
+ from transformers import pipeline
4
+
5
+ pipe = pipeline('text-generation', model='akhooli/ap2023', tokenizer='akhooli/ap2023')
6
+ gc.collect()
7
+
8
+ def sayPoetry(prompt):
9
+ gen = pipe(prompt, max_length=96)[0]["generated_text"]
10
+ poetry =""
11
+ for line in gen[0].split('.')[:-1]:
12
+ poetry += line + "\n"
13
+ return poetry
14
+
15
+ tb = gr.Textbox(label="Enter your prompt or select from examples:", placeholder="أنا الذي", lines=1)
16
+ p_app = gr.Interface(fn=sayPoetry, inputs=tb, outputs="text", allow_flagging='never',
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
+
21
+ p_app.launch()