Files
backend/backend/app/ai/model/image_text.py
2025-11-22 10:26:30 +08:00

34 lines
1.9 KiB
Python
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
from typing import Optional
from sqlalchemy import BigInteger, Text, String, Integer, DateTime, ForeignKey
from sqlalchemy.dialects.mysql import JSON as MySQLJSON
from sqlalchemy.orm import mapped_column, Mapped
from backend.common.model import snowflake_id_key, Base
class ImageText(Base):
"""
图片识别出的文本内容
每张图片可能包含多个文本,这些文本是图片识别的结果
支持关联文章句子image_id 为可选以支持独立的文章句子文本
"""
__tablename__ = 'image_text'
id: Mapped[snowflake_id_key] = mapped_column(BigInteger, init=False, primary_key=True)
image_id: Mapped[Optional[int]] = mapped_column(BigInteger, ForeignKey('image.id'), nullable=True, comment="关联的图片ID")
article_sentence_id: Mapped[Optional[int]] = mapped_column(BigInteger, ForeignKey('article_sentence.id'), nullable=True, comment="关联的文章句子ID")
content: Mapped[str] = mapped_column(Text, nullable=False, comment="文本内容")
standard_audio_id: Mapped[Optional[int]] = mapped_column(BigInteger, ForeignKey('file.id'), nullable=True, comment="标准朗读音频文件ID")
ipa: Mapped[Optional[str]] = mapped_column(String(100), default=None, comment="ipa")
zh: Mapped[Optional[str]] = mapped_column(String(100), default=None, comment="中文")
position: Mapped[Optional[dict]] = mapped_column(MySQLJSON, default=None, comment="文本在图片中的位置信息或文章中的位置信息")
dict_level: Mapped[Optional[str]] = mapped_column(String(20), default=None, comment="词典等级")
source: Mapped[Optional[str]] = mapped_column(String(20), default=None, comment="文本来源 (ref_word/description/article)")
info: Mapped[Optional[dict]] = mapped_column(MySQLJSON, default=None, comment="附加信息")
# 表参数 - 包含所有必要的约束
__table_args__ = (
)