当前位置: 首页 > news >正文

文本分类模型

# !/usr/bin/env python3 import argparse import asyncio import json import os import random import time from datetime import datetime from pathlib import Path import httpx from openai import AsyncOpenAI # ============ 配置 ============ # LLM_BASE_URL = os.getenv("LLM_BASE_URL") # LLM_MODEL = os.getenv("LLM_MODEL") LLM_API_KEY = os.getenv("LLM_API_KEY") or "empty" LLM_TIMEOUT = float(os.getenv("LLM_TIMEOUT", "30")) # ============ 对象种类 ============ CATEGORIES = ["徽章", "戒指", "动物", "人物", "其他"] CATEGORIES_STR = "、".join(CATEGORIES) SYSTEM_PROMPT = f"""你是一个文本分类专家。根据给定的文生图提示词,判断主要对象的种类。 可选种类:{CATEGORIES_STR} 严格只输出一个词,不要解释。""" async def classify(text: str) -> str: """分类提示词""" if not text.strip(): return "" client = AsyncOpenAI(api_key=LLM_API_KEY, base_url=LLM_BASE_URL, http_client=httpx.AsyncClient(timeout=LLM_TIMEOUT), ) try: resp = await client.chat.completions.create(model=LLM_MODEL, messages=[{"role": "system", "content": SYSTEM_PROMPT}, {"role": "user", "content": text.strip()}, ], temperature=0.1, max_tokens=20, ) result = resp.choices[0].message.content.strip() # 提取第一个词 for cat in CATEGORIES: if cat in result: return cat return result finally: await client.close() async def main(): parser = argparse.ArgumentParser() parser.add_argument("--output", type=Path, default=None) parser.add_argument("--seed", type=int, default=None) args = parser.parse_args() test_prompts = [ # 人物 """A single 3D designer art toy figure, presented in a strict horizontal triptych layout with left side view, middle front view, and right rear view. Strictly limited to a palette of exactly 4 pure colors: 1. Pure white for the head, gloves, and boots; 2. Dark ultramarine blue for the torso, arms, and legs; 3. Crimson red for the flowing cape; 4. Silver-grey for the facial mask details and chest logo.""", # 徽章 """A beautifully crafted enamel pin badge, featuring a detailed dragon design in gold and red colors, with subtle metallic sheen, professional product photography, white background, high resolution, studio lighting.""", # 戒指 """A stunning platinum engagement ring with a 2-carat diamond center stone, surrounded by smaller pavé-set diamonds, intricate filigree details on the band, elegant jewelry photography, soft natural lighting, macro shot, 8K.""", # 动物 """A majestic golden eagle soaring through the sky with wings fully extended, dramatic sunset background, sharp focus on feathers, hyper-realistic wildlife photography, National Geographic style, 8K, cinematic composition.""", # 其他 """A futuristic skyscraper with a sleek glass facade, reflecting the surrounding cityscape, dramatic night lighting, long exposure photography, architectural marvel, modern minimalist design, high resolution, 8K.""", # 其他 """A delicious gourmet burger on a wooden table, perfectly chargrilled beef patty, melted cheddar cheese, crispy bacon, fresh lettuce and tomato, steam rising, warm ambient lighting, food photography, shallow depth of field, 8K, mouth-watering.""", ] results = [] # 逐个测试 for i, prompt in enumerate(test_prompts, 1): total_start = time.time() predicted = await classify(prompt) results.append({"predicted": predicted}) print(f"{i} {predicted} {time.time() - total_start:.2f}") if __name__ == "__main__": asyncio.run(main())
http://www.jsqmd.com/news/1373805/

相关文章:

  • Krea 2 Identity Edit完整指南:如何使用这款革命性的AI图像编辑模型改变创作方式
  • VSCode远程开发实战:SSH连接、环境配置与高效工作流
  • 有温度的科技产品,也要先过隐私和信任这一关
  • MAA助手:明日方舟全自动挂机终极指南,解放双手轻松长草!
  • 无名杀网页版实战指南:构建现代化三国杀游戏体验
  • 论文高分秘诀✨专业科研绘图,零基础一键出图|直接商用✅
  • Glean部署教程:Docker Compose一键启动,轻松管理服务依赖
  • 遮挡剔除全解析:PVS、HiZ、软光栅与引擎实现对比
  • 2026年8月苏州市吴中区联通1000M宽带攻略与避坑指南 - 找卡家园
  • 海量原片处理进阶指南:常规调整大小路径局限突显,全本地化工作流构建成破局点 - 资讯报道
  • 终极百度网盘直链解析指南:如何3分钟搭建个人高速下载站
  • AI 执行型智能体 OpenClaw 搭建全流程,实现文件管理与浏览器自动化(含安装包)
  • Steam ROM Manager:五分钟掌握批量游戏导入与美术资源管理的终极指南
  • 中国著名有影响力的权威市场地位认证研究机构公司
  • 揭秘微信视频号直播监控:3大核心技术解析与实战指南
  • AnythingLLM 学习
  • 2026年8月苏州市吴中区联通500M宽带我的真实避坑攻略 - 找卡家园
  • XNB文件处理终极指南:5分钟掌握Stardew Valley游戏资源修改
  • 外贸企业批量采购网易企业邮箱,2026年销售中心电话哪里找? - 选型|行业|价格|案例
  • 数据中台进入治理决胜期:2026 国内七大服务商能力测评榜单
  • 如何用DashPlayer实现英语学习的终极突破:从被动输入到主动输出的完整指南
  • 2026萌宠养殖基地优选**|这3家自有养殖基地,羊驼、小矮马、水豚、浣熊一站式供应,萌宠租赁供应回收全包 - 产品推荐官
  • 如何利用JupyterLab-nvdashboard的时间序列刷选功能深入分析GPU性能瓶颈
  • 零代码有声书制作:用ebook2audiobook轻松实现电子书转语音
  • Agent Governance Toolkit与Realme Pay集成:支付安全中的AI代理治理
  • 科研人入门必备:CiteSpace 6.4.R2 保姆级安装指南
  • 轻松掌握SoundCloud音乐下载:3步高效管理你的音乐收藏
  • 5个核心优势解析:为什么IOPaint是开源AI图像修复的终极选择
  • 5分钟快速上手:用Local-NotebookLM将PDF文档转换成专业播客的终极指南 [特殊字符]
  • 5个突破性方法:用AI大模型彻底改变Verilog硬件设计体验