File size: 3,598 Bytes
127f052
0ae62b7
127f052
7b28cbc
 
 
 
 
 
 
4433993
 
 
 
 
7b28cbc
4433993
9d6764e
7b28cbc
672ad31
 
 
ab72374
 
8b7d7ff
 
 
 
0ae62b7
 
859ad96
ab72374
4433993
 
41adfee
 
4433993
e664527
 
4433993
 
 
ab72374
4433993
 
 
e664527
ab72374
 
e664527
672ad31
 
 
 
 
 
 
 
 
 
 
ab72374
c378e49
672ad31
ab72374
 
7b28cbc
 
672ad31
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
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
import gradio as gr
from text_converter import fre_levels, sbert_levels, model_types, generate_similar_sentence, user_input_readability_level, set_reading_levels

APP_DESCRIPTION = '''# Reading Level Converter
<div id="content_align">Convert any text to a specified reading level while retaining the core text meaning</div>'''

MIN_ENTAILMENT = 0.5
MAX_ITER = 5
SYSTEM_PROMPT = "You are a writing assistant. You help convert complex texts to simpler texts while maintaining the core meaning of the text."

def convert_text(input_text, grade_level, input_reading_score, model_type):
    if model_type == "FRE":
        reading_levels = fre_levels
    else:
        reading_levels = sbert_levels
    min_level, max_level = reading_levels[grade_level]
    output_text, similarity, reading_level, message = generate_similar_sentence(input_text, min_level, max_level, MIN_ENTAILMENT, SYSTEM_PROMPT, MAX_ITER, float(input_reading_score), model_type)
    return output_text, similarity, reading_level, message

with gr.Blocks(css='styles.css') as app:
    gr.Markdown(APP_DESCRIPTION)

    with gr.Tab("FRE"):
        """with gr.Row():
            readability_model = gr.Radio(choices=model_types, label="Readability Model", value = model_types[0], interactive=True, scale = 2)
            readability_model_btn = gr.Button("Set Readability Model", scale = 1)
        
        readability_model_btn.click(
            fn=set_reading_levels,
            inputs=[readability_model],
            outputs=[readability_model]
        )"""

        with gr.Row():
            input_text = gr.Textbox(label="Input Text", placeholder="Type here...", lines=4, scale = 2)
            fetch_score_and_lvl_btn = gr.Button("Fetch Score and Level", scale = 1)

        output_input_reading_score = gr.Textbox(label="Input Text Reading Score", placeholder="Input Text Reading Score...", lines=1, interactive=False)
        output_input_reading_level = gr.Textbox(label="Input Text Reading Level", placeholder="Input Text Reading Level...", lines=1, interactive=False)

        fetch_score_and_lvl_btn.click(
            fn=user_input_readability_level,
            inputs=[input_text, "FRE"],
            outputs=[output_input_reading_score, output_input_reading_level]
        )
        
        
        grade_level_fre = gr.Radio(choices=list(fre_levels.keys()), label="Target Reading Level", interactive=True)
        #grade_level_sbert = gr.Radio(choices=list(sbert_levels.keys()), label="Target Reading Level", interactive=True, visible=(readability_model == model_types[1]))
        #grade_level = gr.Radio(choices=list(fre_levels.keys()) if readability_model == model_types[0] else list(sbert_levels.keys()), label="Target Reading Level", interactive=True)
        
        output_reading_level = gr.Textbox(label="Output Reading Level", placeholder="Output Reading Level...", lines=1)
        output_similarity = gr.Textbox(label="Similarity", placeholder="Similarity Score...", lines=1)
        output_converted_text = gr.Textbox(label="Converted Text", placeholder="Results will appear here...", lines=4)
                    
        output_message = gr.Textbox(label="Message", placeholder="System Message...", lines=2)
        
        convert_button = gr.Button("Convert Text")

        convert_button.click(
            fn=convert_text,
            inputs=[input_text, grade_level_fre, output_input_reading_score, "FRE"],
            outputs=[output_converted_text, output_similarity, output_reading_level, output_message]
        )
    #with gr.Tab("SBERT"):


if __name__ == '__main__':
    app.launch()