Skip to content

Commit 4c821b7

Browse files
committed
Initial commit
0 parents  commit 4c821b7

125 files changed

Lines changed: 12129 additions & 0 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

.gitignore

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
# Logs
2+
logs
3+
*.log
4+
npm-debug.log*
5+
yarn-debug.log*
6+
yarn-error.log*
7+
pnpm-debug.log*
8+
lerna-debug.log*
9+
10+
node_modules
11+
.DS_Store
12+
dist
13+
dist-ssr
14+
coverage
15+
*.local
16+
17+
/cypress/videos/
18+
/cypress/screenshots/
19+
20+
# Editor directories and files
21+
.vscode/*
22+
!.vscode/extensions.json
23+
.idea
24+
*.suo
25+
*.ntvs*
26+
*.njsproj
27+
*.sln
28+
*.sw?
29+
30+
*.tsbuildinfo

README.md

Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
# ✍️ HandText
2+
3+
[📄 中文](./README_zh.md)
4+
5+
## 📖 Project Introduction
6+
7+
🎉 Built with **Vue3** and **Flask**, this project is a refactored version of [📄 handwriting-web](https://github.com/14790897/handwriting-web), with optimized code structure and enhanced features.
8+
9+
---
10+
11+
## 🚀 Key Features
12+
13+
- **Handwriting Recognition**: Upload images and extract handwritten text. 🖼️➡️📝
14+
- **Handwriting Generation**: Convert input text into handwritten-style images or save as PDF files. 📄➡️🖋️
15+
- **Text Editing**: Supports file upload and editing. ✂️📋💾
16+
- **Multi-language Support**: Supports both Chinese and English. 🌐
17+
- **Theme Switching**: Switch between light and dark themes. 🌞🌙
18+
19+
---
20+
21+
## 🛠️ Tech Stack
22+
23+
### Frontend
24+
- **Framework**: Vue3
25+
- **State Management**: Pinia
26+
- **UI Library**: Element Plus
27+
- **Routing**: Vue-Router
28+
- **Internationalization**: vue-i18n
29+
- **HTTP Library**: axios
30+
31+
### Backend
32+
- **Framework**: Flask
33+
- **File Handling**: Supports image upload, text generation, and file storage.
34+
- **API**: Provides handwriting recognition and text generation functionalities.
35+
36+
---
37+
38+
## 🚀 Quick Start
39+
40+
### Frontend Deployment
41+
42+
```bash
43+
1. Clone the project
44+
git clone https://github.com/mingchen666/HandText.git
45+
cd frontend
46+
47+
2. Install dependencies
48+
npm install
49+
50+
3. Start the development server
51+
npm run dev
52+
53+
4. Build for production
54+
npm run build
55+
```
56+
57+
### Backend Deployment
58+
```bash
59+
1. Navigate to the backend directory
60+
cd backend
61+
62+
2. Install dependencies
63+
pip install -r requirements.txt
64+
65+
3. Fill in environment variables in the .env file
66+
67+
4. Start the development server
68+
python app.py
69+
70+
```
71+
72+
## 📜 License
73+
74+
MIT License

README_zh.md

Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
# ✍️ HandText
2+
3+
[📄 English](./README.md)
4+
5+
## 📖 项目简介
6+
7+
🎉使用 **Vue3****Flask**框架,
8+
基于[📄 handwriting-web](https://github.com/14790897/handwriting-web)进行重构,优化代码结构、增强部分功能
9+
10+
---
11+
12+
## 🚀 主要功能
13+
14+
- **手写文字识别**:支持上传图片并提取其中的手写文字。🖼️➡️📝
15+
- **手写字体生成**:将输入的文本转换为手写风格的图片或保存为PDF文件。📄➡️🖋️
16+
- **文本编辑**:支持文件上传编辑功能。✂️📋💾
17+
- **多语言支持**:支持中英文切换。🌐
18+
- **主题切换**:支持亮色和暗色主题切换。🌞🌙
19+
20+
---
21+
22+
## 🛠️ 技术栈
23+
24+
### 前端
25+
- **框架**:Vue3
26+
- **状态管理**:Pinia
27+
- **UI 组件库**:Element Plus
28+
- **路由管理**:Vue-Router
29+
- **国际化**:vue-i18n
30+
- **HTTP库**:axios
31+
32+
### 后端
33+
- **框架**:Flask
34+
- **文件处理**:支持图片上传、文本生成和文件存储。
35+
- **API 接口**:提供手写文字识别、文本生成等功能。
36+
37+
---
38+
39+
## 🚀 快速开始
40+
41+
### 前端部署
42+
43+
44+
```bash
45+
46+
1. 克隆项目
47+
git clone https://github.com/mingchen666/HandText.git
48+
cd frontend
49+
50+
1. 安装依赖
51+
npm install
52+
53+
3. 启动开发服务器
54+
npm run dev
55+
56+
4. 打包
57+
npm run build
58+
```
59+
60+
### 后端部署
61+
```bash
62+
63+
1. 进入后端目录
64+
cd backend
65+
66+
2. 安装依赖
67+
pip install -r requirements.txt
68+
69+
3. 在env文件中填写环境变量
70+
71+
3. 启动开发服务器
72+
python app.py
73+
74+
```
75+
76+
## 📜 许可证
77+
78+
本项目采用 MIT 许可证

backend/.env

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
base_url=https://xxxx.com/v1
2+
api_key=sk-xxxxxx
3+
version_model=glm-4v-flash

backend/app.py

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
# 导入Flask
2+
from flask import jsonify
3+
4+
from app import create_app
5+
6+
app=create_app()
7+
8+
9+
@app.errorhandler(429)
10+
def ratelimit_handler(e):
11+
return jsonify({
12+
"error": "Too Many Requests",
13+
"message": "You have exceeded the allowed number of requests. Please try again later.",
14+
"details": str(e.description)
15+
}), 429
16+
17+
if __name__ == '__main__':
18+
# 启动服务器
19+
app.run(debug=True)
20+
# run() 参数
21+
# debug=True 默认值,自动检测代码的修改,并重新加载服务器
22+
# port=5000 默认值,端口号
23+
# host='0.0.0.0' 默认值,监听所有ip地址

backend/app/__init__.py

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
from flask import Flask, jsonify
2+
from flask_cors import CORS
3+
from flask_limiter import Limiter
4+
from flask_limiter.util import get_remote_address
5+
from flask_restful import Api
6+
from .api.urls import initialize_routes
7+
# from .config import Config
8+
from .extensions import init_exts
9+
10+
'''
11+
CORS(app, resources={
12+
r"/api/*": {
13+
"origins": ["http://example.com", "http://localhost:3000"],
14+
"methods": ["GET", "POST"],
15+
"allow_headers": ["Content-Type"]
16+
}
17+
})
18+
'''
19+
20+
def create_app():
21+
22+
app = Flask(__name__)
23+
# app.config.from_object(Config)
24+
# db_url = 'mysql+pymysql://root:xiaoluo@localhost:3306/flaskdb'
25+
# 配置数据库链接路径url
26+
# app.config['SQLALCHEMY_DATABASE_URI'] = db_url
27+
# 可选:禁用追踪修改,减少内存消耗
28+
# app.config['SQLALCHEMY_TRACK_MODIFICATIONS'] = False
29+
init_exts(app)
30+
31+
32+
# 初始化路由
33+
api = Api(app)
34+
initialize_routes(api)
35+
# 配置跨域
36+
CORS(app)
37+
# CORS(app, resources={r"/*": {"origins": "*"}})
38+
# 自定义 429 错误处理
39+
40+
41+
return app

backend/app/api/__init__.py

Whitespace-only changes.

backend/app/api/fonts.py

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
from flask import jsonify
2+
from flask_restful import Resource, reqparse
3+
from werkzeug.exceptions import BadRequest
4+
5+
from .response import ApiResponse
6+
from ..utils.file import get_fonts_list
7+
from ..utils.log import global_logger
8+
9+
# 创建一个请求解析器
10+
parser = reqparse.RequestParser()
11+
parser.add_argument('title', type=str, required=True,location='args',
12+
help='Title is required and must be a string')
13+
14+
15+
class FontsResource(Resource):
16+
# 获取字体列表
17+
def get(self):
18+
try:
19+
# 解析请求体中的参数
20+
# args = parser.parse_args()
21+
# title = args['title']
22+
try:
23+
filenames = get_fonts_list(directory='app/public/fonts')
24+
# logger.info(f"filenames: {filenames}")
25+
if filenames == []:
26+
return ApiResponse.error('字体文件未找到!')
27+
except Exception as e:
28+
print(e)
29+
return ApiResponse.error('系统发送错误,请稍后再试',500)
30+
# return {
31+
# "code": 200,
32+
# "message": "success",
33+
# "data": filenames
34+
# }
35+
return jsonify(filenames)
36+
# return ApiResponse.success(filenames)
37+
except BadRequest as e:
38+
print(e.data)
39+
global_logger.info("搞什么飞机")
40+
error_message = e.data.get('message', 'Bad Request')
41+
# 返回自定义响应
42+
return ApiResponse.error(error_message, 400)
43+
# return ApiResponse.error('系统发送错误,请稍后再试',500)
44+
except Exception as e:
45+
# 捕获并处理异常
46+
global_logger.error(f"An error occurred: {str(e)}")
47+
return {'message': 'Internal Server Error', 'error': str(e)}, 500

0 commit comments

Comments
 (0)