XMWAI 0.3.27__py3-none-any.whl → 0.4.1__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/core.py CHANGED
@@ -1,9 +1,9 @@
1
- import re
2
- import requests
3
- import json
4
1
  import os
5
2
  import turtle
3
+ import json
4
+ import re
6
5
  import zipfile
6
+ import requests
7
7
 
8
8
 
9
9
  # U1-02 Story GPT----------------------------------
@@ -36,7 +36,7 @@ def story(role, time, address, event, key=""):
36
36
  print("秘钥错误!请重新输入!")
37
37
  return "秘钥错误!请重新输入!"
38
38
  header = {
39
- "Authorization": "Bearer paNyL"+key+"OpyOBmflKZp:yhBhAlSFMwaqlVKAtDbv"
39
+ "Authorization": "AQRVzyCpgQdFQnclClou:FwsxoAqSoVsEedfhiDkK"
40
40
  }
41
41
  response = requests.post(url, headers=header, json=data, stream=True)
42
42
 
@@ -135,7 +135,7 @@ def reply(role, content, key=""):
135
135
  print("秘钥错误!请重新输入!")
136
136
  return "秘钥错误!请重新输入!"
137
137
  header = {
138
- "Authorization": "Bearer paNyL"+key+"OpyOBmflKZp:yhBhAlSFMwaqlVKAtDbv"
138
+ "Authorization": "AQRVzyCpgQdFQnclClou:FwsxoAqSoVsEedfhiDkK"
139
139
  }
140
140
  response = requests.post(url, headers=header, json=data, stream=True)
141
141
 
XMWAI/web_core.py CHANGED
@@ -1,19 +1,19 @@
1
1
  import os
2
2
  import json
3
3
  import requests
4
- from flask import Flask, render_template
5
4
  import re
5
+ import time
6
6
  import shutil
7
- from pyecharts import options as opts
8
- from pyecharts.charts import Pie
9
7
  import webbrowser
10
8
  import threading
11
- import time
9
+ from flask import Flask, render_template
10
+ from pyecharts import options as opts
11
+ from pyecharts.charts import Pie
12
12
  from importlib.resources import files
13
13
  from pathlib import Path
14
14
 
15
15
 
16
- '''Super堡'''
16
+ '''U3-04 Super堡'''
17
17
  # 搭建flask框架
