机器翻译模型(Hugging Face官网) 模型翻译api服务代码 # 离线翻译服务代码 # -*-coding:utf-8-*-import os import json import logging from logging.handlers import RotatingFileHandler from datetime import datetime from flask import Flask, request,jsonify from gevent import pywsgi from transformers import pipeline, AutoModelWithLMHead, AutoTokenizer import warnings, requests warnings.filterwarnings('ignore')try:print('\n 翻译服务\n')#日志级别# debug->info->warning->error->critical# 创建日志记录器logger = logging.getLogger('requests')logger.setLevel(logging.DEBUG)# 创建 RotatingFileHandler 处理器#模型下载:https://huggingface.co/Helsinki-NLPlog_filename = './logs/'+datetime.now().strftime('%Y%m%d') + '.log'file_handler = RotatingFileHandler(log_filename, maxBytes=1024