尧图网络 高端网站定制 · 原创设计
免费咨询热线
400-888-6620
免费获取方案
文本分类模型
# !/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_keyLLM_API_KEY, base_urlLLM_BASE_URL, http_clienthttpx.AsyncClient(timeoutLLM_TIMEOUT), ) try: resp await client.chat.completions.create(modelLLM_MODEL, messages[{role: system, content: SYSTEM_PROMPT}, {role: user, content: text.strip()}, ], temperature0.1, max_tokens20, ) 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, typePath, defaultNone) parser.add_argument(--seed, typeint, defaultNone) 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())
RELATED

相关推荐

NLP 模型评测与多任务性能对比:发布前检查失败路径与回滚

NLP 模型评测与多任务性能对比:发布前检查失败路径与回滚

NLP 模型评测与多任务性能对比:发布前检查失败路径与回滚 1. 离线高分:先排除训练集与评测集重叠 评测结果异常升高时,应先检查训练集、验证集和测试集的来源、版本与文本重叠。可在公开或合成语料上使用 N-gram 或 MinHash 检测,…

📅 2026/11/24 8:40:01
2025届必备的AI辅助论文平台横评

2025届必备的AI辅助论文平台横评

Ai论文网站排名(开题报告、文献综述、降aigc率、降重综合对比) TOP1. 千笔AI TOP2. aipasspaper TOP3. 清北论文 TOP4. 豆包 TOP5. kimi TOP6. deepseek 正变得越来越受众多学生青睐的, 能用来撰写学术文章的免费AI论文工具, 因人工智能迅速发展,…

📅 2026/11/1 8:23:56
喜马拉雅FM下载器:跨平台音频保存解决方案

喜马拉雅FM下载器:跨平台音频保存解决方案

喜马拉雅FM下载器:跨平台音频保存解决方案 【免费下载链接】xmly-downloader-qt5 喜马拉雅FM专辑下载器. 支持VIP与付费专辑. 使用GoQt5编写(Not Qt Binding). 项目地址: https://gitcode.com/gh_mirrors/xm/xmly-downloader-qt5 还在为喜马拉雅VIP到期后无法…

📅 2026/11/6 16:53:56
MORE NEWS

更多资讯

📰

南昌县哪里考电工证 全国通用怎么转过来

南昌县哪里考电工证 全国通用怎么转过来 之前考的证在外省能不能转过来?这是很多从外地来南昌县打工的电工兄弟最关心的问题。别急,今天咱就掰扯清楚,讲讲南昌县哪里考电工证、全国通用怎么转、办理流程到底怎么走,还有河南房建工程从业者怎么避坑。…

📰

电工证能维修电梯吗值不值得考?实操考试心里没底怕挂科

电工证能维修电梯吗值不值得考?实操考试心里没底怕挂科 实操考试心里没底怕挂科,这几乎是每个想考电工证的人最真实的感受。特别是当你说出“电工证能维修电梯吗”这个问题时,很多人会疑惑,这个证到底有没有用?值不值得考?如果你也是这类人,那你一定需…

📰

特种作业操作证技巧:怕考不过白交培训费?掌握这些技巧再不怕

特种作业操作证技巧:怕考不过白交培训费?掌握这些技巧再不怕 你是不是也在担心,花了几千块报了特种作业操作证的培训班,结果考试还是没过,钱白花了?这年头,考证难,考证费不便宜,怕考不过白交培训费,成了很多人的心理阴影。…

📰

阿城电工证查询哪家强?证书过期了不知道怎么复审延期?复审多少钱你得知道!

阿城电工证查询哪家强?证书过期了不知道怎么复审延期?复审多少钱你得知道! 证书过期了不知道怎么复审延期?别急,先搞清楚你的阿城电工证查询路径,再看清楚复审费用到底 多少钱…

📰

长安哪里有考电工证多久拿证?外省证能转吗?三门峡朋友听我说

长安哪里有考电工证多久拿证?外省证能转吗?三门峡朋友听我说 之前考的证在外省能不能转过来?你不是一个人,三门峡的很多电工朋友也遇到过这个问题。尤其是从外省过来打工的,手里拿着低压电工证、高压电工证,但又怕在长安这边不被认可。其实,只要符合…

📰

银川考特种作业操作证千万别踩坑,外省证怎么转过来?

银川考特种作业操作证千万别踩坑,外省证怎么转过来? 之前考的证在外省能不能转过来?银川考特种作业操作证千万别踩坑,很多人因为不了解政策,花了不少冤枉钱。其实,特种作业操作证的报考、考试、复审流程虽然看起来复杂,但只要你掌握了正确的信息,就能…

TODAY

今日更新

THIS WEEK

本周精选

THIS MONTH

本月热门

读完文章,想聊聊您的网站?

告诉我们您的行业与需求,资深顾问一对一梳理方案与报价,全程免费。

📞 💬