File size: 2,044 Bytes
1c2b077
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
import gradio as gr
from fastapi import FastAPI
import uvicorn
import logging

# 配置日志
logging.basicConfig(level=logging.INFO, format='%(asctime)s %(levelname)s %(message)s')
logger = logging.getLogger(__name__)

# 创建FastAPI应用
app = FastAPI()

# 使用app/database.py中的数据库实例
from app.database import db

def init_milvus():
    """初始化 Milvus 数据库"""
    db.init_collection()

# 图像处理相关功能已经在app/image_utils.py中实现



# 使用app/services.py中的服务
from app.services import sticker_service

# 使用app/services.py中的服务,不再需要重复实现这些功能

# 导入UI模块
from app.ui import StickerUI

# 创建Gradio界面

# FastAPI 路由
@app.get("/api/list_stickers")
def api_get_stickers():

    sticker_list = sticker_service.get_all_stickers()
    print('>>> GET Sticker_list', sticker_list)
    return sticker_list


@app.post("/api/search_stickers")
async def api_search_stickers(request: dict):
    description = request.get('description', '')
    if len(description) > 0:
        sticker_list = sticker_service.search_stickers(
            description=description,
            limit=1,
        )
        print('>>> GET Sticker_list', sticker_list)
        return sticker_list
    return []  # 当描述为空时返回空列表



@app.post("/api/delete_sticker")
async def api_delete_stickers(request: dict):
    """Delete sticker by ID"""
    try:
        sticker_id = request.get('id')
        if not sticker_id:
            return {"status": "error", "message": "Missing sticker ID"}
            
        result = sticker_service.delete_sticker(sticker_id)
        return {"status": "success", "message": result}
    except Exception as e:
        logger.error(f"Delete failed: {str(e)}")
        return {"status": "error", "message": f"Delete failed: {str(e)}"}



# 启动应用
if __name__ == "__main__":
    init_milvus()
    ui = StickerUI()
    app = gr.mount_gradio_app(app, ui.create_ui(), '/')
    uvicorn.run(app, host="0.0.0.0", port=7860)