网站性能,网站页面设计素材,企业搜索引擎优化,企查查企业信息查询网官网前言
本文介绍「星火杯」认知大模型场景创新赛中的落选项目- AI命理分析系统#xff0c;属于个人娱乐练手。总结提炼了往期文章精华并发掘出新的知识。 包括本地部署版本和Web在线版本#xff0c;两种打包方式基于 半自动化使用.bat手动打包迁移python项目
如何把 Gradio …前言
本文介绍「星火杯」认知大模型场景创新赛中的落选项目- AI命理分析系统属于个人娱乐练手。总结提炼了往期文章精华并发掘出新的知识。 包括本地部署版本和Web在线版本两种打包方式基于 半自动化使用.bat手动打包迁移python项目
如何把 Gradio 应用上传到 Hugging Face 往期回顾 从零开始-与大语言模型对话学技术-gradio篇1 从零开始-与大语言模型对话学技术-gradio篇2 从零开始-与大语言模型对话学技术-gradio篇3
项目简介
本项目是一个集成化的AI命理分析系统,实现了星座解析、塔罗解牌、八字合婚等多种智能化命理服务。系统通过Python和Gradio实现了交互式的网页界面,用户只需要输入必要个人信息,即可获得智能的命理运势分析。 Github链接
使用说明
最新Web在线版本使用
Web公开版本已在Hugging Face开源点击链接即可在线使用不同于本地版本你必须配置自己的星火APl全平台可用 hugging face连接
本地部署版本
打开AI命理分析系统V4.0进入虚拟python环境自动检测依赖安装环境并运行程序 显示如下提示表示编译运行成功打开这个连接即可进入系统 你也可以打开GUI.py在末尾将demo.launch()修改为 demo.launch(shareTrue) 那么你会额外获取一个随机的公开链接你可以在任何设备上输入网址访问这个AI命理分析系统 Running on local URL: http://127.0.0.1:7860 Running on public URL: https://436fda53710f62fbbc.gradio.live This share link expires in 72 hours. For free permanent hosting and GPU upgrades, run gradio deploy from Terminal to deploy to Spaces (https://huggingface.co/spaces)
功能列表 接入星火认知大模型:你可以选择使用我的API或者自行配置 配置好API才能使用后续功能! AI星座解读:输入个人信息,获得当前月星座运势解析 AI塔罗牌解读:用户提问,系统抽取塔罗牌进行占卜 AI八字合婚分析:输入双方八字,智能匹配分析婚姻 AI兔年运势预测:基于八字分析未来财运、事业等 AI公司命理解析:根据个人信息以及公司名称和行业,分析公司运势。 AI姓名配对:评估两人姓名匹配程度 AI月老姻缘:分析最佳配对对象 AI八字精批:输入八字信息获得对应运势的专业精批。 AI姓名分析:分析输入的姓名对个人命运的影响。 AI紫薇斗数解析:根据八字信息计算紫薇数值并进行解读
完整代码
app.py
# -*- coding utf-8 -*-# Time : 2023/7/31 19:33
# Author : CSDN:FriKlogff
# File : app.py
# Software: PyCharm
# Function: 请输入项目功能import os
os.system(python -m pip install -i https://mirrors.aliyun.com/pypi/simple/ --upgrade pip setuptools
pip install -i https://mirrors.aliyun.com/pypi/simple/ websocket
pip install -i https://mirrors.aliyun.com/pypi/simple/ websocket-client
pip install -i https://mirrors.aliyun.com/pypi/simple/ gradio
pip install -i https://mirrors.aliyun.com/pypi/simple/ sxtwl
)
from PublicFunctions import *
import gradio as gr# 定义星座选项
signs [白羊座, 金牛座, 双子座, 巨蟹座, 狮子座, 处女座,天秤座, 天蝎座, 射手座, 摩羯座, 水瓶座, 双鱼座]
cards_num [1, 2, 3, 4, 5]
months [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12]
days [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]
hours [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23]
# 使用 Gradio 的模块化组件构建包含五个选项卡的界面
with gr.Blocks() as demo:with gr.Tab(星火api配置):xh_input [gr.components.Textbox(labelappid),gr.components.Textbox(labelapi_secret),gr.components.Textbox(labelapi_key),gr.components.Textbox(labelgpt_url)]xh_output gr.components.Textbox(label点击提交返回配置情况请自行配置星火大模型API再使用后续功能)xh_button gr.components.Button(提交)xh_button.click(xh_api, inputsxh_input, outputsxh_output)with gr.Tab(AI星座解读):horoscope_input [gr.components.Radio(choices[男, 女], label性别),gr.components.Textbox(label姓名),gr.components.Number(label出生年份),gr.components.Dropdown(months, label出生月份),gr.components.Dropdown(days, label出生日),gr.components.Dropdown(hours, label出生时辰),gr.components.Dropdown(signs, label选择您的星座)]horoscope_output gr.components.Textbox(label星座解读(由于我们的解析是由AI生成的结果仅供娱乐如果不成功请多试几次))horoscope_button gr.components.Button(提交)horoscope_button.click(horoscope_reading, inputshoroscope_input, outputshoroscope_output)with gr.Tab(AI塔罗牌解读):tarot_input [gr.components.Textbox(label你想问的问题),gr.components.Dropdown(cards_num, label你想抽几张牌),]tarot_output gr.components.Textbox(label塔罗牌解析(由于我们的解析是由AI生成的结果仅供娱乐如果不成功请多试几次))upload_button gr.components.Button(抽取)upload_button.click(tarot_reading, inputstarot_input, outputstarot_output)with gr.Tab(AI八字合婚分析):marriage_input [gr.components.Textbox(label新郎姓名),gr.components.Number(label出生年份),gr.components.Dropdown(months, label出生月份),gr.components.Dropdown(days, label出生日),gr.components.Dropdown(hours, label出生时辰),gr.components.Textbox(label新娘姓名),gr.components.Number(label出生年份),gr.components.Dropdown(months, label出生月份),gr.components.Dropdown(days, label出生日),gr.components.Dropdown(hours, label出生时辰),]marriage_analysis_output gr.components.Textbox(label婚姻分析(由于我们的解析是由AI生成的结果仅供娱乐如果不成功请多试几次))analyze_button gr.components.Button(马上测算)analyze_button.click(marriage_bazi_analysis,inputsmarriage_input,outputsmarriage_analysis_output)with gr.Tab(AI兔年运程预测):birth_year_input [gr.components.Radio(choices[男, 女], label性别),gr.components.Textbox(label姓名),gr.components.Number(label出生年份),gr.components.Dropdown(months, label出生月份),gr.components.Dropdown(days, label出生日),gr.components.Dropdown(hours, label出生时辰),]prediction_output gr.components.Textbox(label运程预测(由于我们的解析是由AI生成的结果仅供娱乐如果不成功请多试几次))predict_button gr.components.Button(预测运势)predict_button.click(rabbit_year_prediction,inputsbirth_year_input,outputsprediction_output)with gr.Tab(AI公司命理解析):company_name_input [gr.components.Radio(choices[男, 女], label性别),gr.components.Textbox(label姓名),gr.components.Number(label出生年份),gr.components.Dropdown(months, label出生月份),gr.components.Dropdown(days, label出生日),gr.components.Dropdown(hours, label出生时辰),gr.components.Textbox(label公司名称),gr.components.Textbox(label所属行业)]name_analysis_output gr.components.Textbox(label命理分析(由于我们的解析是由AI生成的结果仅供娱乐如果不成功请多试几次))analyze_button gr.components.Button(分析)analyze_button.click(company_name_analysis,inputscompany_name_input,outputsname_analysis_output)with gr.Tab(AI姓名配对):name1_input [gr.components.Textbox(label姓名1),gr.components.Textbox(label姓名2),]matching_output gr.components.Textbox(label配对结果(由于我们的解析是由AI生成的结果仅供娱乐如果不成功请多试几次))match_button gr.components.Button(分析配对)match_button.click(name_compatibility,inputsname1_input,outputsmatching_output)with gr.Tab(AI月老姻缘):yue_lau_input [gr.components.Radio(choices[男, 女], label性别),gr.components.Textbox(label姓名),gr.components.Number(label出生年份),gr.components.Dropdown(months, label出生月份),gr.components.Dropdown(days, label出生日),gr.components.Dropdown(hours, label出生时辰),]affinity_output gr.components.Textbox(label姻缘分析(由于我们的解析是由AI生成的结果仅供娱乐如果不成功请多试几次))analyze_button gr.components.Button(分析姻缘)analyze_button.click(yue_lau_affinity,inputsyue_lau_input,outputsaffinity_output)with gr.Tab(AI八字精批):bazi_input [gr.components.Radio(choices[男, 女], label性别),gr.components.Textbox(label姓名),gr.components.Number(label出生年份),gr.components.Dropdown(months, label出生月份),gr.components.Dropdown(days, label出生日),gr.components.Dropdown(hours, label出生时辰),]analysis_output gr.components.Textbox(label精批结果(由于我们的解析是由AI生成的结果仅供娱乐如果不成功请多试几次))batch_button gr.components.Button(八字精批)batch_button.click(bazi_analysis,inputsbazi_input,outputsanalysis_output)with gr.Tab(AI姓名分析):name_input [gr.components.Radio(choices[男, 女], label性别),gr.components.Textbox(label姓名)]name_output gr.components.Textbox(label命理分析(由于我们的解析是由AI生成的结果仅供娱乐如果不成功请多试几次))analyze_button gr.components.Button(分析姓名)analyze_button.click(name_analysis,inputsname_input,outputsname_output)with gr.Tab(AI紫薇斗数解析):zhiwei_input [gr.components.Radio(choices[男, 女], label性别),gr.components.Textbox(label姓名),gr.components.Number(label出生年份),gr.components.Dropdown(months, label出生月份),gr.components.Dropdown(days, label出生日),gr.components.Dropdown(hours, label出生时辰),]zhiwei_output gr.components.Textbox(label紫薇解读(由于我们的解析是由AI生成的结果仅供娱乐如果不成功请多试几次))zhiwei_button gr.components.Button(解读运势)zhiwei_button.click(zhiwei_analysis,inputszhiwei_input,outputszhiwei_output)
demo.launch()
# demo.launch(shareTrue)PublicFunctions.py
# -*- coding utf-8 -*-# Time : 2023/7/31 19:35
# Author : CSDN:FriKlogff
# File : PublicFunctions.py
# Software: PyCharm
# Function: 请输入项目功能
import os
os.system(python -m pip install -i https://mirrors.aliyun.com/pypi/simple/ --upgrade pip setuptools
pip install -i https://mirrors.aliyun.com/pypi/simple/ websocket
pip install -i https://mirrors.aliyun.com/pypi/simple/ websocket-client
pip install -i https://mirrors.aliyun.com/pypi/simple/ gradio
pip install -i https://mirrors.aliyun.com/pypi/simple/ sxtwl
)
import sxtwl
from XhApi import *
import XhApi# print(XhApi.response_content)
Gan [甲, 乙, 丙, 丁, 戊, 己, 庚, 辛, 壬, 癸]
Zhi [子, 丑, 寅, 卯, 辰, 巳, 午, 未, 申, 酉, 戌, 亥]
appid
api_secret
api_key
gpt_url def generate_bazi(year, month, day, hour):year int(year)month int(month)day int(day)hour int(hour)date sxtwl.fromSolar(year, month, day)# 获取年柱yTG date.getYearGZ()ganzhi_year Gan[yTG.tg] Zhi[yTG.dz]# 获取月柱mTG date.getMonthGZ()ganzhi_month Gan[mTG.tg] Zhi[mTG.dz]# 获取日柱dTG date.getDayGZ()ganzhi_day Gan[dTG.tg] Zhi[dTG.dz]# 获取时柱dayGan dTG.tghTG sxtwl.getShiGz(dayGan, hour)ganzhi_hour Gan[hTG.tg] Zhi[hTG.dz]return f{ganzhi_year}年{ganzhi_month}月{ganzhi_day}日{ganzhi_hour}时def xh_api( user_appid, user_api_secret, user_api_key, user_gpt_url):global appid, api_secret, api_key, gpt_urlif user_appid or user_api_secret or user_api_key or user_gpt_url :return any api cannot be empty!appid str(user_appid)api_secret str(user_api_secret)api_key str(user_api_key)gpt_url str(user_gpt_url)# print(type(appid), type(api_secret), type(api_key), type(gpt_url))# print(appid, api_secret, api_key, gpt_url)return appid appid\napi_secret api_secret\napi_key api_key\ngpt_url gpt_urldef horoscope_reading(sex, name, birth_year, birth_month, birth_day, birth_hour, star):XhApi.response_content global appid, api_secret, api_key, gpt_urlbirth_year str(int(birth_year))if sex is None:return sex cannot be empty!if name or birth_year or birth_month or birth_day or birth_hour or star :return Name or birth_year or birth_month or birth_day or star cannot be empty!if birth_year 0:return 0 is not a suitable value of birth_year!template 假设你是一位专业的星座运势分析师,根据客户提供的出生日期和时间,你需要进行以下几方面的详细分析工作:\n \1. 分析用户的星座及性格特点\n \2. 根据月球周期判断事业和学业趋势\n \3. 提供维持提升感情的建议\n \4. 预测财务收入和投资趋势\n \5. 提出健康保健建议\n \作为专业分析师,你需要用通俗语言解释理论,并提供专业建议\ntemplate 客户信息:\ntemplate 性别:{sex}\ntemplate 姓名:{name}\ntemplate 星座:{star}\ntemplate 出生日期:{birth_year}-{birth_month}-{birth_day}-{birth_hour}question template.format(sexsex, namename, birth_yearbirth_year, birth_monthbirth_month, birth_daybirth_day,birth_hourbirth_hour,starstar)# print(appid, api_secret, api_key, gpt_url)return main(appidappid,api_secretapi_secret,api_keyapi_key,gpt_urlgpt_url,questionquestion)def tarot_reading(question, num_cards):XhApi.response_content global appid, api_secret, api_key, gpt_urlif question or num_cards is None or num_cards 0:return question ornum_cards cannot be empty!template 假设你是一位专业的塔罗牌占卜师。用户提出的问题是:{question}。template 根据用户的问题,你需要为TA抽取{num_cards}张塔罗牌,template 解读每张塔罗牌的含义,template 综合牌面分析用户所问的问题,template 并根据占卜结果给予专业的建议。template 具体来说,你需要:\ntemplate 1. 为用户抽取指定数量的塔罗牌\ntemplate 2. 逐一解析每张塔罗牌的符号和含义\ntemplate 3. 综合各牌面意义,对用户提问进行占卜分析\ntemplate 4. 根据占卜结果,给出专业建议或预言question template.format(questionquestion, num_cardsint(num_cards))return main(appidappid,api_secretapi_secret,api_keyapi_key,gpt_urlgpt_url,questionquestion)def marriage_bazi_analysis(name_husband, birth_year_husband, birth_month_husband, birth_day_husband, birth_hour_husband,name_wife, birth_year_wife, birth_month_wife, birth_day_wife, birth_hour_wife):XhApi.response_content global appid, api_secret, api_key, gpt_urlbirth_year_husband int(birth_year_husband)birth_year_wife int(birth_year_wife)if name_husband or birth_year_husband or birth_month_husband or birth_day_husband or birth_hour_husband \or name_wife or birth_year_wife or birth_month_wife or birth_day_wife or birth_hour_wife :return Name or birth_year or birth_month or birth_day cannot be empty!if birth_year_husband 0 or birth_year_wife 0:return 0 is not a suitable value of birth_year!bazi_husband generate_bazi(birth_year_husband, birth_month_husband, birth_day_husband, birth_hour_husband)bazi_wife generate_bazi(birth_year_wife, birth_month_wife, birth_day_wife, birth_hour_wife)# print(bazi_wife, bazi_husband)template 假设你是一位专业的八字合婚分析师,你正在为一对新人进行八字合婚分析。 \分析基于八字五行、十神、四柱的原理判断两人姻缘。重点看天格、年格五行相生相克。 \以下是他们的基本信息\ntemplate 新郎信息:\ntemplate 姓名:{name_husband}\ntemplate 出生日期:{birth_year_husband}-{birth_month_husband}-{birth_day_husband}\n # 根据用户的选择生成问题template 八字:{bazi_husband}\ntemplate 新娘信息:\ntemplate 姓名:{name_wife}\ntemplate 出生日期:{birth_year_wife}-{birth_month_wife}-{birth_day_wife}\n # 根据用户的选择生成问题template 八字:{bazi_wife}\ntemplate 作为资深的合婚分析师,你需要:\ntemplate 1. 分析两人八字五行相生相克关系\ntemplate 2. 比较两人十神是否匹配\ntemplate 3. 检查四柱运势是否协调\ntemplate 4. 给出姻缘匹配度及建议\nquestion template.format(name_husbandname_husband, name_wifename_wife, bazi_husbandbazi_husband,bazi_wifebazi_wife, birth_year_husbandbirth_year_husband,birth_month_husbandbirth_month_husband, birth_day_husbandbirth_day_husband,birth_year_wifebirth_year_wife, birth_month_wifebirth_month_wife,birth_day_wifebirth_day_wife)return main(appidappid,api_secretapi_secret,api_keyapi_key,gpt_urlgpt_url,questionquestion)# 兔年运程
def rabbit_year_prediction(sex, name, birth_year, birth_month, birth_day, birth_hour):XhApi.response_content global appid, api_secret, api_key, gpt_urlbirth_year int(birth_year)bazi generate_bazi(int(birth_year), int(birth_month), int(birth_day), int(birth_hour))if sex is None:return sex cannot be empty!if name or birth_year or birth_month or birth_day or birth_hour :return Name or birth_year or birth_month or birth_day cannot be empty!if birth_year 0:return 0 is not a suitable value of birth_year!template 假设你是一位专业的命理师,仔细分析客户信息,结合通胜原理,考量客户的五行八字、天干合化等,对在兔年客户的事业、财富、姻缘等命局进行预测,并给出建议。template \n客户信息:\ntemplate 性别:{sex}\ntemplate 姓名:{name}\ntemplate 出生日期:{birth_year}-{birth_month}-{birth_day}-{birth_hour}\ntemplate 八字:{bazi}\ntemplate 具体来说,你需要:\ntemplate 1. 检查客户八字和五行属性\ntemplate 2. 分析天干合化对命局的影响\ntemplate 3. 考量通胜原理对运势的作用\ntemplate 4. 对事业、财富、姻缘等命局给出预测\ntemplate 5. 提供专业建议question template.format(sexsex, namename, birth_yearbirth_year, birth_monthbirth_month, birth_daybirth_day,birth_hourbirth_hour, bazibazi)return main(appidappid,api_secretapi_secret,api_keyapi_key,gpt_urlgpt_url,questionquestion)# 公司测名
def company_name_analysis(sex, name, birth_year, birth_month, birth_day, birth_hour, company_name, industry):XhApi.response_content global appid, api_secret, api_key, gpt_urlbirth_year int(birth_year)if sex is None:return sex cannot be empty!if name or birth_year or birth_month or birth_day or birth_hour or company_name or industry :return Name or birth_year or birth_month or birth_day or company_name or industry cannot be empty!if birth_year 0:return 0 is not a suitable value of birth_year!template 假设你是一位公司命理专家,根据立命八字学说,姓名、公司名与行业之间存在相生相克的关系, \需要综合考量五行、八卦、吉凶等理论,分析它们之间的互动对企业发展的影响, \发掘其中蕴含的福禄文星,提出建议以改善财运。template \n客户信息:\ntemplate 性别:{sex}\ntemplate 姓名:{name}\ntemplate 出生日期:{birth_year}-{birth_month}-{birth_day}-{birth_hour}\ntemplate 公司名:{company_name}\ntemplate 行业:{industry}\ntemplate 具体来说,你需要:\ntemplate 1. 分析客户姓名五行属性\ntemplate 2. 考量公司名五行与行业五行关系\ntemplate 3. 判断相生相克对企业运势的影响\ntemplate 4. 发掘姓名、公司名蕴含的福星\ntemplate 5. 提出改善企业财运的专业建议question template.format(sexsex, namename, birth_yearbirth_year, birth_monthbirth_month, birth_daybirth_day,birth_hourbirth_hour,company_namecompany_name, industryindustry)return main(appidappid,api_secretapi_secret,api_keyapi_key,gpt_urlgpt_url,questionquestion)# 姓名配对
def name_compatibility(name1, name2):XhApi.response_content global appid, api_secret, api_key, gpt_urlif name1 or name2 :return name1 or name2 cannot be empty!template 假设你是一位姓名学专家。用户提供了两人的姓名:{name1}和{name2}。template 作为专家,你需要分析他们两人姓名的五行、笔画等特征,template 判断姓名间的五行关系是否协调、笔画关系是否匹配,template 从姓名学角度出发,分析这两人的姓名是否配对。template 具体来说,你需要:\ntemplate 1. 分析{name1}的五行属性和笔画数\ntemplate 2. 分析{name2}的五行属性和笔画数\ntemplate 3. 判断两人姓名的五行相生相克关系\ntemplate 4. 判断两人姓名笔画数差是否合适\ntemplate 5. 从姓名学角度给出配对建议\ntemplate 最后要给出专业建议,说明这对姓名的搭配优劣势。question template.format(name1name1, name2name2)return main(appidappid,api_secretapi_secret,api_keyapi_key,gpt_urlgpt_url,questionquestion)# 月老姻缘
def yue_lau_affinity(sex, name, birth_year, birth_month, birth_day, birth_hour):XhApi.response_content global appid, api_secret, api_key, gpt_urlbirth_year int(birth_year)bazi generate_bazi(int(birth_year), int(birth_month), int(birth_day), int(birth_hour))if sex is None:return sex cannot be empty!if name or birth_year or birth_month or birth_day or birth_hour :return Name or birth_year or birth_month or birth_day cannot be empty!if birth_year 0:return 0 is not a suitable value of birth_year!template 假设你是一位月老姻缘专家。有客户需要你的帮助,其信息如下:\ntemplate 性别:{sex}\ntemplate 姓名:{name}\ntemplate 出生日期:{birth_year}-{birth_month}-{birth_day}-{birth_hour}\ntemplate 八字:{bazi}\ntemplate 作为月老专家,你需要基于客户的姓名、性别、出生日期等信息,template 来分析其感情运势、最佳配对对象,template 给出专业的建议,帮助客户找到适合的另一半。template 具体来说,你需要:\ntemplate 1. 分析客户八字姻缘格局\ntemplate 2. 考量姓名数字对婚姻的影响\ntemplate 3. 判断最佳配对对象的特征\ntemplate 4. 提出改善感情运势的建议question template.format(sexsex, namename, birth_yearbirth_year, birth_monthbirth_month, birth_daybirth_day,birth_hourbirth_hour, bazibazi)return main(appidappid,api_secretapi_secret,api_keyapi_key,gpt_urlgpt_url,questionquestion)# 八字精批
def bazi_analysis(sex, name, birth_year, birth_month, birth_day, birth_hour):XhApi.response_content global appid, api_secret, api_key, gpt_urlbirth_year int(birth_year)if sex is None:return sex cannot be empty!if name or birth_year or birth_month or birth_day :return Name or birth_year or birth_month or birth_day cannot be empty!if birth_year 0:return 0 is not a suitable value of birth_year!bazi generate_bazi(int(birth_year), int(birth_month), int(birth_day), int(birth_hour))template 假设你是一位资深的八字命理师。有客户需要你对其八字进行专业精批,其信息如下:\ntemplate 性别:{sex}\ntemplate 姓名:{name}\ntemplate 八字:{bazi}\ntemplate 作为八字命理专家,你需要根据客户的八字,template 分析事业财运、健康等方面的运势趋势,template 具体来说,你需要:\ntemplate 1. 检查天干五行对事业财运的影响\ntemplate 2. 分析八字各宫协调性和局部格局\ntemplate 3. 指出八字优势和劣势\ntemplate 4. 提出合理的改善建议question template.format(sexsex, namename, bazibazi)return main(appidappid,api_secretapi_secret,api_keyapi_key,gpt_urlgpt_url,questionquestion)def zhiwei_analysis(sex, name, birth_year, birth_month, birth_day, birth_hour):XhApi.response_content global appid, api_secret, api_key, gpt_urlbirth_year int(birth_year)if sex is None:return sex cannot be empty!if name or birth_year or birth_month or birth_day :return Name or birth_year or birth_month or birth_day cannot be empty!if birth_year 0:return 0 is not a suitable value of birth_year!# print(sex, name, birth_year, birth_month, birth_day)bazi generate_bazi(int(birth_year), int(birth_month), int(birth_day), int(birth_hour))template 假设你是一位紫薇斗数专家,接收到客户的出生八字后,你会依次完成以下步骤:\n \1. 计算该八字的紫微星位置,代表其总体运势\n \2. 分析年柱运程,判断事业财运\n \3. 分析月柱运程,判断感情运\n \4. 分析日柱运程,判断健康运\n \5. 综合四柱运势对该客户的综合运势做出详细的预言分析\n \客户信息\n \性别{sex}\n \姓名{name}\n \八字为{bazi}question template.format(sexsex, namename, bazibazi)return main(appidappid,api_secretapi_secret,api_keyapi_key,gpt_urlgpt_url,questionquestion)# 姓名分析def name_analysis(sex, name):XhApi.response_content global appid, api_secret, api_key, gpt_urlif sex is None:return sex cannot be empty!if name :return Name cannot be empty!template 假设你是一位姓名学专家,请根据客户的姓名,分析其一生运势。\ntemplate 要点包括:\ntemplate - 姓名的谐音是否吉利\ntemplate - 姓名笔画多寡对品性的影响\ntemplate - 单名双名优劣\ntemplate 客户的姓名为 {name},性别为{sex},分析对其事业、婚姻、健康等方面的影响,并提出建议。template 具体来说,你需要\ntemplate 1. 分析客户姓名谐音\ntemplate 2. 判断姓名笔画数命理含义\ntemplate 3. 讨论单名双名特点\ntemplate 4. 分析姓名对运势各方面的影响\ntemplate 5. 提出改善命运的专业建议question template.format(namename, sexsex)return main(appidappid,api_secretapi_secret,api_keyapi_key,gpt_urlgpt_url,questionquestion)
XhApi.py
# -*- coding utf-8 -*-# Time : 2023/7/20 12:37
# Author : CSDN:FriKlogff
# File : XhApi.py
# Software: PyCharm
# Function: 星火大模型APIimport os
os.system(python -m pip install -i https://mirrors.aliyun.com/pypi/simple/ --upgrade pip setuptools
pip install -i https://mirrors.aliyun.com/pypi/simple/ websocket
pip install -i https://mirrors.aliyun.com/pypi/simple/ websocket-client
pip install -i https://mirrors.aliyun.com/pypi/simple/ gradio
pip install -i https://mirrors.aliyun.com/pypi/simple/ sxtwl
)
import _thread as thread # 导入线程模块
import base64 # 导入base64编码模块
import datetime # 导入datetime模块
import hashlib # 导入hashlib模块
import hmac # 导入hmac模块
import json # 导入json模块
from urllib.parse import urlparse # 从urllib.parse导入urlparse用于url解析
import ssl # 导入ssl模块
from datetime import datetime # 从datetime导入datetime类
from time import mktime # 从time导入mktime用于生成时间戳
from urllib.parse import urlencode # 从urllib.parse导入urlencode用于编码请求参数
from wsgiref.handlers import format_date_time # 从wsgiref.handlers导入format_date_time用于格式化时间import websocket # 导入websocket模块response_content # 请求参数类
class Ws_Param:# 初始化def __init__(self, APPID, APIKey, APISecret, gpt_url):self.APPID APPID # 应用IDself.APIKey APIKey # API Keyself.APISecret APISecret # API Secretself.host urlparse(gpt_url).netloc # 从url解析出hostself.path urlparse(gpt_url).path # 从url解析出pathself.gpt_url gpt_url # 完整的url# 生成签名和url的方法def create_url(self):now datetime.now() # 当前时间date format_date_time(mktime(now.timetuple())) # 格式化的时间戳# 拼接签名原文signature_origin host: self.host \nsignature_origin date: date \nsignature_origin GET self.path HTTP/1.1# 生成签名signature_sha hmac.new(self.APISecret.encode(utf-8), signature_origin.encode(utf-8),digestmodhashlib.sha256).digest()signature_sha_base64 base64.b64encode(signature_sha).decode(encodingutf-8)# 生成授权headerauthorization_origin fapi_key{self.APIKey}, algorithmhmac-sha256, headershost date request-line, signature{signature_sha_base64}authorization base64.b64encode(authorization_origin.encode(utf-8)).decode(encodingutf-8)# 生成url参数字典v {authorization: authorization,date: date,host: self.host}# 构造最终urlurl self.gpt_url ? urlencode(v)return url# 收到websocket错误的处理
def on_error(ws, error):print(### error:, error)# 收到websocket关闭的处理
def on_close(ws):print(### closed ###)# 收到websocket连接建立的处理
def on_open(ws):thread.start_new_thread(run, (ws,))# 发送请求的方法
def run(ws, *args):data json.dumps(gen_params(appidws.appid, questionws.question))ws.send(data)# 收到websocket消息的处理
def on_message(ws, message):print(message)data json.loads(message)code data[header][code]if code ! 0:print(f请求错误: {code}, {data})ws.close()else:choices data[payload][choices]status choices[status]content choices[text][0][content]print(content, end)global response_contentresponse_content contentif status 2:ws.close()# 生成请求参数
def gen_params(appid, question):通过appid和用户的提问来生成请参数data {header: {app_id: appid,uid: 1234},parameter: {chat: {domain: general,random_threshold: 0.5,max_tokens: 2048,auditing: default}},payload: {message: {text: [{role: user, content: question}]}}}return datadef main(appid, api_key, api_secret, gpt_url, question):wsParam Ws_Param(appid, api_key, api_secret, gpt_url)websocket.enableTrace(False)wsUrl wsParam.create_url()ws websocket.WebSocketApp(wsUrl, on_messageon_message, on_erroron_error, on_closeon_close, on_openon_open)ws.appid appidws.question questionws.run_forever(sslopt{cert_reqs: ssl.CERT_NONE})return response_content