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