Spaces:
Runtime error
Runtime error
Create app.py
Browse files
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''
|
| 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()
|