XMWAI 0.2.7__py3-none-any.whl → 0.2.8__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/__init__.py CHANGED
@@ -2,6 +2,8 @@ from .core import story, photo, reply, poem, crack # 从子模块导入函数
2
2
  from .magic_core import birthday # 从子模块导入函数到顶层
3
3
  from .bomb_core import bomb # 从子模块导入函数到顶层
4
4
  from .idiom_core import idiom, searchIdiom, get_json_path # 从子模块导入函数到顶层
5
+ from .trial_class import make, get_file_content_as_base64, save_pic, detect_windows_scale # 从子模块导入函数到顶层
5
6
 
6
7
  __all__ = ["story", "photo", "reply", "poem", 'birthday', 'bomb',
7
- "idiom", "searchIdiom", "get_json_path", "crack"] # 可选:明确导出的内容
8
+ "idiom", "searchIdiom", "get_json_path", "crack",
9
+ "make", "get_file_content_as_base64", "save_pic", "detect_windows_scale"] # 可选:明确导出的内容
XMWAI/core.py CHANGED
@@ -5,9 +5,6 @@ import os
5
5
  import zipfile
6
6
 
7
7
 
8
- # AI绘图大师函数
9
-
10
-
11
8
  # U1-02 Story GPT----------------------------------
12
9
  def story(role, time, address, event, key=""):
13
10
  content = role+time+address+event
