daniel-img-fix / app.py
jph00's picture
Create app.py
a013f20
raw history blame
No virus
557 Bytes
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()