File size: 557 Bytes
a013f20
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
from fastcore.utils import *
import gradio as gr

def fix_imgs(src, dst):
    found = {n:(s,f) for n,s,f in
             re.findall(r'!\[(\S+)\|(\S+)\]\((\S+)\)', src)}

    def repl_img(x):
        res = found.get(x.group(1))
        if res:
            sz,nm = res
            return f'![{x.group(1)}|{sz}]({nm})'
        else: return f'MISSING IMAGE: {x.group(1)}'
    
    return re.sub(r'!\[\[([^.]+)\.\w+(\|\d+)?\]\]', repl_img, dst)

gr.Interface(fn=fix_imgs, inputs=[gr.Textbox(lines=15),gr.Textbox(lines=15)], outputs=gr.Textbox(lines=15)).launch()