import gradio as gr mf={ "Heading 1":"# $INP", "Heading 2":"## $INP", "Heading 3":"### $INP", "Heading 4":"#### $INP", "Heading 5":"##### $INP", "Heading 6":"###### $INP", "Bold":"**$INP**", "Italics":"*$INP*", "Strikethrough":"~~$INP~~", "Highlight Text":"==$INP==", "Bullet Point":"- $INP", "Inline Code":"`$INP`", "Code Blocks":"```$INP```", "Block Quote":"> $INP", "Checkbox (Unchecked)":"- [ ] $INP", "Checkbox (Checked)":"- [x] $INP", "Math Blocks":"$$ $INP $$", "Add Emoji":":$INP:", "Divider Line":"---", } def upd(inp,cur_l,cur_d,format): if not cur_l: cur_l=[] if not cur_d: cur_d={} #for ea in list(cur.keys()): line=f'{mf[format].replace("$INP",inp)}' cur_l.append(line) out_str="" for ea in cur_l: out_str+=ea return out_str,cur_l,out_str with gr.Blocks() as app: cur_l=gr.State() cur_d=gr.State() prev=gr.Markdown("") format=gr.Dropdown(label="Line Format",choices=[m for m in list(mf.keys())]) txt=gr.Textbox(lines=20) btn=gr.Button() out_txt=gr.Textbox() btn.click(upd,[txt,cur_l,cur_d,format],[prev,cur_l,out_txt]) app.launch()