feifeinoban commited on
Commit
6ce3c38
·
1 Parent(s): 5b546ca

Fix image path for Gradio rendering

Browse files
Files changed (2) hide show
  1. README.md +1 -1
  2. app.py +3 -53
README.md CHANGED
@@ -80,7 +80,7 @@ This replaces labor-intensive human labeling with **autonomous, human-aligned re
80
  - At inference, **add vectors to internal activations** (e.g., Layer 18 of Llama 3.1) to guide behavior.
81
  - **No fine-tuning needed**—works on closed-source models like GPT-5.
82
 
83
- ![MENTOR Architecture](assets/mentor_arch.png)
84
 
85
  > *Figure: The MENTOR framework (from paper). Shell implements this full pipeline.*
86
 
 
80
  - At inference, **add vectors to internal activations** (e.g., Layer 18 of Llama 3.1) to guide behavior.
81
  - **No fine-tuning needed**—works on closed-source models like GPT-5.
82
 
83
+ ![MENTOR Architecture](/file=./assets/mentor_arch.png)
84
 
85
  > *Figure: The MENTOR framework (from paper). Shell implements this full pipeline.*
86
 
app.py CHANGED
@@ -1,9 +1,6 @@
1
  import gradio as gr
2
- import re
3
- import os
4
- import base64
5
 
6
- def load_and_fix_markdown():
7
  with open("README.md", "r", encoding="utf-8") as f:
8
  content = f.read()
9
 
@@ -13,56 +10,9 @@ def load_and_fix_markdown():
13
  if len(parts) >= 3:
14
  content = parts[2].strip()
15
 
16
- # 方法1: 使用HTML img标签
17
- def replace_with_html(match):
18
- alt_text = match.group(1) or ""
19
- path = match.group(2)
20
-
21
- # 处理本地文件路径
22
- clean_path = path.lstrip('./')
23
-
24
- # 尝试找到实际文件
25
- actual_path = None
26
- if os.path.exists(clean_path):
27
- actual_path = clean_path
28
- else:
29
- # 尝试在assets目录中查找
30
- filename = os.path.basename(clean_path)
31
- possible_paths = [
32
- f"assets/{filename}",
33
- f"assets/{clean_path}",
34
- f"images/{filename}",
35
- filename
36
- ]
37
- for p in possible_paths:
38
- if os.path.exists(p):
39
- actual_path = p
40
- break
41
-
42
- if actual_path:
43
- # 使用HTML img标签
44
- return f'<img src="/file={actual_path}" alt="{alt_text}" style="max-width: 100%; height: auto; display: block; margin: 10px 0;">'
45
- else:
46
- # 如果找不到文件,保留原始URL(可能是外部URL)
47
- return f'![{alt_text}]({path})'
48
-
49
- content = re.sub(r'!\[(.*?)\]\((.*?)\)', replace_with_html, content)
50
  return content
51
 
52
  with gr.Blocks() as demo:
53
- # 使用HTML组件而不是Markdown组件
54
- gr.HTML("""
55
- <div style="max-width: 800px; margin: 0 auto; padding: 20px;">
56
- <div id="markdown-content">
57
- """)
58
-
59
- # 动态加载内容
60
- gr.HTML(load_and_fix_markdown())
61
-
62
- gr.HTML("""
63
- </div>
64
- </div>
65
- """)
66
 
67
- # 确保允许访问所有可能的路径
68
- demo.launch(allowed_paths=["./", "./assets", "./images", "./static"])
 
1
  import gradio as gr
 
 
 
2
 
3
+ def load_markdown():
4
  with open("README.md", "r", encoding="utf-8") as f:
5
  content = f.read()
6
 
 
10
  if len(parts) >= 3:
11
  content = parts[2].strip()
12
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
13
  return content
14
 
15
  with gr.Blocks() as demo:
16
+ gr.Markdown(load_markdown())
 
 
 
 
 
 
 
 
 
 
 
 
17
 
18
+ demo.launch(allowed_paths=["./", "./assets"])