安卓ai自动化脚本 Yyds.Auto实现 示例 纯ai图像识别自动点击脚本

在这里插入图片描述


```py
import hashlib

def yolo_find_x(specify_labels=None, min_prob: float = 0.9, use_gpu=False) -> List[ResYolo]:
    """
    通过yolo算法识别当前屏幕内容

    :param specify_labels: 是否寻找指定label内容
    :param min_prob:   最低置信率
    :param use_gpu:    是否使用gpu运算

    :returns: 识别结果列表
    """
    if specify_labels is None:
        specify_labels = []
    str_fds = screen_yolo_locate(use_gpu=use_gpu)
    sp_fds = str_fds.split('\n')
    results: List[ResYolo] = list()
    for fd in sp_fds:
        if fd != "":
            result = re.match(
                r'{label=\'(.*)\', cx=(\d+), cy=(\d+), x=(\d+.\d+), y=(\d+.\d+), w=(\d+.\d+), h=(\d+.\d+), '
                r'prob=(\d+.\d+)}',
                fd).groups()
            res_yolo = ResYolo(
                result[0],
                int(result[1]),
                int(result[2]),
                float(result[3]),
                float(result[4]),
                float(result[5]),
                float(result[6]),
                float(result[7]),
            )
            if res_yolo.prob >= min_prob:
                if len(specify_labels) > 0:
                    for it in specify_labels:
                        if re.match(it, res_yolo.label):
                            results.append(res_yolo)
                else:
                    results.append(res_yolo)
    return results

# 对文件进行md5计算,检查文件是否完整
def md5_file(path):
    md5 = hashlib.md5()
    f = open(path, mode="rb")
    md5.update(f.read())
    f.close()
    md5_sum = md5.hexdigest()
    return md5_sum


def main():
    m1 = os.path.exists("/data/local/tmp/yyds.bin") and md5_file("/data/local/tmp/yyds.bin")
    m2 = os.path.exists("/data/local/tmp/yyds.bin") and md5_file("/data/local/tmp/yyds.param")
    if m1 != "dd90463d425e889abb0015bca59f2537" or m2 != "e89facf887d5088177d262119a8fb89b":
        toast("未正确下载ncnn模型文件, 正在下载")
        download("https://----------.com/auto/last-sim-opt.bin", "/data/local/tmp/yyds.bin")
        download("https://----------.com/auto/last-sim-opt.param", "/data/local/tmp/yyds.param")
    else:
        toast("模型已正确配置")

    while True:   
        time.sleep(5)
        print("扫描识别中")
        yolo_res_list = yolo_find_x()
        if len(yolo_res_list) > 0:
            for yolo_res in yolo_res_list:
                if yolo_res.label == "label2" or yolo_res.label == "label1":
                    print("点击:", yolo_res)
                    time.sleep(1)
                    click(yolo_res.cx, yolo_res.cy)
                    toast(str(yolo_res))
### 使用 DeepSeek 工具自动生成代码 DeepSeek 是一款强大的人工智能写作助手,不仅能生成自然语言文本,还可以用于生成编程代码。下面介绍如何利用 DeepSeek 的能力来创建代码示例教程文档。 #### 准备工作 为了开始使用 DeepSeek 创建代码,首先要确保环境已经配置好: - 安装必要的 Python 库 `requests` 和 `tkinter` 以便于后续操作。 ```bash pip install requests markdown ``` 这些库可以帮助处理 HTTP 请求以及图形界面交互[^1]。 #### 调用 DeepSeek API 构建代码片段 接下来展示一段简单的 Python 脚本,该脚本可以向 DeepSeek 发送请求并接收返回的结果作为新生成的代码内容。 ```python import os import requests from tkinter import Tk, simpledialog def get_code(prompt): url = "https://api.deepseek.com/v3/generate" headers = { 'Authorization': f'Bearer {os.getenv("DEEPSEEK_API_KEY")}', 'Content-Type': 'application/json' } payload = {"prompt": prompt} response = requests.post(url, json=payload, headers=headers) if response.status_code == 200: result = response.json() return result['text'] else: raise Exception(f"Error: Received status code {response.status_code}") root = Tk() # Hide the root window root.withdraw() # Prompt user to enter what kind of code they want generated. code_type = simpledialog.askstring(title="Code Generation", prompt="What type of code do you wish to generate?") if code_type is not None and code_type.strip(): try: generated_code = get_code(code_type) print(generated_code) with open('generated_code.md', 'w') as file: file.write("# Generated Code\n") file.write("```python\n") file.write(generated_code + "\n") file.write("```\n") messagebox.showinfo("Success!", "Your requested code has been successfully written into a Markdown file.") except Exception as e: messagebox.showerror("Error", str(e)) else: messagebox.showwarning("Cancelled", "Operation cancelled by user.") root.destroy() ``` 此段程序会弹出对话框让用户输入想要生成哪种类型的代码,之后将结果保存到名为 `generated_code.md` 的文件里,并以合适的格式呈现出来。
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值