XMWAI 0.3.26__tar.gz → 0.3.27__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Potentially problematic release.
This version of XMWAI might be problematic. Click here for more details.
- {xmwai-0.3.26/XMWAI.egg-info → xmwai-0.3.27}/PKG-INFO +1 -1
- xmwai-0.3.27/XMWAI/web_core.py +287 -0
- {xmwai-0.3.26 → xmwai-0.3.27/XMWAI.egg-info}/PKG-INFO +1 -1
- {xmwai-0.3.26 → xmwai-0.3.27}/XMWAI.egg-info/SOURCES.txt +1 -0
- {xmwai-0.3.26 → xmwai-0.3.27}/setup.py +1 -1
- {xmwai-0.3.26 → xmwai-0.3.27}/LICENSE.txt +0 -0
- {xmwai-0.3.26 → xmwai-0.3.27}/MANIFEST.in +0 -0
- {xmwai-0.3.26 → xmwai-0.3.27}/README.md +0 -0
- {xmwai-0.3.26 → xmwai-0.3.27}/XMWAI/__init__.py +0 -0
- {xmwai-0.3.26 → xmwai-0.3.27}/XMWAI/bomb_core.py +0 -0
- {xmwai-0.3.26 → xmwai-0.3.27}/XMWAI/core.py +0 -0
- {xmwai-0.3.26 → xmwai-0.3.27}/XMWAI/file/__init__.py +0 -0
- {xmwai-0.3.26 → xmwai-0.3.27}/XMWAI/file/idiom.json +0 -0
- {xmwai-0.3.26 → xmwai-0.3.27}/XMWAI/gif/0.gif +0 -0
- {xmwai-0.3.26 → xmwai-0.3.27}/XMWAI/gif/1.gif +0 -0
- {xmwai-0.3.26 → xmwai-0.3.27}/XMWAI/gif/10.gif +0 -0
- {xmwai-0.3.26 → xmwai-0.3.27}/XMWAI/gif/11.gif +0 -0
- {xmwai-0.3.26 → xmwai-0.3.27}/XMWAI/gif/12.gif +0 -0
- {xmwai-0.3.26 → xmwai-0.3.27}/XMWAI/gif/13.gif +0 -0
- {xmwai-0.3.26 → xmwai-0.3.27}/XMWAI/gif/14.gif +0 -0
- {xmwai-0.3.26 → xmwai-0.3.27}/XMWAI/gif/15.gif +0 -0
- {xmwai-0.3.26 → xmwai-0.3.27}/XMWAI/gif/16.gif +0 -0
- {xmwai-0.3.26 → xmwai-0.3.27}/XMWAI/gif/17.gif +0 -0
- {xmwai-0.3.26 → xmwai-0.3.27}/XMWAI/gif/18.gif +0 -0
- {xmwai-0.3.26 → xmwai-0.3.27}/XMWAI/gif/19.gif +0 -0
- {xmwai-0.3.26 → xmwai-0.3.27}/XMWAI/gif/2.gif +0 -0
- {xmwai-0.3.26 → xmwai-0.3.27}/XMWAI/gif/20.gif +0 -0
- {xmwai-0.3.26 → xmwai-0.3.27}/XMWAI/gif/21.gif +0 -0
- {xmwai-0.3.26 → xmwai-0.3.27}/XMWAI/gif/22.gif +0 -0
- {xmwai-0.3.26 → xmwai-0.3.27}/XMWAI/gif/23.gif +0 -0
- {xmwai-0.3.26 → xmwai-0.3.27}/XMWAI/gif/24.gif +0 -0
- {xmwai-0.3.26 → xmwai-0.3.27}/XMWAI/gif/25.gif +0 -0
- {xmwai-0.3.26 → xmwai-0.3.27}/XMWAI/gif/26.gif +0 -0
- {xmwai-0.3.26 → xmwai-0.3.27}/XMWAI/gif/27.gif +0 -0
- {xmwai-0.3.26 → xmwai-0.3.27}/XMWAI/gif/28.gif +0 -0
- {xmwai-0.3.26 → xmwai-0.3.27}/XMWAI/gif/29.gif +0 -0
- {xmwai-0.3.26 → xmwai-0.3.27}/XMWAI/gif/3.gif +0 -0
- {xmwai-0.3.26 → xmwai-0.3.27}/XMWAI/gif/30.gif +0 -0
- {xmwai-0.3.26 → xmwai-0.3.27}/XMWAI/gif/31.gif +0 -0
- {xmwai-0.3.26 → xmwai-0.3.27}/XMWAI/gif/32.gif +0 -0
- {xmwai-0.3.26 → xmwai-0.3.27}/XMWAI/gif/33.gif +0 -0
- {xmwai-0.3.26 → xmwai-0.3.27}/XMWAI/gif/34.gif +0 -0
- {xmwai-0.3.26 → xmwai-0.3.27}/XMWAI/gif/35.gif +0 -0
- {xmwai-0.3.26 → xmwai-0.3.27}/XMWAI/gif/36.gif +0 -0
- {xmwai-0.3.26 → xmwai-0.3.27}/XMWAI/gif/37.gif +0 -0
- {xmwai-0.3.26 → xmwai-0.3.27}/XMWAI/gif/38.gif +0 -0
- {xmwai-0.3.26 → xmwai-0.3.27}/XMWAI/gif/39.gif +0 -0
- {xmwai-0.3.26 → xmwai-0.3.27}/XMWAI/gif/4.gif +0 -0
- {xmwai-0.3.26 → xmwai-0.3.27}/XMWAI/gif/40.gif +0 -0
- {xmwai-0.3.26 → xmwai-0.3.27}/XMWAI/gif/41.gif +0 -0
- {xmwai-0.3.26 → xmwai-0.3.27}/XMWAI/gif/42.gif +0 -0
- {xmwai-0.3.26 → xmwai-0.3.27}/XMWAI/gif/43.gif +0 -0
- {xmwai-0.3.26 → xmwai-0.3.27}/XMWAI/gif/44.gif +0 -0
- {xmwai-0.3.26 → xmwai-0.3.27}/XMWAI/gif/45.gif +0 -0
- {xmwai-0.3.26 → xmwai-0.3.27}/XMWAI/gif/46.gif +0 -0
- {xmwai-0.3.26 → xmwai-0.3.27}/XMWAI/gif/47.gif +0 -0
- {xmwai-0.3.26 → xmwai-0.3.27}/XMWAI/gif/48.gif +0 -0
- {xmwai-0.3.26 → xmwai-0.3.27}/XMWAI/gif/49.gif +0 -0
- {xmwai-0.3.26 → xmwai-0.3.27}/XMWAI/gif/5.gif +0 -0
- {xmwai-0.3.26 → xmwai-0.3.27}/XMWAI/gif/50.gif +0 -0
- {xmwai-0.3.26 → xmwai-0.3.27}/XMWAI/gif/51.gif +0 -0
- {xmwai-0.3.26 → xmwai-0.3.27}/XMWAI/gif/52.gif +0 -0
- {xmwai-0.3.26 → xmwai-0.3.27}/XMWAI/gif/53.gif +0 -0
- {xmwai-0.3.26 → xmwai-0.3.27}/XMWAI/gif/54.gif +0 -0
- {xmwai-0.3.26 → xmwai-0.3.27}/XMWAI/gif/55.gif +0 -0
- {xmwai-0.3.26 → xmwai-0.3.27}/XMWAI/gif/56.gif +0 -0
- {xmwai-0.3.26 → xmwai-0.3.27}/XMWAI/gif/57.gif +0 -0
- {xmwai-0.3.26 → xmwai-0.3.27}/XMWAI/gif/58.gif +0 -0
- {xmwai-0.3.26 → xmwai-0.3.27}/XMWAI/gif/59.gif +0 -0
- {xmwai-0.3.26 → xmwai-0.3.27}/XMWAI/gif/6.gif +0 -0
- {xmwai-0.3.26 → xmwai-0.3.27}/XMWAI/gif/60.gif +0 -0
- {xmwai-0.3.26 → xmwai-0.3.27}/XMWAI/gif/61.gif +0 -0
- {xmwai-0.3.26 → xmwai-0.3.27}/XMWAI/gif/62.gif +0 -0
- {xmwai-0.3.26 → xmwai-0.3.27}/XMWAI/gif/63.gif +0 -0
- {xmwai-0.3.26 → xmwai-0.3.27}/XMWAI/gif/64.gif +0 -0
- {xmwai-0.3.26 → xmwai-0.3.27}/XMWAI/gif/65.gif +0 -0
- {xmwai-0.3.26 → xmwai-0.3.27}/XMWAI/gif/66.gif +0 -0
- {xmwai-0.3.26 → xmwai-0.3.27}/XMWAI/gif/67.gif +0 -0
- {xmwai-0.3.26 → xmwai-0.3.27}/XMWAI/gif/68.gif +0 -0
- {xmwai-0.3.26 → xmwai-0.3.27}/XMWAI/gif/69.gif +0 -0
- {xmwai-0.3.26 → xmwai-0.3.27}/XMWAI/gif/7.gif +0 -0
- {xmwai-0.3.26 → xmwai-0.3.27}/XMWAI/gif/70.gif +0 -0
- {xmwai-0.3.26 → xmwai-0.3.27}/XMWAI/gif/71.gif +0 -0
- {xmwai-0.3.26 → xmwai-0.3.27}/XMWAI/gif/72.gif +0 -0
- {xmwai-0.3.26 → xmwai-0.3.27}/XMWAI/gif/73.gif +0 -0
- {xmwai-0.3.26 → xmwai-0.3.27}/XMWAI/gif/74.gif +0 -0
- {xmwai-0.3.26 → xmwai-0.3.27}/XMWAI/gif/75.gif +0 -0
- {xmwai-0.3.26 → xmwai-0.3.27}/XMWAI/gif/76.gif +0 -0
- {xmwai-0.3.26 → xmwai-0.3.27}/XMWAI/gif/77.gif +0 -0
- {xmwai-0.3.26 → xmwai-0.3.27}/XMWAI/gif/78.gif +0 -0
- {xmwai-0.3.26 → xmwai-0.3.27}/XMWAI/gif/79.gif +0 -0
- {xmwai-0.3.26 → xmwai-0.3.27}/XMWAI/gif/8.gif +0 -0
- {xmwai-0.3.26 → xmwai-0.3.27}/XMWAI/gif/80.gif +0 -0
- {xmwai-0.3.26 → xmwai-0.3.27}/XMWAI/gif/81.gif +0 -0
- {xmwai-0.3.26 → xmwai-0.3.27}/XMWAI/gif/82.gif +0 -0
- {xmwai-0.3.26 → xmwai-0.3.27}/XMWAI/gif/83.gif +0 -0
- {xmwai-0.3.26 → xmwai-0.3.27}/XMWAI/gif/84.gif +0 -0
- {xmwai-0.3.26 → xmwai-0.3.27}/XMWAI/gif/85.gif +0 -0
- {xmwai-0.3.26 → xmwai-0.3.27}/XMWAI/gif/9.gif +0 -0
- {xmwai-0.3.26 → xmwai-0.3.27}/XMWAI/gif/__init__.py +0 -0
- {xmwai-0.3.26 → xmwai-0.3.27}/XMWAI/idiom_core.py +0 -0
- {xmwai-0.3.26 → xmwai-0.3.27}/XMWAI/magic_core.py +0 -0
- {xmwai-0.3.26 → xmwai-0.3.27}/XMWAI/static/burger.js +0 -0
- {xmwai-0.3.26 → xmwai-0.3.27}/XMWAI/static/images/BottomBun.png +0 -0
- {xmwai-0.3.26 → xmwai-0.3.27}/XMWAI/static/images/TopBun.png +0 -0
- {xmwai-0.3.26 → xmwai-0.3.27}/XMWAI/static/images/beef.png +0 -0
- {xmwai-0.3.26 → xmwai-0.3.27}/XMWAI/static/images/bg.jpeg +0 -0
- {xmwai-0.3.26 → xmwai-0.3.27}/XMWAI/static/images/bg.png +0 -0
- {xmwai-0.3.26 → xmwai-0.3.27}/XMWAI/static/images/cheese.png +0 -0
- {xmwai-0.3.26 → xmwai-0.3.27}/XMWAI/static/images/lettuce.png +0 -0
- {xmwai-0.3.26 → xmwai-0.3.27}/XMWAI/static/images/sauce.png +0 -0
- {xmwai-0.3.26 → xmwai-0.3.27}/XMWAI/static/images/tomato.png +0 -0
- {xmwai-0.3.26 → xmwai-0.3.27}/XMWAI/templates/burger.html +0 -0
- {xmwai-0.3.26 → xmwai-0.3.27}/XMWAI/templates/nutrition_pie.html +0 -0
- {xmwai-0.3.26 → xmwai-0.3.27}/XMWAI/templates//345/210/233/346/204/217/350/217/234/350/260/261.html" +0 -0
- {xmwai-0.3.26 → xmwai-0.3.27}/XMWAI/trial_class.py +0 -0
- /xmwai-0.3.26/XMWAI/web_core.py → /xmwai-0.3.27/XMWAI/web_core copy.py +0 -0
- {xmwai-0.3.26 → xmwai-0.3.27}/XMWAI.egg-info/dependency_links.txt +0 -0
- {xmwai-0.3.26 → xmwai-0.3.27}/XMWAI.egg-info/requires.txt +0 -0
- {xmwai-0.3.26 → xmwai-0.3.27}/XMWAI.egg-info/top_level.txt +0 -0
- {xmwai-0.3.26 → xmwai-0.3.27}/setup.cfg +0 -0
|
@@ -0,0 +1,287 @@
|
|
|
1
|
+
import os
|
|
2
|
+
import json
|
|
3
|
+
import requests
|
|
4
|
+
from flask import Flask, render_template
|
|
5
|
+
import re
|
|
6
|
+
import shutil
|
|
7
|
+
from pyecharts import options as opts
|
|
8
|
+
from pyecharts.charts import Pie
|
|
9
|
+
import webbrowser
|
|
10
|
+
import threading
|
|
11
|
+
import time
|
|
12
|
+
from importlib.resources import files
|
|
13
|
+
from pathlib import Path
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+
'''Super堡'''
|
|
17
|
+
# 搭建flask框架
|
|
18
|
+
app = Flask(
|
|
19
|
+
__name__,
|
|
20
|
+
template_folder=os.path.join(os.path.dirname(__file__), "templates"),
|
|
21
|
+
static_folder=os.path.join(os.path.dirname(__file__), "static")
|
|
22
|
+
)
|
|
23
|
+
|
|
24
|
+
mapping = {
|
|
25
|
+
"面包底": "BottomBun",
|
|
26
|
+
"生菜": "lettuce",
|
|
27
|
+
"番茄": "tomato",
|
|
28
|
+
"牛肉饼": "beef",
|
|
29
|
+
"芝士": "cheese",
|
|
30
|
+
"酱料": "sauce",
|
|
31
|
+
"面包顶": "TopBun"
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
ingredients_order = []
|
|
35
|
+
|
|
36
|
+
|
|
37
|
+
def burger(result):
|
|
38
|
+
global ingredients_order
|
|
39
|
+
inputs = result.strip().split("→")
|
|
40
|
+
ingredients_order = [mapping[i] for i in inputs]
|
|
41
|
+
ingredients_order = ingredients_order[::-1]
|
|
42
|
+
|
|
43
|
+
# 自动启动服务器
|
|
44
|
+
start_server()
|
|
45
|
+
return ingredients_order
|
|
46
|
+
|
|
47
|
+
|
|
48
|
+
@app.route('/')
|
|
49
|
+
def show_burger():
|
|
50
|
+
return render_template("burger.html", ingredients=ingredients_order)
|
|
51
|
+
|
|
52
|
+
|
|
53
|
+
def run_server(port=5050):
|
|
54
|
+
"""在后台线程中运行服务器"""
|
|
55
|
+
app.run(debug=False, host='0.0.0.0', port=port, use_reloader=False)
|
|
56
|
+
|
|
57
|
+
|
|
58
|
+
def start_server(port=5050):
|
|
59
|
+
"""启动服务器并打开浏览器"""
|
|
60
|
+
url = f"http://127.0.0.1:{port}/"
|
|
61
|
+
|
|
62
|
+
# 在后台线程中启动服务器
|
|
63
|
+
server_thread = threading.Thread(target=run_server, args=(port,))
|
|
64
|
+
server_thread.daemon = True
|
|
65
|
+
server_thread.start()
|
|
66
|
+
|
|
67
|
+
# 等待服务器启动
|
|
68
|
+
time.sleep(2)
|
|
69
|
+
|
|
70
|
+
# 打开浏览器
|
|
71
|
+
webbrowser.open(url)
|
|
72
|
+
|
|
73
|
+
# 保持服务器运行
|
|
74
|
+
try:
|
|
75
|
+
server_thread.join()
|
|
76
|
+
except KeyboardInterrupt:
|
|
77
|
+
pass
|
|
78
|
+
|
|
79
|
+
|
|
80
|
+
'''Random料理屋'''
|
|
81
|
+
# 食材对应 emoji
|
|
82
|
+
emoji_dict = {
|
|
83
|
+
"鸡": "🍗", "牛": "🥩", "猪": "🥓", "鱼": "🐟", "虾": "🦐", "蟹": "🦀",
|
|
84
|
+
"豆腐": "🧈", "土豆": "🥔", "胡萝卜": "🥕", "西红柿": "🍅", "青菜": "🥬",
|
|
85
|
+
"菠菜": "🥬", "蘑菇": "🍄", "玉米": "🌽", "米饭": "🍚", "面条": "🍜",
|
|
86
|
+
"面包": "🍞", "奶酪": "🧀", "鸡蛋": "🥚", "牛奶": "🥛", "橙子": "🍊",
|
|
87
|
+
"苹果": "🍎", "香蕉": "🍌"
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
# 动作对应 emoji
|
|
91
|
+
action_dict = {
|
|
92
|
+
"炒": "🍳", "煮": "🍲", "烤": "🔥", "蒸": "♨️", "炸": "🍟", "拌": "🥣",
|
|
93
|
+
"切": "🔪", "腌": "🫙", "炖": "🥘"
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
|
|
97
|
+
def add_emoji_to_text(text):
|
|
98
|
+
for key, val in action_dict.items():
|
|
99
|
+
text = re.sub(f'({key})', f'{val} \\1', text)
|
|
100
|
+
for key, val in emoji_dict.items():
|
|
101
|
+
text = re.sub(f'({key})', f'{val} \\1', text)
|
|
102
|
+
return text
|
|
103
|
+
|
|
104
|
+
|
|
105
|
+
def format_section_steps(text):
|
|
106
|
+
lines = [line.strip() for line in text.strip().split("\n") if line.strip()]
|
|
107
|
+
lines = lines[:50]
|
|
108
|
+
return "<br>".join(add_emoji_to_text(line) for line in lines)
|
|
109
|
+
|
|
110
|
+
|
|
111
|
+
def parse_nutrition_section(text):
|
|
112
|
+
"""解析 API 返回的营养 JSON 并提取数值"""
|
|
113
|
+
default_data = {"蛋白质": 30, "脂肪": 20, "碳水化合物": 50, "维生素": 10, "矿物质": 5}
|
|
114
|
+
|
|
115
|
+
def extract_number(val):
|
|
116
|
+
if isinstance(val, (int, float)):
|
|
117
|
+
return val
|
|
118
|
+
if isinstance(val, str):
|
|
119
|
+
match = re.search(r"(\d+(\.\d+)?)", val)
|
|
120
|
+
if match:
|
|
121
|
+
return float(match.group(1))
|
|
122
|
+
return 0
|
|
123
|
+
|
|
124
|
+
try:
|
|
125
|
+
match = re.search(r"\{.*\}", text, re.S)
|
|
126
|
+
if match:
|
|
127
|
+
parsed = json.loads(match.group())
|
|
128
|
+
result = {}
|
|
129
|
+
for key in default_data.keys():
|
|
130
|
+
if key in parsed:
|
|
131
|
+
val = parsed[key]
|
|
132
|
+
if isinstance(val, dict):
|
|
133
|
+
total = sum(extract_number(v) for v in val.values())
|
|
134
|
+
result[key] = total
|
|
135
|
+
else:
|
|
136
|
+
result[key] = extract_number(val)
|
|
137
|
+
else:
|
|
138
|
+
result[key] = default_data[key]
|
|
139
|
+
return result
|
|
140
|
+
except Exception as e:
|
|
141
|
+
print("JSON解析失败:", e)
|
|
142
|
+
return default_data
|
|
143
|
+
|
|
144
|
+
|
|
145
|
+
def generate_pie_chart(data_dict, filename: Path):
|
|
146
|
+
data = [(k, v) for k, v in data_dict.items()]
|
|
147
|
+
pie = (
|
|
148
|
+
Pie(init_opts=opts.InitOpts(width="1100px", height="500px"))
|
|
149
|
+
.add("", data)
|
|
150
|
+
.set_global_opts(title_opts=opts.TitleOpts(title="营养价值分布"))
|
|
151
|
+
.set_series_opts(label_opts=opts.LabelOpts(formatter="{b}: {c}"))
|
|
152
|
+
)
|
|
153
|
+
pie.render(str(filename))
|
|
154
|
+
return filename
|
|
155
|
+
|
|
156
|
+
|
|
157
|
+
def cookbook(m, t, s, key):
|
|
158
|
+
if key != "CaJQ":
|
|
159
|
+
return "密钥错误,无法生成食谱。"
|
|
160
|
+
|
|
161
|
+
# 调用 API 生成创意菜谱
|
|
162
|
+
messagesList = [
|
|
163
|
+
{"role": "system", "content": "天马行空的创意菜厨师"},
|
|
164
|
+
{"role": "user", "content": f"请以{m}为主菜,{s}为配菜,{t}为烹饪方式写一个创意食谱,"
|
|
165
|
+
"结果中不要*,并且结果只需要创意灵感、食材清单、制作步骤、"
|
|
166
|
+
"食材搭配的营养价值四种大标题内容。食材搭配的营养价值部分请输出标准 JSON,"
|
|
167
|
+
"键为蛋白质、脂肪、碳水化合物、维生素、矿物质,值为数值及说明。"}
|
|
168
|
+
]
|
|
169
|
+
|
|
170
|
+
url = "https://qianfan.baidubce.com/v2/chat/completions"
|
|
171
|
+
payload = json.dumps({"model": "ernie-4.5-turbo-32k",
|
|
172
|
+
"messages": messagesList}, ensure_ascii=False)
|
|
173
|
+
headers = {
|
|
174
|
+
"Content-Type": "application/json",
|
|
175
|
+
"appid": "",
|
|
176
|
+
"Authorization": "Bearer bce-v3/ALTAK-cGbxpVA5AbSz6h8nbLaFh/b539762075d55c76d93dc78bcf0a91beeaf0490a"
|
|
177
|
+
}
|
|
178
|
+
|
|
179
|
+
try:
|
|
180
|
+
response = requests.post(url, headers=headers,
|
|
181
|
+
data=payload.encode("utf-8"))
|
|
182
|
+
response_data = response.json()
|
|
183
|
+
content = response_data["choices"][0]["message"]["content"]
|
|
184
|
+
except Exception as e:
|
|
185
|
+
return f"接口调用失败:{e}"
|
|
186
|
+
|
|
187
|
+
# 分割内容
|
|
188
|
+
sections = re.split(r"(创意灵感|食材清单|制作步骤|食材搭配的营养价值)", content)
|
|
189
|
+
body_sections = [""]*4
|
|
190
|
+
title_map = {"创意灵感": 0, "食材清单": 1, "制作步骤": 2, "食材搭配的营养价值": 3}
|
|
191
|
+
i = 1
|
|
192
|
+
while i < len(sections):
|
|
193
|
+
header = sections[i]
|
|
194
|
+
text_sec = sections[i+1] if i+1 < len(sections) else ""
|
|
195
|
+
idx = title_map.get(header.strip(), None)
|
|
196
|
+
if idx is not None:
|
|
197
|
+
body_sections[idx] = text_sec.strip()
|
|
198
|
+
i += 2
|
|
199
|
+
|
|
200
|
+
# 模板和图片目录
|
|
201
|
+
templates_dir = Path(files("XMWAI") / "templates")
|
|
202
|
+
templates_dir.mkdir(exist_ok=True)
|
|
203
|
+
|
|
204
|
+
# 从包内 static 拷贝背景图到模板目录
|
|
205
|
+
bg_src = Path(files("XMWAI") / "static" / "images" / "bg.jpeg")
|
|
206
|
+
bg_copy = templates_dir / "bg.jpeg"
|
|
207
|
+
if not bg_copy.exists():
|
|
208
|
+
shutil.copy(bg_src, bg_copy)
|
|
209
|
+
|
|
210
|
+
# 生成饼图文件
|
|
211
|
+
pie_chart_file = templates_dir / "nutrition_pie.html"
|
|
212
|
+
nutrient_data = parse_nutrition_section(body_sections[3])
|
|
213
|
+
generate_pie_chart(nutrient_data, pie_chart_file)
|
|
214
|
+
|
|
215
|
+
# 添加 emoji
|
|
216
|
+
m_emoji = add_emoji_to_text(m)
|
|
217
|
+
s_emoji = add_emoji_to_text(s)
|
|
218
|
+
t_emoji = add_emoji_to_text(t)
|
|
219
|
+
|
|
220
|
+
# 步骤顺序 HTML
|
|
221
|
+
step_titles = ["食材搭配的营养价值", "创意灵感", "食材清单", "制作步骤"]
|
|
222
|
+
steps_order = [3, 0, 1, 2]
|
|
223
|
+
steps_html = ""
|
|
224
|
+
for i, idx in enumerate(steps_order):
|
|
225
|
+
if idx == 3:
|
|
226
|
+
section_content_html = "根据食材搭配生成的营养价值饼图如下 ⬇️"
|
|
227
|
+
else:
|
|
228
|
+
section_content_html = format_section_steps(body_sections[idx])
|
|
229
|
+
steps_html += f"""
|
|
230
|
+
<div class="step-card" style="animation-delay:{(i+1)*0.2}s;">
|
|
231
|
+
<div class="step-title">Step {i+1} 📝 {step_titles[i]}</div>
|
|
232
|
+
<div class="step-content">{section_content_html}</div>
|
|
233
|
+
</div>
|
|
234
|
+
"""
|
|
235
|
+
|
|
236
|
+
# HTML 页面 (背景图引用相对路径 bg.jpeg)
|
|
237
|
+
html = f"""
|
|
238
|
+
<!DOCTYPE html>
|
|
239
|
+
<html lang="zh">
|
|
240
|
+
<head>
|
|
241
|
+
<meta charset="UTF-8">
|
|
242
|
+
<title>创意菜谱</title>
|
|
243
|
+
<style>
|
|
244
|
+
html, body {{ margin:0; padding:0; width:100%; height:100%; overflow-x:hidden; }}
|
|
245
|
+
body {{ font-family:"微软雅黑",sans-serif; background:#2c2c2c url('bg.jpeg') no-repeat center center fixed; background-size:cover; color:#333; }}
|
|
246
|
+
.container {{ max-width:1200px; margin:30px auto; background:rgba(255,248,220,0.95); border-radius:15px; padding:30px; box-shadow:0 0 20px rgba(0,0,0,0.2); }}
|
|
247
|
+
.banner {{ width:100%; height:220px; background:url('bg.jpeg') center/cover no-repeat; border-radius:15px 15px 0 0; display:flex; align-items:center; justify-content:center; }}
|
|
248
|
+
.banner h1 {{ color:#fff; font-size:28px; text-shadow:1px 1px 3px #666; }}
|
|
249
|
+
p {{ font-size:18px; margin:8px 0; }}
|
|
250
|
+
.step-card {{ background:#fff0b3; margin:10px 0; border-radius:12px; overflow:hidden; opacity:0; transform:translateY(20px) scale(0.98); animation:fadeInUp 0.6s forwards; }}
|
|
251
|
+
.step-title {{ font-weight:bold; padding:10px 15px; cursor:pointer; background:#ffb347; color:#fff; border-bottom:1px solid #ffd27f; }}
|
|
252
|
+
.step-content {{ padding:10px 15px; display:block; font-size:16px; opacity:0; max-height:0; overflow:hidden; transition: opacity 0.4s ease, max-height 0.4s ease; }}
|
|
253
|
+
.step-card.hover .step-content {{ opacity:1; max-height:800px; }}
|
|
254
|
+
iframe {{ width:100%; height:500px; border:none; margin-top:20px; }}
|
|
255
|
+
@keyframes fadeInUp {{ to {{ opacity:1; transform:translateY(0) scale(1); }} }}
|
|
256
|
+
</style>
|
|
257
|
+
</head>
|
|
258
|
+
<body>
|
|
259
|
+
<div class="container">
|
|
260
|
+
<div class="banner"><h1>🍽 {m+t+s}</h1></div>
|
|
261
|
+
<p>🍖 <strong>主菜:</strong>{m_emoji}</p>
|
|
262
|
+
<p>🥗 <strong>配菜:</strong>{s_emoji}</p>
|
|
263
|
+
<p>👩🍳 <strong>做法:</strong>{t_emoji}</p>
|
|
264
|
+
{steps_html}
|
|
265
|
+
<iframe src="{pie_chart_file.name}"></iframe>
|
|
266
|
+
</div>
|
|
267
|
+
<script>
|
|
268
|
+
const steps = document.querySelectorAll('.step-card');
|
|
269
|
+
steps.forEach(card => {{
|
|
270
|
+
card.addEventListener('mouseenter', () => {{ card.classList.add('hover'); }});
|
|
271
|
+
card.addEventListener('mouseleave', () => {{ card.classList.remove('hover'); }});
|
|
272
|
+
}});
|
|
273
|
+
</script>
|
|
274
|
+
</body>
|
|
275
|
+
</html>
|
|
276
|
+
"""
|
|
277
|
+
|
|
278
|
+
# 保存 HTML 文件到包内 templates
|
|
279
|
+
safe_title = re.sub(r'[\/\\:*?"<>|]', "", m+t+s)
|
|
280
|
+
html_file = templates_dir / f"{safe_title}_菜谱.html"
|
|
281
|
+
with open(html_file, "w", encoding="utf-8") as f:
|
|
282
|
+
f.write(html)
|
|
283
|
+
|
|
284
|
+
# 打开浏览器
|
|
285
|
+
webbrowser.open(f"file://{html_file.resolve()}")
|
|
286
|
+
|
|
287
|
+
return content
|
|
@@ -2,7 +2,7 @@ from setuptools import setup, find_packages
|
|
|
2
2
|
|
|
3
3
|
setup(
|
|
4
4
|
name="XMWAI", # 包名(pip install XMWAI)
|
|
5
|
-
version="0.3.
|
|
5
|
+
version="0.3.27", # 每次上传记得升级版本号
|
|
6
6
|
author="pydevelopment", # 作者
|
|
7
7
|
author_email="hekai@xiaoma.cn", # 邮箱
|
|
8
8
|
description="Small code King AI related library", # 简短描述
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
{xmwai-0.3.26 → xmwai-0.3.27}/XMWAI/templates//345/210/233/346/204/217/350/217/234/350/260/261.html"
RENAMED
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|