XMWAI 0.3.24__py3-none-any.whl → 0.3.25__py3-none-any.whl
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/web_core.py +109 -59
- {xmwai-0.3.24.dist-info → xmwai-0.3.25.dist-info}/METADATA +1 -1
- {xmwai-0.3.24.dist-info → xmwai-0.3.25.dist-info}/RECORD +7 -8
- XMWAI/xmw_photo/__init__.py +0 -0
- /XMWAI/{xmw_photo → static/images}/bg.jpeg +0 -0
- {xmwai-0.3.24.dist-info → xmwai-0.3.25.dist-info}/WHEEL +0 -0
- {xmwai-0.3.24.dist-info → xmwai-0.3.25.dist-info}/licenses/LICENSE.txt +0 -0
- {xmwai-0.3.24.dist-info → xmwai-0.3.25.dist-info}/top_level.txt +0 -0
XMWAI/web_core.py
CHANGED
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
from PIL import Image, ImageDraw
|
|
2
|
+
import random
|
|
1
3
|
import os
|
|
2
4
|
import json
|
|
3
5
|
import requests
|
|
@@ -88,8 +90,8 @@ emoji_dict = {
|
|
|
88
90
|
|
|
89
91
|
# 动作对应 emoji
|
|
90
92
|
action_dict = {
|
|
91
|
-
"炒": "🍳", "煮": "🍲", "烤": "🔥", "蒸": "♨️", "炸": "🍟",
|
|
92
|
-
"切": "🔪", "腌": "🫙", "炖": "🥘"
|
|
93
|
+
"炒": "🍳", "煮": "🍲", "烤": "🔥", "蒸": "♨️", "炸": "🍟",
|
|
94
|
+
"拌": "🥣", "切": "🔪", "腌": "🫙", "炖": "🥘"
|
|
93
95
|
}
|
|
94
96
|
|
|
95
97
|
|
|
@@ -108,7 +110,6 @@ def format_section_steps(text):
|
|
|
108
110
|
|
|
109
111
|
|
|
110
112
|
def parse_nutrition_section(text):
|
|
111
|
-
"""解析 API 返回的营养 JSON 并提取数值"""
|
|
112
113
|
default_data = {"蛋白质": 30, "脂肪": 20, "碳水化合物": 50, "维生素": 10, "矿物质": 5}
|
|
113
114
|
|
|
114
115
|
def extract_number(val):
|
|
@@ -153,11 +154,34 @@ def generate_pie_chart(data_dict, filename: Path):
|
|
|
153
154
|
return filename
|
|
154
155
|
|
|
155
156
|
|
|
157
|
+
def random_gradient_bg(bg_path: Path):
|
|
158
|
+
"""生成一张随机渐变背景图"""
|
|
159
|
+
width, height = 1200, 800
|
|
160
|
+
|
|
161
|
+
# 随机挑两个颜色 (RGB)
|
|
162
|
+
start_color = (random.randint(100, 255), random.randint(
|
|
163
|
+
100, 255), random.randint(100, 255))
|
|
164
|
+
end_color = (random.randint(100, 255), random.randint(
|
|
165
|
+
100, 255), random.randint(100, 255))
|
|
166
|
+
|
|
167
|
+
img = Image.new("RGB", (width, height), start_color)
|
|
168
|
+
draw = ImageDraw.Draw(img)
|
|
169
|
+
|
|
170
|
+
for y in range(height):
|
|
171
|
+
r = int(start_color[0] + (end_color[0] - start_color[0]) * y / height)
|
|
172
|
+
g = int(start_color[1] + (end_color[1] - start_color[1]) * y / height)
|
|
173
|
+
b = int(start_color[2] + (end_color[2] - start_color[2]) * y / height)
|
|
174
|
+
draw.line([(0, y), (width, y)], fill=(r, g, b))
|
|
175
|
+
|
|
176
|
+
img.save(bg_path, "JPEG")
|
|
177
|
+
print(f"🎨 生成随机渐变背景:{bg_path}")
|
|
178
|
+
|
|
179
|
+
|
|
156
180
|
def cookbook(m, t, s, key):
|
|
157
181
|
if key != "CaJQ":
|
|
158
182
|
return "密钥错误,无法生成食谱。"
|
|
159
183
|
|
|
160
|
-
# 调用 API
|
|
184
|
+
# 调用 API
|
|
161
185
|
messagesList = [
|
|
162
186
|
{"role": "system", "content": "天马行空的创意菜厨师"},
|
|
163
187
|
{"role": "user", "content": f"请以{m}为主菜,{s}为配菜,{t}为烹饪方式写一个创意食谱,"
|
|
@@ -169,11 +193,8 @@ def cookbook(m, t, s, key):
|
|
|
169
193
|
url = "https://qianfan.baidubce.com/v2/chat/completions"
|
|
170
194
|
payload = json.dumps({"model": "ernie-4.5-turbo-32k",
|
|
171
195
|
"messages": messagesList}, ensure_ascii=False)
|
|
172
|
-
headers = {
|
|
173
|
-
|
|
174
|
-
"appid": "",
|
|
175
|
-
"Authorization": "Bearer bce-v3/ALTAK-cGbxpVA5AbSz6h8nbLaFh/b539762075d55c76d93dc78bcf0a91beeaf0490a"
|
|
176
|
-
}
|
|
196
|
+
headers = {"Content-Type": "application/json",
|
|
197
|
+
"appid": "", "Authorization": "Bearer xxxxx"}
|
|
177
198
|
|
|
178
199
|
try:
|
|
179
200
|
response = requests.post(url, headers=headers,
|
|
@@ -185,33 +206,35 @@ def cookbook(m, t, s, key):
|
|
|
185
206
|
|
|
186
207
|
# 分割内容
|
|
187
208
|
sections = re.split(r"(创意灵感|食材清单|制作步骤|食材搭配的营养价值)", content)
|
|
188
|
-
body_sections = [""]*4
|
|
209
|
+
body_sections = [""] * 4
|
|
189
210
|
title_map = {"创意灵感": 0, "食材清单": 1, "制作步骤": 2, "食材搭配的营养价值": 3}
|
|
190
211
|
i = 1
|
|
191
212
|
while i < len(sections):
|
|
192
213
|
header = sections[i]
|
|
193
|
-
text_sec = sections[i+1] if i+1 < len(sections) else ""
|
|
214
|
+
text_sec = sections[i + 1] if i + 1 < len(sections) else ""
|
|
194
215
|
idx = title_map.get(header.strip(), None)
|
|
195
216
|
if idx is not None:
|
|
196
217
|
body_sections[idx] = text_sec.strip()
|
|
197
218
|
i += 2
|
|
198
219
|
|
|
199
|
-
#
|
|
200
|
-
templates_dir = Path(files("XMWAI")
|
|
220
|
+
# 模板和图片目录
|
|
221
|
+
templates_dir = Path(files("XMWAI") / "templates")
|
|
201
222
|
templates_dir.mkdir(exist_ok=True)
|
|
202
|
-
photo_dir = Path(files("XMWAI").joinpath("xmw_photo"))
|
|
203
223
|
|
|
204
|
-
#
|
|
224
|
+
# ✅ 每次生成随机背景
|
|
225
|
+
bg_path = Path(files("XMWAI") / "static" / "images" / "bg.jpeg")
|
|
226
|
+
random_gradient_bg(bg_path)
|
|
227
|
+
|
|
228
|
+
# 生成饼图
|
|
205
229
|
pie_chart_file = templates_dir / "nutrition_pie.html"
|
|
206
230
|
nutrient_data = parse_nutrition_section(body_sections[3])
|
|
207
231
|
generate_pie_chart(nutrient_data, pie_chart_file)
|
|
208
232
|
|
|
209
233
|
# 添加 emoji
|
|
210
|
-
m_emoji = add_emoji_to_text(
|
|
211
|
-
|
|
212
|
-
t_emoji = add_emoji_to_text(t)
|
|
234
|
+
m_emoji, s_emoji, t_emoji = add_emoji_to_text(
|
|
235
|
+
m), add_emoji_to_text(s), add_emoji_to_text(t)
|
|
213
236
|
|
|
214
|
-
#
|
|
237
|
+
# 生成步骤 HTML
|
|
215
238
|
step_titles = ["食材搭配的营养价值", "创意灵感", "食材清单", "制作步骤"]
|
|
216
239
|
steps_order = [3, 0, 1, 2]
|
|
217
240
|
steps_html = ""
|
|
@@ -221,62 +244,89 @@ def cookbook(m, t, s, key):
|
|
|
221
244
|
else:
|
|
222
245
|
section_content_html = format_section_steps(body_sections[idx])
|
|
223
246
|
steps_html += f"""
|
|
224
|
-
<div class="step-card" style="animation-delay:{(i+1)*0.2}s;">
|
|
225
|
-
<div class="step-title">Step {i+1} 📝 {step_titles[i]}</div>
|
|
247
|
+
<div class="step-card" style="animation-delay:{(i + 1) * 0.2}s;">
|
|
248
|
+
<div class="step-title">Step {i + 1} 📝 {step_titles[i]}</div>
|
|
226
249
|
<div class="step-content">{section_content_html}</div>
|
|
227
250
|
</div>
|
|
228
251
|
"""
|
|
229
252
|
|
|
230
|
-
#
|
|
231
|
-
|
|
253
|
+
# 相对路径
|
|
254
|
+
bg_rel_path = os.path.relpath(bg_path, templates_dir)
|
|
255
|
+
pie_rel_path = os.path.relpath(pie_chart_file, templates_dir)
|
|
256
|
+
|
|
257
|
+
# HTML 文件
|
|
258
|
+
safe_title = re.sub(r'[\/\\:*?"<>|]', "", m + t + s)
|
|
259
|
+
html_file = templates_dir / f"{safe_title}_菜谱.html"
|
|
260
|
+
|
|
232
261
|
html = f"""
|
|
233
262
|
<!DOCTYPE html>
|
|
234
263
|
<html lang="zh">
|
|
235
264
|
<head>
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
265
|
+
<meta charset="UTF-8">
|
|
266
|
+
<title>创意菜谱</title>
|
|
267
|
+
<style>
|
|
268
|
+
html, body {{ margin:0; padding:0; width:100%; height:100%; overflow-x:hidden; }}
|
|
269
|
+
body {{
|
|
270
|
+
font-family:"微软雅黑",sans-serif;
|
|
271
|
+
background:#2c2c2c url('{bg_rel_path}') no-repeat center center fixed;
|
|
272
|
+
background-size:cover;
|
|
273
|
+
color:#333;
|
|
274
|
+
}}
|
|
275
|
+
.container {{
|
|
276
|
+
max-width:1200px; margin:30px auto;
|
|
277
|
+
background:rgba(255,248,220,0.95);
|
|
278
|
+
border-radius:15px; padding:30px;
|
|
279
|
+
box-shadow:0 0 20px rgba(0,0,0,0.2);
|
|
280
|
+
}}
|
|
281
|
+
.banner {{
|
|
282
|
+
width:100%; height:220px;
|
|
283
|
+
background:url('{bg_rel_path}') center/cover no-repeat;
|
|
284
|
+
border-radius:15px 15px 0 0;
|
|
285
|
+
display:flex; align-items:center; justify-content:center;
|
|
286
|
+
}}
|
|
287
|
+
.banner h1 {{ color:#fff; font-size:28px; text-shadow:1px 1px 3px #666; }}
|
|
288
|
+
p {{ font-size:18px; margin:8px 0; }}
|
|
289
|
+
.step-card {{
|
|
290
|
+
background:#fff0b3; margin:10px 0; border-radius:12px;
|
|
291
|
+
overflow:hidden; opacity:0; transform:translateY(20px) scale(0.98);
|
|
292
|
+
animation:fadeInUp 0.6s forwards;
|
|
293
|
+
}}
|
|
294
|
+
.step-title {{
|
|
295
|
+
font-weight:bold; padding:10px 15px; cursor:pointer;
|
|
296
|
+
background:#ffb347; color:#fff; border-bottom:1px solid #ffd27f;
|
|
297
|
+
}}
|
|
298
|
+
.step-content {{
|
|
299
|
+
padding:10px 15px; display:block; font-size:16px;
|
|
300
|
+
opacity:0; max-height:0; overflow:hidden;
|
|
301
|
+
transition: opacity 0.4s ease, max-height 0.4s ease;
|
|
302
|
+
}}
|
|
303
|
+
.step-card.hover .step-content {{ opacity:1; max-height:800px; }}
|
|
304
|
+
iframe {{ width:100%; height:500px; border:none; margin-top:20px; }}
|
|
305
|
+
@keyframes fadeInUp {{ to {{ opacity:1; transform:translateY(0) scale(1); }} }}
|
|
306
|
+
</style>
|
|
252
307
|
</head>
|
|
253
308
|
<body>
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
309
|
+
<div class="container">
|
|
310
|
+
<div class="banner"><h1>🍽 {m+t+s}</h1></div>
|
|
311
|
+
<p>🍖 <strong>主菜:</strong>{m_emoji}</p>
|
|
312
|
+
<p>🥗 <strong>配菜:</strong>{s_emoji}</p>
|
|
313
|
+
<p>👩🍳 <strong>做法:</strong>{t_emoji}</p>
|
|
314
|
+
{steps_html}
|
|
315
|
+
<iframe src="{pie_rel_path}"></iframe>
|
|
316
|
+
</div>
|
|
317
|
+
<script>
|
|
318
|
+
const steps = document.querySelectorAll('.step-card');
|
|
319
|
+
steps.forEach(card => {{
|
|
320
|
+
card.addEventListener('mouseenter', () => card.classList.add('hover'));
|
|
321
|
+
card.addEventListener('mouseleave', () => card.classList.remove('hover'));
|
|
322
|
+
}});
|
|
323
|
+
</script>
|
|
269
324
|
</body>
|
|
270
325
|
</html>
|
|
271
326
|
"""
|
|
272
327
|
|
|
273
|
-
# 保存 HTML 文件到包内 templates
|
|
274
|
-
safe_title = re.sub(r'[\/\\:*?"<>|]', "", m+t+s)
|
|
275
|
-
html_file = templates_dir / f"{safe_title}_菜谱.html"
|
|
276
328
|
with open(html_file, "w", encoding="utf-8") as f:
|
|
277
329
|
f.write(html)
|
|
278
330
|
|
|
279
|
-
# 打开浏览器
|
|
280
331
|
webbrowser.open(f"file://{html_file.resolve()}")
|
|
281
|
-
|
|
282
332
|
return content
|
|
@@ -4,7 +4,7 @@ XMWAI/core.py,sha256=XG2ZLhW9CETUQMr-8FLZonL_aQg9jfohGnm9oU5XyVQ,10018
|
|
|
4
4
|
XMWAI/idiom_core.py,sha256=yU-VHhqqoutVm6GVikcjL3m9yuB1hUsFBpPYvwY4n5g,1689
|
|
5
5
|
XMWAI/magic_core.py,sha256=Ms4b12PJ8rjsmceg1VUqWCWx2ebvdhLp4sIF6K_Vaok,3491
|
|
6
6
|
XMWAI/trial_class.py,sha256=GRDEe24a-DYMRyoTLgJbE5dCSQY0CbYqB5ALsBfYmtA,10226
|
|
7
|
-
XMWAI/web_core.py,sha256=
|
|
7
|
+
XMWAI/web_core.py,sha256=RWNSSKMtfoqU4dTXNbBbRiTwZPcfSLFREzbknpL4lKM,11629
|
|
8
8
|
XMWAI/file/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
9
9
|
XMWAI/file/idiom.json,sha256=HUtPRUzhxBbWoasjadbmbA_5ngQ5AXLu9weQSZ4hzhk,10319857
|
|
10
10
|
XMWAI/gif/0.gif,sha256=LGpAReVTyZEb1J-bWYTpxxHbIxmLJ-3wA0lw4cBqdsY,303
|
|
@@ -98,6 +98,7 @@ XMWAI/static/burger.js,sha256=jxPZ7dsrg6CskRoBocVAWIg-zWjsMqVuHhEmVous2cQ,5329
|
|
|
98
98
|
XMWAI/static/images/BottomBun.png,sha256=ESF72RWDx0lCJBzB7vMpTMDoPtBBLszPRKeSUl4F_Dg,4079
|
|
99
99
|
XMWAI/static/images/TopBun.png,sha256=0Ib_cC_o-gT1fbYeBe7fmgfV6RvlMdLsH7b5YbwnXso,12692
|
|
100
100
|
XMWAI/static/images/beef.png,sha256=SCavT4kza_ZB0diH3tfYjkUlv61duuNLb_R9MzqnA34,7403
|
|
101
|
+
XMWAI/static/images/bg.jpeg,sha256=pYLeliPNhHQp7JlLRbVpz-v_MPs02n9rFrvH1Uxps6s,81475
|
|
101
102
|
XMWAI/static/images/bg.png,sha256=MhAu2tkzdUmBC7oXw1ZfG9h2Kwe9Sw9gRqiBxorwIUE,2885536
|
|
102
103
|
XMWAI/static/images/cheese.png,sha256=7XRv_4n0n53jwKJGRUbApyVVAISRrzcDSiWeoOQVEhI,6435
|
|
103
104
|
XMWAI/static/images/lettuce.png,sha256=ngj3nQe9Zqv-GfXpooaD0g0QtLW1cwC_7TwXSoaffb0,6199
|
|
@@ -106,10 +107,8 @@ XMWAI/static/images/tomato.png,sha256=FEOEAOdUhW_BDFgTpxOkYc0I5Iu29_gtHb3RIPEej0
|
|
|
106
107
|
XMWAI/templates/burger.html,sha256=vDnxpSW8phetyScySsalScZnFKl3LNpy5lJjKxGXgbI,3320
|
|
107
108
|
XMWAI/templates/nutrition_pie.html,sha256=yJVXI28i-UfvF0xOXGSNLMb8oCJNhh2J3zoRDr5_7DM,5567
|
|
108
109
|
XMWAI/templates/创意菜谱.html,sha256=RcDgH58QLyUJ9A59wobu3wvchGBY1snVsXcZQZam5M0,4805
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
xmwai-0.3.
|
|
112
|
-
xmwai-0.3.
|
|
113
|
-
xmwai-0.3.
|
|
114
|
-
xmwai-0.3.24.dist-info/top_level.txt,sha256=yvGcDI-sggK5jqd9wz0saipZvk3oIE3hNGHlqUjxf0c,6
|
|
115
|
-
xmwai-0.3.24.dist-info/RECORD,,
|
|
110
|
+
xmwai-0.3.25.dist-info/licenses/LICENSE.txt,sha256=bcaIQMrIhdQ3O-PoZlexjmW6h-wLGvHxh5Oksl4ohtc,1066
|
|
111
|
+
xmwai-0.3.25.dist-info/METADATA,sha256=5ZCMmF29_54ujYVrWu8pcBsvCnSlYnzIYA-vCfXvsJc,1198
|
|
112
|
+
xmwai-0.3.25.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
|
|
113
|
+
xmwai-0.3.25.dist-info/top_level.txt,sha256=yvGcDI-sggK5jqd9wz0saipZvk3oIE3hNGHlqUjxf0c,6
|
|
114
|
+
xmwai-0.3.25.dist-info/RECORD,,
|
XMWAI/xmw_photo/__init__.py
DELETED
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|