18
18
  app = Flask(
19
19
  __name__,
@@ -77,7 +77,8 @@ def start_server(port=5050):
77
77
  pass
78
78
 
79
79
 
80
- '''Random料理屋'''
80
+
81
+ '''U3-03 Random料理屋'''
81
82
  # 食材对应 emoji
82
83
  emoji_dict = {
83
84
  "鸡": "🍗", "牛": "🥩", "猪": "🥓", "鱼": "🐟", "虾": "🦐", "蟹": "🦀",
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: XMWAI
3
- Version: 0.3.27
3
+ Version: 0.4.1
4
4
  Summary: Small code King AI related library
5
5
  Home-page: https://github.com/Tonykai88/XMWAI.git
6
6
  Author: pydevelopment
@@ -1,11 +1,10 @@
1
1
  XMWAI/__init__.py,sha256=-0GLZK0X3vEuTbu5n2AX3cWw6SXtJTERtBIAssZq41o,908
2
2
  XMWAI/bomb_core.py,sha256=h2ZPH3SuoG2L_XOf1dcK8p3lhw5QzhneWl2yMLj1RiU,1819
3
- XMWAI/core.py,sha256=XG2ZLhW9CETUQMr-8FLZonL_aQg9jfohGnm9oU5XyVQ,10018
3
+ XMWAI/core.py,sha256=kgUYQ3oaycFdF6KnYArbu3jP9l0heq1_nRWcWKi-uFg,9998
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 copy.py,sha256=3nXhv2VdLT5RbWpRF2f7bBPmMaEDt5ZvLl_LarseByI,10781
8
- XMWAI/web_core.py,sha256=3bDNyo5n-l2TsDfuPJv_DRT6sKxr6ZcYF176uIOQOVM,10913
7
+ XMWAI/web_core.py,sha256=7awPg1kYW3lYrbgylqJvUF3g050bn6H21PgmQ7Kv1wA,10927
9
8
  XMWAI/file/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
10
9
  XMWAI/file/idiom.json,sha256=HUtPRUzhxBbWoasjadbmbA_5ngQ5AXLu9weQSZ4hzhk,10319857
11
10
  XMWAI/gif/0.gif,sha256=LGpAReVTyZEb1J-bWYTpxxHbIxmLJ-3wA0lw4cBqdsY,303
@@ -108,8 +107,8 @@ XMWAI/static/images/tomato.png,sha256=FEOEAOdUhW_BDFgTpxOkYc0I5Iu29_gtHb3RIPEej0
108
107
  XMWAI/templates/burger.html,sha256=vDnxpSW8phetyScySsalScZnFKl3LNpy5lJjKxGXgbI,3320
109
108
  XMWAI/templates/nutrition_pie.html,sha256=yJVXI28i-UfvF0xOXGSNLMb8oCJNhh2J3zoRDr5_7DM,5567
110
109
  XMWAI/templates/创意菜谱.html,sha256=RcDgH58QLyUJ9A59wobu3wvchGBY1snVsXcZQZam5M0,4805
111
- xmwai-0.3.27.dist-info/licenses/LICENSE.txt,sha256=bcaIQMrIhdQ3O-PoZlexjmW6h-wLGvHxh5Oksl4ohtc,1066
112
- xmwai-0.3.27.dist-info/METADATA,sha256=4VP7uX2hEuNK_fvh1PoRZEdaTljaEYCJ5zXcYoWinl8,1198
113
- xmwai-0.3.27.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
114
- xmwai-0.3.27.dist-info/top_level.txt,sha256=yvGcDI-sggK5jqd9wz0saipZvk3oIE3hNGHlqUjxf0c,6
115
- xmwai-0.3.27.dist-info/RECORD,,
110
+ xmwai-0.4.1.dist-info/licenses/LICENSE.txt,sha256=bcaIQMrIhdQ3O-PoZlexjmW6h-wLGvHxh5Oksl4ohtc,1066
111
+ xmwai-0.4.1.dist-info/METADATA,sha256=x_-w3xgeWZzH5Hfvt6b8GDK-fAz92WYlXDTxY3kFq4k,1197
112
+ xmwai-0.4.1.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
113
+ xmwai-0.4.1.dist-info/top_level.txt,sha256=yvGcDI-sggK5jqd9wz0saipZvk3oIE3hNGHlqUjxf0c,6
114
+ xmwai-0.4.1.dist-info/RECORD,,
XMWAI/web_core copy.py DELETED
@@ -1,283 +0,0 @@
1
- import os
2
- import json
3
- import requests
4
- from flask import Flask, render_template
5
- import re
6
- from pyecharts import options as opts
7
- from pyecharts.charts import Pie
8
- import webbrowser
9
- import threading
10
- import time
11
- from importlib.resources import files
12
- from pathlib import Path
13
-
14
-
15
- '''Super堡'''
16
- # 搭建flask框架
17
- app = Flask(
18
- __name__,
19
- template_folder=os.path.join(os.path.dirname(__file__), "templates"),
20
- static_folder=os.path.join(os.path.dirname(__file__), "static")
21
- )
22
-
23
- mapping = {
24
- "面包底": "BottomBun",
25
- "生菜": "lettuce",
26
- "番茄": "tomato",
27
- "牛肉饼": "beef",
28
- "芝士": "cheese",
29
- "酱料": "sauce",
30
- "面包顶": "TopBun"
31
- }
32
-
33
- ingredients_order = []
34
-
35
-
36
- def burger(result):
37
- global ingredients_order
38
- inputs = result.strip().split("→")
39
- ingredients_order = [mapping[i] for i in inputs]
40
- ingredients_order = ingredients_order[::-1]
41
-
42
- # 自动启动服务器
43
- start_server()
44
- return ingredients_order
45
-
46
-
47
- @app.route('/')
48
- def show_burger():
49
- return render_template("burger.html", ingredients=ingredients_order)
50
-
51
-
52
- def run_server(port=5050):
53
- """在后台线程中运行服务器"""
54
- app.run(debug=False, host='0.0.0.0', port=port, use_reloader=False)
55
-
56
-
57
- def start_server(port=5050):
58
- """启动服务器并打开浏览器"""
59
- url = f"http://127.0.0.1:{port}/"
60
-
61
- # 在后台线程中启动服务器
62
- server_thread = threading.Thread(target=run_server, args=(port,))
63
- server_thread.daemon = True
64
- server_thread.start()
65
-
66
- # 等待服务器启动
67
- time.sleep(2)
68
-
69
- # 打开浏览器
70
- webbrowser.open(url)
71
-
72
- # 保持服务器运行
73
- try:
74
- server_thread.join()
75
- except KeyboardInterrupt:
76
- pass
77
-
78
-
79
- '''Random料理屋'''
80
- # 食材对应 emoji
81
- emoji_dict = {
82
- "鸡": "🍗", "牛": "🥩", "猪": "🥓", "鱼": "🐟", "虾": "🦐", "蟹": "🦀",
83
- "豆腐": "🧈", "土豆": "🥔", "胡萝卜": "🥕", "西红柿": "🍅", "青菜": "🥬",
84
- "菠菜": "🥬", "蘑菇": "🍄", "玉米": "🌽", "米饭": "🍚", "面条": "🍜",
85
- "面包": "🍞", "奶酪": "🧀", "鸡蛋": "🥚", "牛奶": "🥛", "橙子": "🍊",
86
- "苹果": "🍎", "香蕉": "🍌"
87
- }
88
-
89
- # 动作对应 emoji
90
- action_dict = {
91
- "炒": "🍳", "煮": "🍲", "烤": "🔥", "蒸": "♨️", "炸": "🍟", "拌": "🥣",
92
- "切": "🔪", "腌": "🫙", "炖": "🥘"
93
- }
94
-
95
-
96
- def add_emoji_to_text(text):
97
- for key, val in action_dict.items():
98
- text = re.sub(f'({key})', f'{val} \\1', text)
99
- for key, val in emoji_dict.items():
100
- text = re.sub(f'({key})', f'{val} \\1', text)
101
- return text
102
-
103
-
104
- def format_section_steps(text):
105
- lines = [line.strip() for line in text.strip().split("\n") if line.strip()]
106
- lines = lines[:50]
107
- return "<br>".join(add_emoji_to_text(line) for line in lines)
108
-
109
-
110
- def parse_nutrition_section(text):
111
- """解析 API 返回的营养 JSON 并提取数值"""
112
- default_data = {"蛋白质": 30, "脂肪": 20, "碳水化合物": 50, "维生素": 10, "矿物质": 5}
113
-
114
- def extract_number(val):
115
- if isinstance(val, (int, float)):
116
- return val
117
- if isinstance(val, str):
118
- match = re.search(r"(\d+(\.\d+)?)", val)
119
- if match:
120
- return float(match.group(1))
121
- return 0
122
-
123
- try:
124
- match = re.search(r"\{.*\}", text, re.S)
125
- if match:
126
- parsed = json.loads(match.group())
127
- result = {}
128
- for key in default_data.keys():
129
- if key in parsed:
130
- val = parsed[key]
131
- if isinstance(val, dict):
132
- total = sum(extract_number(v) for v in val.values())
133
- result[key] = total
134
- else:
135
- result[key] = extract_number(val)
136
- else:
137
- result[key] = default_data[key]
138
- return result
139
- except Exception as e:
140
- print("JSON解析失败:", e)
141
- return default_data
142
-
143
-
144
- def generate_pie_chart(data_dict, filename: Path):
145
- data = [(k, v) for k, v in data_dict.items()]
146
- pie = (
147
- Pie(init_opts=opts.InitOpts(width="1100px", height="500px"))
148
- .add("", data)
149
- .set_global_opts(title_opts=opts.TitleOpts(title="营养价值分布"))
150
- .set_series_opts(label_opts=opts.LabelOpts(formatter="{b}: {c}"))
151
- )
152
- pie.render(str(filename))
153
- return filename
154
-
155
-
156
- def cookbook(m, t, s, key):
157
- if key != "CaJQ":
158
- return "密钥错误,无法生成食谱。"
159
-
160
- # 调用 API 生成创意菜谱
161
- messagesList = [
162
- {"role": "system", "content": "天马行空的创意菜厨师"},
163
- {"role": "user", "content": f"请以{m}为主菜,{s}为配菜,{t}为烹饪方式写一个创意食谱,"
164
- "结果中不要*,并且结果只需要创意灵感、食材清单、制作步骤、"
165
- "食材搭配的营养价值四种大标题内容。食材搭配的营养价值部分请输出标准 JSON,"
166
- "键为蛋白质、脂肪、碳水化合物、维生素、矿物质,值为数值及说明。"}
167
- ]
168
-
169
- url = "https://qianfan.baidubce.com/v2/chat/completions"
170
- payload = json.dumps({"model": "ernie-4.5-turbo-32k",
171
- "messages": messagesList}, ensure_ascii=False)
172
- headers = {
173
- "Content-Type": "application/json",
174
- "appid": "",
175
- "Authorization": "Bearer bce-v3/ALTAK-cGbxpVA5AbSz6h8nbLaFh/b539762075d55c76d93dc78bcf0a91beeaf0490a"
176
- }
177
-
178
- try:
179
- response = requests.post(url, headers=headers,
180
- data=payload.encode("utf-8"))
181
- response_data = response.json()
182
- content = response_data["choices"][0]["message"]["content"]
183
- except Exception as e:
184
- return f"接口调用失败:{e}"
185
-
186
- # 分割内容
187
- sections = re.split(r"(创意灵感|食材清单|制作步骤|食材搭配的营养价值)", content)
188
- body_sections = [""]*4
189
- title_map = {"创意灵感": 0, "食材清单": 1, "制作步骤": 2, "食材搭配的营养价值": 3}
190
- i = 1
191
- while i < len(sections):
192
- header = sections[i]
193
- text_sec = sections[i+1] if i+1 < len(sections) else ""
194
- idx = title_map.get(header.strip(), None)
195
- if idx is not None:
196
- body_sections[idx] = text_sec.strip()
197
- i += 2
198
-
199
- # 模板和图片目录
200
- templates_dir = Path(files("XMWAI") / "templates")
201
- templates_dir.mkdir(exist_ok=True)
202
-
203
- # 静态图片路径(PyPI 安装后能读取)
204
- bg_path = Path(files("XMWAI") / "static" / "images" / "bg.jpeg")
205
-
206
- # 生成饼图文件
207
- pie_chart_file = templates_dir / "nutrition_pie.html"
208
- nutrient_data = parse_nutrition_section(body_sections[3])
209
- generate_pie_chart(nutrient_data, pie_chart_file)
210
-
211
- # 添加 emoji
212
- m_emoji = add_emoji_to_text(m)
213
- s_emoji = add_emoji_to_text(s)
214
- t_emoji = add_emoji_to_text(t)
215
-
216
- # 步骤顺序 HTML
217
- step_titles = ["食材搭配的营养价值", "创意灵感", "食材清单", "制作步骤"]
218
- steps_order = [3, 0, 1, 2]
219
- steps_html = ""
220
- for i, idx in enumerate(steps_order):
221
- if idx == 3:
222
- section_content_html = "根据食材搭配生成的营养价值饼图如下 ⬇️"
223
- else:
224
- section_content_html = format_section_steps(body_sections[idx])
225
- steps_html += f"""
226
- <div class="step-card" style="animation-delay:{(i+1)*0.2}s;">
227
- <div class="step-title">Step {i+1} 📝 {step_titles[i]}</div>
228
- <div class="step-content">{section_content_html}</div>
229
- </div>
230
- """
231
-
232
- # HTML 页面
233
- html = f"""
234
- <!DOCTYPE html>
235
- <html lang="zh">
236
- <head>
237
- <meta charset="UTF-8">
238
- <title>创意菜谱</title>
239
- <style>
240
- html, body {{ margin:0; padding:0; width:100%; height:100%; overflow-x:hidden; }}
241
- body {{ font-family:"微软雅黑",sans-serif; background:#2c2c2c url('{bg_path.resolve()}') no-repeat center center fixed; background-size:cover; color:#333; }}
242
- .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); }}
243
- .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; }}
244
- .banner h1 {{ color:#fff; font-size:28px; text-shadow:1px 1px 3px #666; }}
245
- p {{ font-size:18px; margin:8px 0; }}
246
- .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; }}
247
- .step-title {{ font-weight:bold; padding:10px 15px; cursor:pointer; background:#ffb347; color:#fff; border-bottom:1px solid #ffd27f; }}
248
- .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; }}
249
- .step-card.hover .step-content {{ opacity:1; max-height:800px; }}
250
- iframe {{ width:100%; height:500px; border:none; margin-top:20px; }}
251
- @keyframes fadeInUp {{ to {{ opacity:1; transform:translateY(0) scale(1); }} }}
252
- </style>
253
- </head>
254
- <body>
255
- <div class="container">
256
- <div class="banner"><h1>🍽 {m+t+s}</h1></div>
257
- <p>🍖 <strong>主菜:</strong>{m_emoji}</p>
258
- <p>🥗 <strong>配菜:</strong>{s_emoji}</p>
259
- <p>👩‍🍳 <strong>做法:</strong>{t_emoji}</p>
260
- {steps_html}
261
- <iframe src="{pie_chart_file.resolve()}"></iframe>
262
- </div>
263
- <script>
264
- const steps = document.querySelectorAll('.step-card');
265
- steps.forEach(card => {{
266
- card.addEventListener('mouseenter', () => {{ card.classList.add('hover'); }});
267
- card.addEventListener('mouseleave', () => {{ card.classList.remove('hover'); }});
268
- }});
269
- </script>
270
- </body>
271
- </html>
272
- """
273
-
274
- # 保存 HTML 文件到包内 templates
275
- safe_title = re.sub(r'[\/\\:*?"<>|]', "", m+t+s)
276
- html_file = templates_dir / f"{safe_title}_菜谱.html"
277
- with open(html_file, "w", encoding="utf-8") as f:
278
- f.write(html)
279
-
280
- # 打开浏览器
281
- webbrowser.open(f"file://{html_file.resolve()}")
282
-
283
- return content
File without changes