XMWAI/trial_class.py ADDED
@@ -0,0 +1,171 @@
1
+ import base64
2
+ import urllib
3
+ import requests
4
+ import json
5
+ from PIL import Image
6
+ from PIL import ImageGrab
7
+ from io import BytesIO
8
+ import time
9
+ import os
10
+ import ctypes
11
+
12
+
13
+ def make(screen):
14
+ save_pic(screen)
15
+ while not os.path.exists("pic.png"):
16
+ pass
17
+
18
+ """
19
+ 使用 AK,SK 生成鉴权签名(Access Token)
20
+ :return: access_token,或是None(如果错误)
21
+ """
22
+ API_KEY = "YleMT041wl8zkXhk1Y4AdEuk"
23
+ SECRET_KEY = "xQousjKEqphGwVMKHJlUSGDXp7PiUVpk"
24
+ url = "https://aip.baidubce.com/oauth/2.0/token"
25
+ params = {"grant_type": "client_credentials",
26
+ "client_id": API_KEY, "client_secret": SECRET_KEY}
27
+
28
+ # 获取访问令牌并构建API请求URL
29
+ access_token = str(requests.post(
30
+ url, params=params).json().get("access_token"))
31
+ create_url = f"https://aip.baidubce.com/rpc/2.0/ernievilg/v1/txt2imgv2?access_token={access_token}"
32
+ query_url = f"https://aip.baidubce.com/rpc/2.0/ernievilg/v1/getImgv2?access_token={access_token}"
33
+
34
+ # 读取图像并转换为Base64编码
35
+ with open("pic.png", "rb") as image_file:
36
+ base64_string = base64.b64encode(image_file.read()).decode('utf-8')
37
+
38
+ # 构建创建任务的请求参数
39
+ create_payload = json.dumps({
40
+ "prompt": "参考当前图,希望画面卡通一些,画面可以丰富一些,内容积极向上,参考宫崎骏画风",
41
+ "width": 1024,
42
+ "height": 1024,
43
+ "image": base64_string,
44
+ "change_degree": 1
45
+ }, ensure_ascii=False)
46
+
47
+ headers = {
48
+ 'Content-Type': 'application/json',
49
+ 'Accept': 'application/json'
50
+ }
51
+
52
+ # 发送创建任务请求
53
+ response = requests.post(create_url, headers=headers,
54
+ data=create_payload.encode("utf-8"))
55
+ response.raise_for_status() # 检查请求是否成功
56
+ task_id = response.json()["data"]["task_id"]
57
+ # print(f"任务已创建,ID: {task_id}")
58
+
59
+ # 轮询检查任务状态
60
+ query_payload = json.dumps({"task_id": task_id}, ensure_ascii=False)
61
+ task_status = "RUNNING"
62
+ print("AI图片生成中.......")
63
+ while task_status == "RUNNING":
64
+ time.sleep(30)
65
+ response = requests.post(
66
+ query_url, headers=headers, data=query_payload.encode("utf-8"))
67
+ response.raise_for_status()
68
+ task_status = response.json()["data"]["task_status"]
69
+ # print(f"任务状态: {task_status}")
70
+
71
+ # 处理任务结果
72
+ if task_status == "SUCCESS":
73
+ picture = requests.get(response.json()[
74
+ "data"]["sub_task_result_list"][0]["final_image_list"][0]["img_url"])
75
+ image_data = BytesIO(picture.content)
76
+ image = Image.open(image_data)
77
+ image.save('image.gif')
78
+ os.system("image.gif")
79
+ else:
80
+ print(f"任务失败,状态: {task_status}")
81
+
82
+
83
+ def get_file_content_as_base64(path, urlencoded=False):
84
+ """
85
+ 获取文件base64编码
86
+ :param path: 文件路径
87
+ :param urlencoded: 是否对结果进行urlencoded
88
+ :return: base64编码信息
89
+ """
90
+ with open(path, "rb") as f:
91
+ content = base64.b64encode(f.read()).decode("utf8")
92
+ if urlencoded:
93
+ content = urllib.parse.quote_plus(content)
94
+ return content
95
+
96
+
97
+ def save_pic(screen, output_file="pic.png"):
98
+ """
99
+ 精准截取turtle绘图区域,不包含窗口边框和标题栏
100
+ 专为Windows系统优化,支持高DPI缩放
101
+
102
+ 参数:
103
+ screen: turtle的Screen对象
104
+ output_file: 输出文件名
105
+ """
106
+ canvas = screen.getcanvas()
107
+ screen.update()
108
+
109
+ try:
110
+ # 获取画布位置和大小
111
+ x = canvas.winfo_rootx()
112
+ y = canvas.winfo_rooty()
113
+ width = canvas.winfo_width()
114
+ height = canvas.winfo_height()
115
+
116
+ # 检测Windows屏幕缩放比例
117
+ scale_factor = detect_windows_scale()
118
+ # print(f"检测到屏幕缩放比例: {scale_factor}x")
119
+
120
+ # 调整截图区域,排除窗口边框
121
+ # 典型Windows窗口边框宽度约为8像素,标题栏约为30像素
122
+ border_width = int(8 * scale_factor)
123
+ title_height = int(30 * scale_factor)
124
+
125
+ # 计算实际绘图区域
126
+ img = ImageGrab.grab(
127
+ bbox=(
128
+ x + border_width, # 左边界,排除左侧边框
129
+ y + title_height, # 上边界,排除标题栏和上边框
130
+ x + width - border_width, # 右边界,排除右侧边框
131
+ y + height - border_width # 下边界,排除底部边框
132
+ )
133
+ )
134
+
135
+ # 保存为PNG
136
+ img.save(output_file)
137
+ # print(f"已保存图形到 {output_file} (尺寸: {img.size})")
138
+ except Exception as e:
139
+ print(f"截图时出错: {e}")
140
+ print("提示: 尝试使用save_turtle_canvas_fallback函数或手动截图")
141
+
142
+
143
+ def detect_windows_scale():
144
+ """
145
+ 检测Windows系统的屏幕缩放比例
146
+ 优先使用高精度方法,失败则降级使用兼容性方法
147
+ """
148
+ try:
149
+ # 高精度方法:获取系统DPI
150
+ user32 = ctypes.windll.user32
151
+ user32.SetProcessDPIAware()
152
+
153
+ # 尝试获取系统DPI (Windows 8.1及以上)
154
+ if hasattr(user32, 'GetDpiForSystem'):
155
+ dpi = user32.GetDpiForSystem()
156
+ return dpi / 96.0 # Windows标准DPI是96
157
+
158
+ # 尝试获取显示器DPI (Windows 10及以上)
159
+ if hasattr(user32, 'GetDpiForWindow'):
160
+ root = tk.Tk()
161
+ dpi = user32.GetDpiForWindow(root.winfo_id())
162
+ root.destroy()
163
+ return dpi / 96.0
164
+
165
+ # 兼容方法:获取屏幕尺寸并与标准尺寸比较
166
+ screen_width = user32.GetSystemMetrics(0)
167
+ return screen_width / 1920.0 # 假设标准分辨率为1920x1080
168
+ except Exception as e:
169
+ print(f"检测缩放比例时出错: {e}")
170
+ print("使用默认缩放比例1.0")
171
+ return 1.0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: XMWAI
3
- Version: 0.2.7
3
+ Version: 0.2.8
4
4
  Summary: Small code King AI related library
