jph00 commited on
Commit
a013f20
1 Parent(s): cb2637d

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +17 -0
app.py ADDED
@@ -0,0 +1,17 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from fastcore.utils import *
2
+ import gradio as gr
3
+
4
+ def fix_imgs(src, dst):
5
+ found = {n:(s,f) for n,s,f in
6
+ re.findall(r'!\[(\S+)\|(\S+)\]\((\S+)\)', src)}
7
+
8
+ def repl_img(x):
9
+ res = found.get(x.group(1))
10
+ if res:
11
+ sz,nm = res
12
+ return f'![{x.group(1)}|{sz}]({nm})'
13
+ else: return f'MISSING IMAGE: {x.group(1)}'
14
+
15
+ return re.sub(r'!\[\[([^.]+)\.\w+(\|\d+)?\]\]', repl_img, dst)
16
+
17
+ gr.Interface(fn=fix_imgs, inputs=[gr.Textbox(lines=15),gr.Textbox(lines=15)], outputs=gr.Textbox(lines=15)).launch()