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
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 52 |
|
| 53 |
if __name__ == "__main__":
|
| 54 |
-
|
| 55 |
-
with gr.Row():
|
| 56 |
-
with gr.Column(variant='panel', scale=5):
|
| 57 |
-
file = gr.File(label="Please upload a PDF or image", file_types=[".pdf", ".png", ".jpeg", "jpg"])
|
| 58 |
-
max_pages = gr.Slider(1, 10, 5, step=1, label="Max convert pages")
|
| 59 |
-
with gr.Row():
|
| 60 |
-
layout_mode = gr.Dropdown(["layoutlmv3", "doclayout_yolo"], label="Layout model", value="layoutlmv3")
|
| 61 |
-
language = gr.Dropdown(all_lang, label="Language", value="")
|
| 62 |
-
with gr.Row():
|
| 63 |
-
formula_enable = gr.Checkbox(label="Enable formula recognition", value=True)
|
| 64 |
-
is_ocr = gr.Checkbox(label="Force enable OCR", value=False)
|
| 65 |
-
table_enable = gr.Checkbox(label="Enable table recognition(test)", value=False)
|
| 66 |
-
with gr.Row():
|
| 67 |
-
change_bu = gr.Button("Convert")
|
| 68 |
-
clear_bu = gr.ClearButton(value="Clear")
|
| 69 |
-
pdf_show = PDF(label="PDF preview", interactive=True, height=800)
|
| 70 |
-
|
| 71 |
-
with gr.Column(variant='panel', scale=5):
|
| 72 |
-
output_file = gr.File(label="convert result", interactive=False)
|
| 73 |
-
with gr.Tabs():
|
| 74 |
-
with gr.Tab("Markdown rendering"):
|
| 75 |
-
md = gr.Markdown(label="Markdown rendering", height=900, show_copy_button=True,
|
| 76 |
-
latex_delimiters=latex_delimiters, line_breaks=True)
|
| 77 |
-
with gr.Tab("Markdown text"):
|
| 78 |
-
md_text = gr.TextArea(lines=45, show_copy_button=True)
|
| 79 |
-
file.upload(fn=to_pdf, inputs=file, outputs=pdf_show)
|
| 80 |
-
clear_bu.add([file, md, pdf_show, md_text, output_file, is_ocr, table_enable, language])
|
| 81 |
-
|
| 82 |
-
demo.launch()
|
|
|
|
| 1 |
import gradio as gr
|
| 2 |
+
|
| 3 |
+
def render_markdown(markdown_text):
|
| 4 |
+
"""返回markdown文本供Gradio的Markdown组件渲染"""
|
| 5 |
+
if not markdown_text.strip():
|
| 6 |
+
return "请在左侧输入Markdown文本..."
|
| 7 |
+
|
| 8 |
+
return markdown_text
|
| 9 |
+
|
| 10 |
+
# 默认示例markdown文本
|
| 11 |
+
default_markdown = """# Markdown编辑器演示
|
| 12 |
+
### 代码块示例
|
| 13 |
+
|
| 14 |
+
#### Python
|
| 15 |
+
```python
|
| 16 |
+
def hello_world():
|
| 17 |
+
print("Hello, World!")
|
| 18 |
+
for i in range(5):
|
| 19 |
+
print(f"Count: {i}")
|
| 20 |
+
return "欢迎使用Markdown编辑器"
|
| 21 |
+
```
|
| 22 |
+
|
| 23 |
+
#### JavaScript
|
| 24 |
+
```javascript
|
| 25 |
+
function greetUser(name) {
|
| 26 |
+
console.log(`Hello, ${name}!`);
|
| 27 |
+
const numbers = [1, 2, 3, 4, 5];
|
| 28 |
+
return numbers.map(n => n * 2);
|
| 29 |
+
}
|
| 30 |
+
```
|
| 31 |
+
|
| 32 |
+
#### HTML
|
| 33 |
+
```html
|
| 34 |
+
<!DOCTYPE html>
|
| 35 |
+
<html lang="zh-CN">
|
| 36 |
+
<head>
|
| 37 |
+
<meta charset="UTF-8">
|
| 38 |
+
<title>测试页面</title>
|
| 39 |
+
</head>
|
| 40 |
+
<body>
|
| 41 |
+
<h1 class="title">Hello World</h1>
|
| 42 |
+
<p id="content">这是一个测试页面</p>
|
| 43 |
+
</body>
|
| 44 |
+
</html>
|
| 45 |
+
```
|
| 46 |
+
|
| 47 |
+
#### CSS
|
| 48 |
+
```css
|
| 49 |
+
.title {
|
| 50 |
+
color: #2c3e50;
|
| 51 |
+
font-size: 2rem;
|
| 52 |
+
text-align: center;
|
| 53 |
+
margin-bottom: 20px;
|
| 54 |
+
}
|
| 55 |
+
|
| 56 |
+
#content {
|
| 57 |
+
background-color: #f8f9fa;
|
| 58 |
+
padding: 15px;
|
| 59 |
+
border-radius: 5px;
|
| 60 |
+
box-shadow: 0 2px 4px rgba(0,0,0,0.1);
|
| 61 |
+
}
|
| 62 |
+
```
|
| 63 |
+
|
| 64 |
+
#### JSON
|
| 65 |
+
```json
|
| 66 |
+
{
|
| 67 |
+
"name": "测试用户",
|
| 68 |
+
"age": 30,
|
| 69 |
+
"skills": ["Python", "JavaScript", "HTML", "CSS"],
|
| 70 |
+
"active": true,
|
| 71 |
+
"projects": [
|
| 72 |
+
{
|
| 73 |
+
"name": "Gradio应用",
|
| 74 |
+
"status": "进行中"
|
| 75 |
+
}
|
| 76 |
+
]
|
| 77 |
+
}
|
| 78 |
+
```
|
| 79 |
+
|
| 80 |
+
#### SQL
|
| 81 |
+
```sql
|
| 82 |
+
SELECT u.name, u.email, p.title
|
| 83 |
+
FROM users u
|
| 84 |
+
LEFT JOIN projects p ON u.id = p.user_id
|
| 85 |
+
WHERE u.active = true
|
| 86 |
+
AND u.created_date >= '2024-01-01'
|
| 87 |
+
ORDER BY u.name ASC, p.created_date DESC;
|
| 88 |
+
```
|
| 89 |
+
|
| 90 |
+
#### Bash/Shell
|
| 91 |
+
```bash
|
| 92 |
+
#!/bin/bash
|
| 93 |
+
|
| 94 |
+
# 设置变量
|
| 95 |
+
PROJECT_DIR="/home/user/project"
|
| 96 |
+
LOG_FILE="$PROJECT_DIR/app.log"
|
| 97 |
+
|
| 98 |
+
# 创建目录
|
| 99 |
+
mkdir -p $PROJECT_DIR
|
| 100 |
+
|
| 101 |
+
# 启动应用
|
| 102 |
+
echo "启动应用..." > $LOG_FILE
|
| 103 |
+
python app.py >> $LOG_FILE 2>&1 &
|
| 104 |
+
|
| 105 |
+
# 检查进程
|
| 106 |
+
if pgrep -f "python app.py" > /dev/null; then
|
| 107 |
+
echo "应用启动成功"
|
| 108 |
+
else
|
| 109 |
+
echo "应用启动失败"
|
| 110 |
+
fi
|
| 111 |
+
```
|
| 112 |
+
|
| 113 |
+
#### Java
|
| 114 |
+
```java
|
| 115 |
+
public class HelloWorld {
|
| 116 |
+
private String message;
|
| 117 |
+
|
| 118 |
+
public HelloWorld(String message) {
|
| 119 |
+
this.message = message;
|
| 120 |
+
}
|
| 121 |
+
|
| 122 |
+
public void greet() {
|
| 123 |
+
System.out.println("Hello, " + message + "!");
|
| 124 |
+
}
|
| 125 |
+
|
| 126 |
+
public static void main(String[] args) {
|
| 127 |
+
HelloWorld app = new HelloWorld("Gradio");
|
| 128 |
+
app.greet();
|
| 129 |
+
}
|
| 130 |
+
}
|
| 131 |
+
```
|
| 132 |
+
|
| 133 |
+
#### C++
|
| 134 |
+
```cpp
|
| 135 |
+
#include <iostream>
|
| 136 |
+
#include <vector>
|
| 137 |
+
#include <string>
|
| 138 |
+
|
| 139 |
+
class Greeter {
|
| 140 |
+
private:
|
| 141 |
+
std::string name;
|
| 142 |
+
|
| 143 |
+
public:
|
| 144 |
+
Greeter(const std::string& n) : name(n) {}
|
| 145 |
+
|
| 146 |
+
void sayHello() const {
|
| 147 |
+
std::cout << "Hello, " << name << "!" << std::endl;
|
| 148 |
+
}
|
| 149 |
+
};
|
| 150 |
+
|
| 151 |
+
int main() {
|
| 152 |
+
std::vector<std::string> names = {"Alice", "Bob", "Charlie"};
|
| 153 |
+
|
| 154 |
+
for (const auto& name : names) {
|
| 155 |
+
Greeter greeter(name);
|
| 156 |
+
greeter.sayHello();
|
| 157 |
+
}
|
| 158 |
+
|
| 159 |
+
return 0;
|
| 160 |
+
}
|
| 161 |
+
```
|
| 162 |
+
|
| 163 |
+
#### C
|
| 164 |
+
```c
|
| 165 |
+
#include <stdio.h>
|
| 166 |
+
#include <stdlib.h>
|
| 167 |
+
#include <string.h>
|
| 168 |
+
|
| 169 |
+
typedef struct {
|
| 170 |
+
char name[50];
|
| 171 |
+
int age;
|
| 172 |
+
} Person;
|
| 173 |
+
|
| 174 |
+
void print_person(Person* p) {
|
| 175 |
+
printf("姓名: %s, 年龄: %d\\n", p->name, p->age);
|
| 176 |
+
}
|
| 177 |
+
|
| 178 |
+
int main() {
|
| 179 |
+
Person person;
|
| 180 |
+
strcpy(person.name, "张三");
|
| 181 |
+
person.age = 25;
|
| 182 |
+
|
| 183 |
+
print_person(&person);
|
| 184 |
+
|
| 185 |
+
return 0;
|
| 186 |
+
}
|
| 187 |
+
```
|
| 188 |
+
|
| 189 |
+
#### Go
|
| 190 |
+
```go
|
| 191 |
+
package main
|
| 192 |
+
|
| 193 |
+
import (
|
| 194 |
+
"fmt"
|
| 195 |
+
"time"
|
| 196 |
+
)
|
| 197 |
+
|
| 198 |
+
type User struct {
|
| 199 |
+
Name string `json:"name"`
|
| 200 |
+
Age int `json:"age"`
|
| 201 |
+
Created time.Time `json:"created"`
|
| 202 |
+
}
|
| 203 |
+
|
| 204 |
+
func (u User) Greet() string {
|
| 205 |
+
return fmt.Sprintf("Hello, I'm %s, %d years old", u.Name, u.Age)
|
| 206 |
+
}
|
| 207 |
+
|
| 208 |
+
func main() {
|
| 209 |
+
user := User{
|
| 210 |
+
Name: "Go开发者",
|
| 211 |
+
Age: 30,
|
| 212 |
+
Created: time.Now(),
|
| 213 |
+
}
|
| 214 |
+
|
| 215 |
+
fmt.Println(user.Greet())
|
| 216 |
+
}
|
| 217 |
+
```
|
| 218 |
+
|
| 219 |
+
#### Rust
|
| 220 |
+
```rust
|
| 221 |
+
use std::collections::HashMap;
|
| 222 |
+
|
| 223 |
+
#[derive(Debug)]
|
| 224 |
+
struct Person {
|
| 225 |
+
name: String,
|
| 226 |
+
age: u32,
|
| 227 |
+
}
|
| 228 |
+
|
| 229 |
+
impl Person {
|
| 230 |
+
fn new(name: &str, age: u32) -> Self {
|
| 231 |
+
Person {
|
| 232 |
+
name: name.to_string(),
|
| 233 |
+
age,
|
| 234 |
+
}
|
| 235 |
+
}
|
| 236 |
+
|
| 237 |
+
fn greet(&self) -> String {
|
| 238 |
+
format!("Hello, I'm {} and I'm {} years old", self.name, self.age)
|
| 239 |
+
}
|
| 240 |
+
}
|
| 241 |
+
|
| 242 |
+
fn main() {
|
| 243 |
+
let mut people = HashMap::new();
|
| 244 |
+
|
| 245 |
+
let alice = Person::new("Alice", 30);
|
| 246 |
+
let bob = Person::new("Bob", 25);
|
| 247 |
+
|
| 248 |
+
people.insert("alice", alice);
|
| 249 |
+
people.insert("bob", bob);
|
| 250 |
+
|
| 251 |
+
for (key, person) in &people {
|
| 252 |
+
println!("{}: {}", key, person.greet());
|
| 253 |
+
}
|
| 254 |
+
}
|
| 255 |
+
```
|
| 256 |
+
|
| 257 |
+
#### PHP
|
| 258 |
+
```php
|
| 259 |
+
<?php
|
| 260 |
+
|
| 261 |
+
class User {
|
| 262 |
+
private $name;
|
| 263 |
+
private $email;
|
| 264 |
+
|
| 265 |
+
public function __construct($name, $email) {
|
| 266 |
+
$this->name = $name;
|
| 267 |
+
$this->email = $email;
|
| 268 |
+
}
|
| 269 |
+
|
| 270 |
+
public function getName() {
|
| 271 |
+
return $this->name;
|
| 272 |
+
}
|
| 273 |
+
|
| 274 |
+
public function getEmail() {
|
| 275 |
+
return $this->email;
|
| 276 |
+
}
|
| 277 |
+
|
| 278 |
+
public function getInfo() {
|
| 279 |
+
return [
|
| 280 |
+
'name' => $this->name,
|
| 281 |
+
'email' => $this->email,
|
| 282 |
+
'created' => date('Y-m-d H:i:s')
|
| 283 |
+
];
|
| 284 |
+
}
|
| 285 |
+
}
|
| 286 |
+
|
| 287 |
+
$user = new User("张三", "[email protected]");
|
| 288 |
+
echo "用户: " . $user->getName() . "\\n";
|
| 289 |
+
print_r($user->getInfo());
|
| 290 |
+
|
| 291 |
+
?>
|
| 292 |
+
```
|
| 293 |
+
|
| 294 |
+
#### XML
|
| 295 |
+
```xml
|
| 296 |
+
<?xml version="1.0" encoding="UTF-8"?>
|
| 297 |
+
<users xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
|
| 298 |
+
<user id="1" active="true">
|
| 299 |
+
<name>张三</name>
|
| 300 |
+
<email>[email protected]</email>
|
| 301 |
+
<profile>
|
| 302 |
+
<age>30</age>
|
| 303 |
+
<skills>
|
| 304 |
+
<skill level="advanced">Python</skill>
|
| 305 |
+
<skill level="intermediate">JavaScript</skill>
|
| 306 |
+
<skill level="beginner">Go</skill>
|
| 307 |
+
</skills>
|
| 308 |
+
</profile>
|
| 309 |
+
</user>
|
| 310 |
+
<user id="2" active="false">
|
| 311 |
+
<name>李四</name>
|
| 312 |
+
<email>[email protected]</email>
|
| 313 |
+
<profile>
|
| 314 |
+
<age>25</age>
|
| 315 |
+
<skills>
|
| 316 |
+
<skill level="expert">Java</skill>
|
| 317 |
+
<skill level="advanced">SQL</skill>
|
| 318 |
+
</skills>
|
| 319 |
+
</profile>
|
| 320 |
+
</user>
|
| 321 |
+
</users>
|
| 322 |
+
```
|
| 323 |
+
|
| 324 |
+
#### YAML
|
| 325 |
+
```yaml
|
| 326 |
+
# 应用配置文件
|
| 327 |
+
app:
|
| 328 |
+
name: "Gradio Markdown Editor"
|
| 329 |
+
version: "1.0.0"
|
| 330 |
+
debug: true
|
| 331 |
+
|
| 332 |
+
server:
|
| 333 |
+
host: "0.0.0.0"
|
| 334 |
+
port: 7860
|
| 335 |
+
workers: 4
|
| 336 |
+
|
| 337 |
+
database:
|
| 338 |
+
host: localhost
|
| 339 |
+
port: 5432
|
| 340 |
+
name: myapp
|
| 341 |
+
user: admin
|
| 342 |
+
password: secret123
|
| 343 |
+
pool_size: 10
|
| 344 |
+
|
| 345 |
+
features:
|
| 346 |
+
- markdown_preview
|
| 347 |
+
- syntax_highlighting
|
| 348 |
+
- auto_save
|
| 349 |
+
- themes
|
| 350 |
+
|
| 351 |
+
users:
|
| 352 |
+
- name: "管理员"
|
| 353 |
+
role: admin
|
| 354 |
+
permissions:
|
| 355 |
+
- read
|
| 356 |
+
- write
|
| 357 |
+
- delete
|
| 358 |
+
- name: "编辑者"
|
| 359 |
+
role: editor
|
| 360 |
+
permissions:
|
| 361 |
+
- read
|
| 362 |
+
- write
|
| 363 |
+
```
|
| 364 |
+
"""
|
| 365 |
+
|
| 366 |
+
# 创建Gradio界面
|
| 367 |
+
with gr.Blocks(
|
| 368 |
+
title="Markdown实时编辑器",
|
| 369 |
+
) as demo:
|
| 370 |
+
|
| 371 |
+
gr.Markdown("# 📝 Markdown实时编辑器")
|
| 372 |
+
gr.Markdown("在左侧输入Markdown文本,右侧会实时显示渲染效果")
|
| 373 |
+
|
| 374 |
+
with gr.Row():
|
| 375 |
+
with gr.Column(scale=1):
|
| 376 |
+
markdown_input = gr.Textbox(
|
| 377 |
+
label="输入Markdown文本",
|
| 378 |
+
placeholder="在这里输入你的Markdown内容...",
|
| 379 |
+
max_lines=40,
|
| 380 |
+
value=default_markdown,
|
| 381 |
+
)
|
| 382 |
+
|
| 383 |
+
with gr.Column(scale=1):
|
| 384 |
+
markdown_output = gr.Markdown(
|
| 385 |
+
label="Markdown渲染效果",
|
| 386 |
+
value=default_markdown,
|
| 387 |
+
height=800,
|
| 388 |
+
)
|
| 389 |
+
|
| 390 |
+
# 添加一些快捷按钮
|
| 391 |
+
with gr.Row():
|
| 392 |
+
clear_btn = gr.Button("🗑️ 清空", variant="secondary", size="sm")
|
| 393 |
+
example_btn = gr.Button("📄 加载示例", variant="secondary", size="sm")
|
| 394 |
+
|
| 395 |
+
# 绑定事件
|
| 396 |
+
markdown_input.change(
|
| 397 |
+
fn=render_markdown,
|
| 398 |
+
inputs=markdown_input,
|
| 399 |
+
outputs=markdown_output
|
| 400 |
+
)
|
| 401 |
+
|
| 402 |
+
clear_btn.click(
|
| 403 |
+
fn=lambda: ("", "请在左侧输入Markdown文本..."),
|
| 404 |
+
outputs=[markdown_input, markdown_output]
|
| 405 |
+
)
|
| 406 |
+
|
| 407 |
+
example_btn.click(
|
| 408 |
+
fn=lambda: (default_markdown, default_markdown),
|
| 409 |
+
outputs=[markdown_input, markdown_output]
|
| 410 |
+
)
|
| 411 |
|
| 412 |
if __name__ == "__main__":
|
| 413 |
+
demo.launch()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|