Spaces:
Sleeping
Sleeping
disable and enable the buttons upon analyze and generate
Browse files
app.py
CHANGED
|
@@ -45,16 +45,15 @@ analysis = BaitAnalysis()
|
|
| 45 |
meter, theme, qafiyah = "", "", ""
|
| 46 |
|
| 47 |
def analyze(poem):
|
| 48 |
-
global meter,theme,qafiyah
|
| 49 |
shatrs = poem.split("\n")
|
| 50 |
baits = [' # '.join(shatrs[2*i:2*i+2]) for i in range(len(shatrs)//2)]
|
| 51 |
output = analysis.analyze(baits,override_tashkeel=True)
|
| 52 |
meter = output['meter']
|
| 53 |
qafiyah = output['qafiyah'][0]
|
| 54 |
theme = output['theme'][-1]
|
| 55 |
-
|
| 56 |
df = get_output_df(output)
|
| 57 |
-
return get_highlighted_patterns_html(df)
|
| 58 |
|
| 59 |
def generate(inputs, top_p = 3):
|
| 60 |
baits = inputs.split('\n')
|
|
@@ -93,7 +92,8 @@ def generate(inputs, top_p = 3):
|
|
| 93 |
else:
|
| 94 |
break
|
| 95 |
# return theme+" "+ f"من بحر {meter} مع قافية بحر ({qafiyah})" + "\n" +result
|
| 96 |
-
return result
|
|
|
|
| 97 |
examples = [
|
| 98 |
[
|
| 99 |
"""القلب أعلم يا عذول بدائه
|
|
@@ -124,21 +124,28 @@ with gr.Blocks(theme=gr.themes.Soft(), css=css) as demo:
|
|
| 124 |
|
| 125 |
with gr.Row():
|
| 126 |
with gr.Column():
|
| 127 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 128 |
with gr.Column():
|
| 129 |
-
|
|
|
|
|
|
|
|
|
|
| 130 |
|
| 131 |
with gr.Row():
|
| 132 |
html_output = gr.HTML()
|
| 133 |
-
|
| 134 |
if lang == 'en':
|
| 135 |
gr.Examples(examples, textbox_output)
|
| 136 |
-
inp_btn.click(generate, inputs = textbox_output, outputs=inputs)
|
| 137 |
-
trg_btn.click(analyze, inputs = textbox_output, outputs=html_output)
|
| 138 |
else:
|
| 139 |
gr.Examples(examples, inputs)
|
| 140 |
-
trg_btn.click(generate, inputs = inputs, outputs=textbox_output)
|
| 141 |
-
inp_btn.click(analyze, inputs = inputs, outputs=html_output)
|
| 142 |
-
|
| 143 |
-
|
| 144 |
-
demo.launch()
|
|
|
|
| 45 |
meter, theme, qafiyah = "", "", ""
|
| 46 |
|
| 47 |
def analyze(poem):
|
| 48 |
+
global meter,theme,qafiyah, generate_btn
|
| 49 |
shatrs = poem.split("\n")
|
| 50 |
baits = [' # '.join(shatrs[2*i:2*i+2]) for i in range(len(shatrs)//2)]
|
| 51 |
output = analysis.analyze(baits,override_tashkeel=True)
|
| 52 |
meter = output['meter']
|
| 53 |
qafiyah = output['qafiyah'][0]
|
| 54 |
theme = output['theme'][-1]
|
|
|
|
| 55 |
df = get_output_df(output)
|
| 56 |
+
return get_highlighted_patterns_html(df), gr.Button.update(interactive=True)
|
| 57 |
|
| 58 |
def generate(inputs, top_p = 3):
|
| 59 |
baits = inputs.split('\n')
|
|
|
|
| 92 |
else:
|
| 93 |
break
|
| 94 |
# return theme+" "+ f"من بحر {meter} مع قافية بحر ({qafiyah})" + "\n" +result
|
| 95 |
+
return result, gr.Button.update(interactive=False)
|
| 96 |
+
|
| 97 |
examples = [
|
| 98 |
[
|
| 99 |
"""القلب أعلم يا عذول بدائه
|
|
|
|
| 124 |
|
| 125 |
with gr.Row():
|
| 126 |
with gr.Column():
|
| 127 |
+
if lang == 'ar':
|
| 128 |
+
trg_btn = gr.Button(btn_trg_text, interactive=False)
|
| 129 |
+
else:
|
| 130 |
+
trg_btn = gr.Button(btn_trg_text)
|
| 131 |
+
|
| 132 |
with gr.Column():
|
| 133 |
+
if lang == 'ar':
|
| 134 |
+
inp_btn = gr.Button(btn_inp_text)
|
| 135 |
+
else:
|
| 136 |
+
inp_btn = gr.Button(btn_inp_text, interactive = False)
|
| 137 |
|
| 138 |
with gr.Row():
|
| 139 |
html_output = gr.HTML()
|
| 140 |
+
|
| 141 |
if lang == 'en':
|
| 142 |
gr.Examples(examples, textbox_output)
|
| 143 |
+
inp_btn.click(generate, inputs = textbox_output, outputs=[inputs, inp_btn])
|
| 144 |
+
trg_btn.click(analyze, inputs = textbox_output, outputs=[html_output,inp_btn])
|
| 145 |
else:
|
| 146 |
gr.Examples(examples, inputs)
|
| 147 |
+
trg_btn.click(generate, inputs = inputs, outputs=[textbox_output, trg_btn])
|
| 148 |
+
inp_btn.click(analyze, inputs = inputs, outputs=[html_output,trg_btn] )
|
| 149 |
+
|
| 150 |
+
demo.launch(server_name = '0.0.0.0', share=True)
|
| 151 |
+
# demo.launch()
|