先统一安装所有依赖库一行命令bash运行pip install numpy scikit-learn torch torchvision pillow python-dotenv openai1️⃣ AI 预测房价 / 销量 / 成绩通用python运行from sklearn.linear_model import LinearRegression import numpy as np # 数据学习时长(小时) - 考试分数 study_hours np.array([[1], [2], [3], [4], [5], [6], [7]]) scores np.array([50, 60, 70, 75, 85, 90, 95]) # AI模型 model LinearRegression() model.fit(study_hours, scores) # 预测 hour float(input(输入学习时长(小时))) pred model.predict([[hour]]) print(fAI 预测分数{pred[0]:.1f} 分)2️⃣ AI 图片识别识别 1000 种物体猫 / 狗 / 车 / 飞机…python运行import torch import torchvision.models as models import torchvision.transforms as transforms from PIL import Image import json # 加载预训练AI模型 model models.mobilenet_v2(weightsmodels.MobileNet_V2_Weights.DEFAULT) model.eval() # 图片预处理 transform transforms.Compose([ transforms.Resize((224, 224)), transforms.ToTensor(), transforms.Normalize(mean[0.485, 0.456, 0.406], std[0.229, 0.224, 0.225]) ]) # 下载标签文件运行一次即可 import urllib.request url https://raw.githubusercontent.com/anishathalye/imagenet-simple-labels/master/imagenet-simple-labels.json urllib.request.urlretrieve(url, labels.json) # 加载标签 with open(labels.json) as f: labels json.load(f) # 加载图片把这里换成你的图片路径 img Image.open(test.jpg).convert(RGB) img_tensor transform(img).unsqueeze(0) # AI识别 with torch.no_grad(): outputs model(img_tensor) _, predicted torch.max(outputs, 1) print(AI 识别结果, labels[predicted.item()])3️⃣ AI 聊天机器人本地运行不用 APIpython运行# 简易规则版聊天机器人 def chatbot_response(msg): msg msg.lower() if 你好 in msg or hi in msg: return 你好呀我是你的AI聊天机器人 elif 名字 in msg: return 我叫Python小助手 elif 年龄 in msg or 多大 in msg: return 我永远18岁 elif 再见 in msg or 退出 in msg: return 再见下次再聊哦 else: return 我在听呢你可以继续说 # 开始聊天 print(AI聊天机器人输入 退出 结束) while True: user input(你) if 退出 in user: print(机器人再见) break res chatbot_response(user) print(机器人, res)4️⃣ Python 调用 ChatGPT 做自动化最强 AI 工具python运行from openai import OpenAI # 配置你的API Key去OpenAI官网获取 client OpenAI(api_key你的API_KEY) def ask_gpt(prompt): response client.chat.completions.create( modelgpt-3.5-turbo, messages[{role: user, content: prompt}] ) return response.choices[0].message.content # 自动让AI写文案、写代码、总结、翻译都行 prompt input(请输入你想让AI做什么) result ask_gpt(prompt) print(\nAI 回答) print(result) 我再送你一个超级自动化 AI 工具免费不用 key把上面所有功能合成一个AI 助手python运行def ai_assistant(): print( 全能AI自动化助手 ) print(1预测 2图片识别 3聊天 4退出) choice input(请选择功能) if choice 1: print(\n【AI预测】) # 这里放上面预测代码 from sklearn.linear_model import LinearRegression import numpy as np x np.array([[1],[2],[3],[4],[5]]) y np.array([10,20,30,40,50]) m LinearRegression() m.fit(x,y) num float(input(输入数字)) print(预测结果, m.predict([[num]])[0]) elif choice 3: print(\n【AI聊天】) # 这里放上面聊天代码 while True: u input(你) if u退出:break print(机器人我在你说啥我都听) ai_assistant()