Compare commits
4 Commits
mvp
...
519a5f3773
Author | SHA1 | Date | |
---|---|---|---|
![]() |
519a5f3773 | ||
![]() |
1f4d491694 | ||
![]() |
8ce4f1e373 | ||
![]() |
3395b860e4 |
1
.gitignore
vendored
1
.gitignore
vendored
@@ -11,6 +11,7 @@ env/
|
|||||||
# IDE
|
# IDE
|
||||||
.vscode/
|
.vscode/
|
||||||
.idea/
|
.idea/
|
||||||
|
.roo
|
||||||
|
|
||||||
# Environment files
|
# Environment files
|
||||||
.env
|
.env
|
||||||
|
9
frontend/chat_page.py
Normal file
9
frontend/chat_page.py
Normal file
@@ -0,0 +1,9 @@
|
|||||||
|
import gradio as gr
|
||||||
|
|
||||||
|
def chat_page():
|
||||||
|
with gr.Blocks() as demo:
|
||||||
|
gr.Markdown("## 聊天")
|
||||||
|
with gr.Row():
|
||||||
|
with gr.Column():
|
||||||
|
pass
|
||||||
|
return demo
|
9
frontend/setting_page.py
Normal file
9
frontend/setting_page.py
Normal file
@@ -0,0 +1,9 @@
|
|||||||
|
import gradio as gr
|
||||||
|
|
||||||
|
def setting_page():
|
||||||
|
with gr.Blocks() as demo:
|
||||||
|
gr.Markdown("## 设置")
|
||||||
|
with gr.Row():
|
||||||
|
with gr.Column():
|
||||||
|
pass
|
||||||
|
return demo
|
9
frontend/train_page.py
Normal file
9
frontend/train_page.py
Normal file
@@ -0,0 +1,9 @@
|
|||||||
|
import gradio as gr
|
||||||
|
|
||||||
|
def train_page():
|
||||||
|
with gr.Blocks() as demo:
|
||||||
|
gr.Markdown("## 微调")
|
||||||
|
with gr.Row():
|
||||||
|
with gr.Column():
|
||||||
|
pass
|
||||||
|
return demo
|
23
main.py
Normal file
23
main.py
Normal file
@@ -0,0 +1,23 @@
|
|||||||
|
import gradio as gr
|
||||||
|
from frontend.setting_page import setting_page
|
||||||
|
from frontend.chat_page import chat_page
|
||||||
|
from frontend.train_page import train_page
|
||||||
|
def main():
|
||||||
|
setting_demo = setting_page()
|
||||||
|
chat_demo = chat_page()
|
||||||
|
train_demo = train_page()
|
||||||
|
|
||||||
|
with gr.Blocks() as app:
|
||||||
|
gr.Markdown("# 基于文档驱动的自适应编码大模型微调框架")
|
||||||
|
with gr.Tabs():
|
||||||
|
with gr.TabItem("微调"):
|
||||||
|
train_demo.render()
|
||||||
|
with gr.TabItem("聊天"):
|
||||||
|
chat_demo.render()
|
||||||
|
with gr.TabItem("设置"):
|
||||||
|
setting_demo.render()
|
||||||
|
|
||||||
|
app.launch()
|
||||||
|
|
||||||
|
if __name__ == "__main__":
|
||||||
|
main()
|
@@ -1,2 +1,4 @@
|
|||||||
openai>=1.0.0
|
openai>=1.0.0
|
||||||
python-dotenv>=1.0.0
|
python-dotenv>=1.0.0
|
||||||
|
pydantic>=2.0.0
|
||||||
|
gradio>=3.0.0
|
4
schema/__init__.py
Normal file
4
schema/__init__.py
Normal file
@@ -0,0 +1,4 @@
|
|||||||
|
from .dataset import *
|
||||||
|
from .dataset_generation import APIProvider, LLMResponse, LLMRequest
|
||||||
|
from .md_doc import MarkdownNode
|
||||||
|
from .prompt_templeta import prompt_templeta
|
13
schema/md_doc.py
Normal file
13
schema/md_doc.py
Normal file
@@ -0,0 +1,13 @@
|
|||||||
|
from pydantic import BaseModel, Field
|
||||||
|
from typing import List, Optional
|
||||||
|
|
||||||
|
class MarkdownNode(BaseModel):
|
||||||
|
level: int = Field(default=0, description="节点层级")
|
||||||
|
title: str = Field(default="Root", description="节点标题")
|
||||||
|
content: Optional[str] = Field(default=None, description="节点内容")
|
||||||
|
children: List['MarkdownNode'] = Field(default_factory=list, description="子节点列表")
|
||||||
|
|
||||||
|
class Config:
|
||||||
|
arbitrary_types_allowed = True
|
||||||
|
|
||||||
|
MarkdownNode.model_rebuild()
|
@@ -1,28 +1,24 @@
|
|||||||
import re
|
import re
|
||||||
|
import sys
|
||||||
|
from pathlib import Path
|
||||||
|
|
||||||
class MarkdownNode:
|
# 添加项目根目录到sys.path
|
||||||
def __init__(self, level=0, title="Root"):
|
sys.path.append(str(Path(__file__).resolve().parent.parent))
|
||||||
self.level = level
|
from schema import MarkdownNode
|
||||||
self.title = title
|
|
||||||
self.content = "" # 使用字符串存储合并后的内容
|
|
||||||
self.children = []
|
|
||||||
|
|
||||||
def __repr__(self):
|
def add_child(parent, child):
|
||||||
return f"({self.level}) {self.title}"
|
parent.children.append(child)
|
||||||
|
|
||||||
def add_child(self, child):
|
def print_tree(node, indent=0):
|
||||||
self.children.append(child)
|
|
||||||
|
|
||||||
def print_tree(self, indent=0):
|
|
||||||
prefix = "│ " * (indent - 1) + "└─ " if indent > 0 else ""
|
prefix = "│ " * (indent - 1) + "└─ " if indent > 0 else ""
|
||||||
print(f"{prefix}{self.title}")
|
print(f"{prefix}{node.title}")
|
||||||
if self.content:
|
if node.content:
|
||||||
content_prefix = "│ " * indent + "├─ [内容]"
|
content_prefix = "│ " * indent + "├─ [内容]"
|
||||||
print(content_prefix)
|
print(content_prefix)
|
||||||
for line in self.content.split('\n'):
|
for line in node.content.split('\n'):
|
||||||
print("│ " * indent + "│ " + line)
|
print("│ " * indent + "│ " + line)
|
||||||
for child in self.children:
|
for child in node.children:
|
||||||
child.print_tree(indent + 1)
|
print_tree(child, indent + 1)
|
||||||
|
|
||||||
def parse_markdown(markdown):
|
def parse_markdown(markdown):
|
||||||
lines = markdown.split('\n')
|
lines = markdown.split('\n')
|
||||||
@@ -51,10 +47,10 @@ def parse_markdown(markdown):
|
|||||||
if match:
|
if match:
|
||||||
level = len(match.group(1))
|
level = len(match.group(1))
|
||||||
title = match.group(2)
|
title = match.group(2)
|
||||||
node = MarkdownNode(level, title)
|
node = MarkdownNode(level=level, title=title, content="", children=[])
|
||||||
while stack[-1].level >= level:
|
while stack[-1].level >= level:
|
||||||
stack.pop()
|
stack.pop()
|
||||||
stack[-1].add_child(node)
|
add_child(stack[-1], node)
|
||||||
stack.append(node)
|
stack.append(node)
|
||||||
else:
|
else:
|
||||||
if stack[-1].content:
|
if stack[-1].content:
|
||||||
@@ -65,9 +61,9 @@ def parse_markdown(markdown):
|
|||||||
|
|
||||||
if __name__=="__main__":
|
if __name__=="__main__":
|
||||||
# 从文件读取 Markdown 内容
|
# 从文件读取 Markdown 内容
|
||||||
with open("example.md", "r", encoding="utf-8") as f:
|
with open("workdir/example.md", "r", encoding="utf-8") as f:
|
||||||
markdown = f.read()
|
markdown = f.read()
|
||||||
|
|
||||||
# 解析 Markdown 并打印树结构
|
# 解析 Markdown 并打印树结构
|
||||||
root = parse_markdown(markdown)
|
root = parse_markdown(markdown)
|
||||||
root.print_tree()
|
print_tree(root)
|
||||||
|
Reference in New Issue
Block a user