Spaces:
Running
Running
feifeinoban
commited on
Commit
·
78595e2
1
Parent(s):
2fa0975
Fix image path for Gradio rendering
Browse files
app.py
CHANGED
|
@@ -1,8 +1,7 @@
|
|
| 1 |
import gradio as gr
|
| 2 |
-
import
|
| 3 |
|
| 4 |
-
|
| 5 |
-
def load_markdown():
|
| 6 |
with open("README.md", "r", encoding="utf-8") as f:
|
| 7 |
content = f.read()
|
| 8 |
|
|
@@ -10,11 +9,24 @@ def load_markdown():
|
|
| 10 |
if content.startswith("---"):
|
| 11 |
parts = content.split("---", 2)
|
| 12 |
if len(parts) >= 3:
|
| 13 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 14 |
|
| 15 |
return content
|
| 16 |
|
| 17 |
with gr.Blocks() as demo:
|
| 18 |
-
gr.Markdown(
|
| 19 |
|
| 20 |
-
demo.launch(
|
|
|
|
| 1 |
import gradio as gr
|
| 2 |
+
import re
|
| 3 |
|
| 4 |
+
def load_and_fix_markdown():
|
|
|
|
| 5 |
with open("README.md", "r", encoding="utf-8") as f:
|
| 6 |
content = f.read()
|
| 7 |
|
|
|
|
| 9 |
if content.startswith("---"):
|
| 10 |
parts = content.split("---", 2)
|
| 11 |
if len(parts) >= 3:
|
| 12 |
+
content = parts[2].strip()
|
| 13 |
+
|
| 14 |
+
# 修复所有图片路径 - 这是关键!
|
| 15 |
+
def replace_path(match):
|
| 16 |
+
path = match.group(1)
|
| 17 |
+
# 如果是绝对URL,保留域名但简化路径
|
| 18 |
+
if path.startswith("https://huggingface.co/spaces/"):
|
| 19 |
+
return f'[-1]})'
|
| 20 |
+
# 如果是相对路径,转换为应用根路径
|
| 21 |
+
elif "assets/" in path:
|
| 22 |
+
return f'[-1]})'
|
| 23 |
+
return match.group(0)
|
| 24 |
+
|
| 25 |
+
content = re.sub(r'!\[.*?\]\((.*?)\)', replace_path, content)
|
| 26 |
|
| 27 |
return content
|
| 28 |
|
| 29 |
with gr.Blocks() as demo:
|
| 30 |
+
gr.Markdown(load_and_fix_markdown())
|
| 31 |
|
| 32 |
+
demo.launch()
|