5
5
  Home-page: https://github.com/Tonykai88/XMWAI.git
6
6
  Author: pydevelopment
@@ -12,6 +12,7 @@ Requires-Python: >=3.7.0
12
12
  Description-Content-Type: text/markdown
13
13
  License-File: LICENSE.txt
14
14
  Requires-Dist: requests>=2.32.3
15
+ Requires-Dist: Pillow>=11.1.0
15
16
  Dynamic: author
16
17
  Dynamic: author-email
17
18
  Dynamic: classifier
@@ -1,9 +1,10 @@
1
- XMWAI/__init__.py,sha256=91jaQmcGqp_B4i68bNfn_0m6JTFzz-itTiCmt__vIR8,487
1
+ XMWAI/__init__.py,sha256=lkYAOe3hpF_pg8UMnTVqDCy4X63Ozu7VmsvNY_sC6e0,701
2
2
  XMWAI/bomb_core.py,sha256=h2ZPH3SuoG2L_XOf1dcK8p3lhw5QzhneWl2yMLj1RiU,1819
3
3
  XMWAI/cookbook_core.py,sha256=mo3IYgh_bYD_3vH2Stkjwo9okFOb4abooZeJ-Djx6VU,3675
4
- XMWAI/core.py,sha256=H4EpXmXXakVNleUKyUMVnl3AmR8XjjVLsVfGvsLRUqg,7933
4
+ XMWAI/core.py,sha256=SxzfbOW7WZALuA5fQ4dGieJR2-roxufjXQ_mqwGDg3E,7905
5
5
  XMWAI/idiom_core.py,sha256=yU-VHhqqoutVm6GVikcjL3m9yuB1hUsFBpPYvwY4n5g,1689
6
6
  XMWAI/magic_core.py,sha256=Ms4b12PJ8rjsmceg1VUqWCWx2ebvdhLp4sIF6K_Vaok,3491
7
+ XMWAI/trial_class.py,sha256=RrpsRQ1Jtl1Qivht08nzGMgeTf-4I7jW8YGnDlBKRzk,6056
7
8
  XMWAI/file/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
8
9
  XMWAI/file/idiom.json,sha256=HUtPRUzhxBbWoasjadbmbA_5ngQ5AXLu9weQSZ4hzhk,10319857
9
10
  XMWAI/gif/0.gif,sha256=LGpAReVTyZEb1J-bWYTpxxHbIxmLJ-3wA0lw4cBqdsY,303
@@ -93,8 +94,8 @@ XMWAI/gif/84.gif,sha256=6Ip_uQmvrr2fagLXu1YqWyI_DL2PVVtKCPtmNtzt3P4,38767
93
94
  XMWAI/gif/85.gif,sha256=6Ip_uQmvrr2fagLXu1YqWyI_DL2PVVtKCPtmNtzt3P4,38767
94
95
  XMWAI/gif/9.gif,sha256=cPouth-xwc3QPcg2m6HMP2OD1ZCeRBD_-RPImvvKAA0,9485
95
96
  XMWAI/gif/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
96
- xmwai-0.2.7.dist-info/licenses/LICENSE.txt,sha256=bcaIQMrIhdQ3O-PoZlexjmW6h-wLGvHxh5Oksl4ohtc,1066
97
- xmwai-0.2.7.dist-info/METADATA,sha256=-pGe6LcF2Fy7GeNWgQxhP8dEOcKyRpVZ_HeEQ2FnQDY,1033
98
- xmwai-0.2.7.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
99
- xmwai-0.2.7.dist-info/top_level.txt,sha256=yvGcDI-sggK5jqd9wz0saipZvk3oIE3hNGHlqUjxf0c,6
100
- xmwai-0.2.7.dist-info/RECORD,,
97
+ xmwai-0.2.8.dist-info/licenses/LICENSE.txt,sha256=bcaIQMrIhdQ3O-PoZlexjmW6h-wLGvHxh5Oksl4ohtc,1066
98
+ xmwai-0.2.8.dist-info/METADATA,sha256=sIk8AWvgMlf3RWaKNl4L4CmcSNEo3v_Af04vS69eZRI,1064
99
+ xmwai-0.2.8.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
100
+ xmwai-0.2.8.dist-info/top_level.txt,sha256=yvGcDI-sggK5jqd9wz0saipZvk3oIE3hNGHlqUjxf0c,6
101
+ xmwai-0.2.8.dist-info/RECORD,,
File without changes