import gradio as gr from text_converter import generate_similar_sentence APP_DESCRIPTION = '''# Reading Level Converter
Convert any text to a specified reading level while retaining the core text meaning
''' 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." # Dictionary mapping grade levels to reading ease scores reading_levels = { "5th Grade (90-100)": (90, 100), "6th Grade (80-90)": (80, 90), "7th Grade (70-80)": (70, 80), "8th - 9th Grade (60-70)": (60, 70), "10th - 12th Grade (50-60)": (50, 60), "College (30-50)": (30, 50), "College Graduate + Professionals (0-30)": (0, 30) } def convert_text(input_text, grade_level): min_level, max_level = reading_levels[grade_level] output_text, similarity, reading_level, input_reading_level, message = generate_similar_sentence(input_text, min_level, max_level, MIN_ENTAILMENT, SYSTEM_PROMPT, MAX_ITER) return output_text, similarity, reading_level, input_reading_level, message def main(): with gr.Blocks(css='styles.css') as app: gr.Markdown(APP_DESCRIPTION) with gr.Tab("Reading Level Calculator"): input_text = gr.Textbox(label="Input Text", placeholder="Type here...", lines=4) grade_level = gr.Radio(choices=list(reading_levels.keys()), label="Target Reading Level", value=list(reading_levels.keys())[0]) output_input_reading_level = gr.Textbox(label="Input Text Reading Level", placeholder="Input Text Reading Level...", lines=1) 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], outputs=[output_converted_text, output_similarity, output_reading_level, output_input_reading_level, output_message] ) app.launch(inbrowser=True) if __name__ == '__main__': main()