import requests import gradio as gr import os address = os.getenv("address") def generate_message(indcator_no_login,indcator_low_activity,indcator_repeated_course,indcator_low_marks,indcator_low_wam,indcator_fail): response = requests.post(address, json={ "no_login":indcator_no_login, "low_activity":indcator_low_activity, "repeated_course":indcator_repeated_course, "low_marks":indcator_low_marks, "low_wam": indcator_low_wam, "fail": indcator_fail, "prediction": "", "additional_info": "", }).json() result = response["body"] return result title = "Message Generator Playground" with gr.Blocks(title=title) as demo: gr.Markdown(""" # Message Generator Playground Select the conditions for a dummy student. """) with gr.Tab("Options"): with gr.Row(): with gr.Column(): no_login = gr.Radio(["Yes", "No"], label="No Moodle login in last 7 days", value="Yes", type="value" ) low_activity = gr.Radio(["Yes", "No"], label="Low Moodle activity", value="No", type="value" ) repeated_course = gr.Radio(["Yes", "No"], label="Repeated Course", value="No", type="value" ) low_marks = gr.Radio(["Yes", "No"], label="Low marks", value="No", type="value" ) low_wam = gr.Radio(["Yes", "No"], label="Low WAM", value="No", type="value" ) fails = gr.Radio(["Yes", "No"], label="Failed other course previously", value="No", type="value" ) ai_button = gr.Button("Generate GenAI Message") with gr.Column(): textlabel = gr.Textbox(label="Placeholder",lines=5,value="Your HTML message will be shown below. PLEASE NOTE: All URLs end with '%7Bga_link_placeholder%7D', which is used for tracking in Google Analytics and post-processing. Therefore, they are not clickable here. You can remove '%7Bga_link_placeholder%7D' from the links to access the webpages. However, these URLs will be processed and will be clickable for students in actual emails.",) email_ai = gr.HTML( label="AI-generated Email", value="Depending on message content, please wait up to 1 mins, please scroll if message is long", ) ai_button.click(generate_message, inputs=[no_login,low_activity,repeated_course,low_marks,low_wam,fails], outputs=[email_ai]) demo.launch()