File size: 1,216 Bytes
4a5a872
 
 
29070b3
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
4a5a872
7014750
 
 
 
 
 
6bcf23a
7014750
 
 
 
08d8497
4a5a872
7014750
 
 
4a5a872
7014750
4a5a872
08d8497
 
4a5a872
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
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()