django搭建一个AI博客进行YouTube视频自动生成文字博客

文章目录

  • 一、生成Django框架
  • 二、项目代码(前端)
    • 1、编写前端代码(正文界面)
      • 1.1、生产html框架
      • 1.2、添加live preview扩展
      • 1.3、更改title元素中文本
      • 1.4、添加CDN(CSS)样式链接
      • 1.5、nav标签
      • 1.6、在body标签中添加类
      • 1.7、nav下创建div标签
      • 1.8、当前界面预览
      • 1.9、在div标签后添加footer
      • 1.10、完整代码
    • 2、编写前端代码(登录注册界面)
      • 2.1、创建html框架并添加cdn样式表
      • 2.2、创建密码登录框(完整代码)
    • 3、编写前端代码(注册页面)
      • 3.1、完整代码
    • 4、编写前端代码(文章保存记录)
      • 4.1、完整代码
    • 5、编写前端代码(文章页面)
      • 5.1、完整代码
  • 三、Django代码(后端)
    • 1、添加app功能
    • 2、blog_generato添加index视图(views.py)
    • 3、添加数据库
    • 4、创建管理员用户
      • 4.1、后台中文化
      • 4.2、在blog_generato下的urls.py中添加url
      • 4.3、将注册登录html页面添加到views中
    • 5、获取ai转换
    • 6、获取openai秘钥
  • 四、修改后的完整代码(前后端)
    • 1、 ai_blog_app--> settings.py
    • 2、ai_blog_app--> urls.py
    • 3、ai_blog_app --> _init_.py
    • 4、blog_generato --> admin.py
    • 5、blog_generato --> models.py
    • blog_generato --> urls.py
    • 7、 blog_generato --> viwes.py
    • 8、templates --> all-logs.html(修改后)
    • 9、templates -->blog-details.html(修改后)
    • 10、templates -->index.html(修改后)
    • 11、templates -->login.html(修改后)
    • 12、templates -->signup.html(修改后)


一、生成Django框架

我这里使用的是PyCharm 2021.3.3

创建流程:

  • 打开PyCharm
  • 点击左上角File
  • 选择New Project
  • 选择Django
  • 最后点击Create
  • 然后在Django项目中添加一个文件夹,以便用来保存html文件
    在这里插入图片描述

二、项目代码(前端)

1、编写前端代码(正文界面)

1.1、生产html框架

使用Visual Studio Code打开你刚刚在django项目创建的用来编写html文件的文件夹

首先创建一个index.html文件
在这里插入图片描述
英文感叹号加回车键生成html框架
在这里插入图片描述

1.2、添加live preview扩展

Live Preview 扩展的作用是在VSCode内部实现边写边预览的效果。

这个扩展主要用于HTML文件,它允许开发者在编写代码的同时实时查看代码渲染的效果,而不需要离开编辑器或打开浏览器。具体来说,Live Preview 扩展提供了以下几个便利的功能:

实时预览:当你在编辑HTML文件时,任何对代码的更改都会立即反映在预览窗口中,这样你可以即时看到改动效果,提高开发效率。

高度集成:作为微软官方插件,Live Preview与VSCode的集成程度非常高,使用起来非常流畅和方便。

简化操作:相比于其他如LiveServer等插件,Live Preview无需额外的保存和重启服务步骤,减少了繁琐的操作流程。

易于安装:你可以通过VSCode的扩展商店直接搜索并安装Live Preview,安装过程简单快捷。

自定义布局:你可以根据自己的需要调整预览窗口的位置,选择向上/下/左/右拆分,以适应不同的工作流程和屏幕布局。

在这里插入图片描述
直接安装即可

右键点击index.html文件,然后选择显示预览
在这里插入图片描述

1.3、更改title元素中文本

更改第六行的title元素

<title>AI 博客</title>

然后ctrl + s保存

1.4、添加CDN(CSS)样式链接

在第七行添加css的链接

<link href="https://cdn.jsdelivr.net/npm/tailwindcss@2.2.19/dist/tailwind.min.css" rel="stylesheet">

1.5、nav标签

从第十一行开始为nav标签

<nav ></nav>

在第一个nav标签中添加一个类

<nav class="bg-blue-600 p-4 text-white flex justify-between"></nav>

在nav标签中添加div标签

<div><h1 class="text-3xl font-bold">AI 博客生成器</h1></div><div><a href="#" class="text-white hover:underline">注销</a></div>

1.6、在body标签中添加类

<body class="flex flex-col min-h-scrren bg-gray-100 font-sans antialised">

1.7、nav下创建div标签

创建h2标签之前先要创建三对div标签,三十八行到四十五行

   <div><div><div><h2>欢迎来到AI博客生成器</h2></div></div></div>

在最后一对div标签中创建h2和p标签

   <div><div><div class="text-center"><h2 class="text-2xl font-semibold mb-4">欢迎来到AI博客生成器</h2><p class="text-gray-700">使用人工智能从YouTube视频中生成高质量的博客文章。只需输入链接到下面的YouTube视频,让人工智能为你创建内容!</p></div></div>

为前面两对div添加元素

   <div class="flex-grow container mx-auto mt-10 px-4 sm:px-0"><div class="max-w-3xl mx-auto bg-white p-6 rounded-lg"><div class="text-center"><h2 class="text-2xl font-semibold mb-4">欢迎来到AI博客生成器</h2><p class="text-gray-700">使用人工智能从YouTube视频中生成高质量的博客文章。只需输入链接到下面的YouTube视频,让人工智能为你创建内容!</p></div></div>

1.8、当前界面预览

在这里插入图片描述
在第二对div标签中添加内容

    <div class="flex-grow container mx-auto mt-10 px-4 sm:px-0"><div class="max-w-3xl mx-auto bg-white p-6 rounded-lg shadow-md transition-transform transform hover:scale-105 flex flex-col"><div class="text-center"><h2 class="text-2xl font-semibold mb-4">欢迎来到AI博客生成器</h2><p class="text-gray-700">使用人工智能从YouTube视频中生成高质量的博客文章。只需输入链接到下面的YouTube视频,让人工智能为你创建内容!</p></div><br><div><h2 class="text-xl mb-4 font-semibold">请输入YouTube视频链接</h2><div class="flex space-x-4"><input id="youtubeLink" type="url" placeholder="请输入YouTube链接..." class="flex-grow p-2 border border-blue-400 rounded-l-md "><button id="generateBlogButton" class="bg-blue-600 text-blue px-4 py-2 rounded-r-md hover:gb-blue-700 transition-colors">提交</button></div></div></div></div>

添加section标签

    <div class="flex-grow container mx-auto mt-10 px-4 sm:px-0"><div class="max-w-3xl mx-auto bg-white p-6 rounded-lg shadow-md transition-transform transform hover:scale-105 flex flex-col"><div class="text-center"><h2 class="text-2xl font-semibold mb-4">欢迎来到AI博客生成器</h2><p class="text-gray-700">使用人工智能从YouTube视频中生成高质量的博客文章。只需输入链接到下面的YouTube视频,让人工智能为你创建内容!</p></div><br><div><h2 class="text-xl mb-4 font-semibold">请输入YouTube视频链接</h2><div class="flex space-x-4"><input id="youtubeLink" type="url" placeholder="请输入YouTube链接..." class="flex-grow p-2 border border-blue-400 rounded-l-md "><button id="generateBlogButton" class="bg-blue-600 text-blue px-4 py-2 rounded-r-md hover:gb-blue-700 transition-colors">提交</button></div></div><section class="mt-10 flex-grow"><h2 class="text-xl mb-4 font-semibold">生产博客文章</h2><div id="blogContent" class="mt-2 text-gray-700 space-y-4"></div></section></div></div>

1.9、在div标签后添加footer

    <footer class="text-center p-4 text-blacl mt-6">作者YouTube<a href="https://www.youtube.com/codewithtomi">链接</a></footer>

1.10、完整代码

<!DOCTYPE html>
<html lang="en">
<head><meta charset="UTF-8"><meta name="viewport" content="width=device-width, initial-scale=1.0"><title>AI 博客</title><link href="https://cdn.jsdelivr.net/npm/tailwindcss@2.2.19/dist/tailwind.min.css" rel="stylesheet"><style>@keyframes rotate{from{transform: rotate(0deg);}to{transform: rotate(360deg);}}@-webkit-keyframes rotate{from{-webkit-transform: rotate(0deg);}to{-webkit-transform: rotate(360deg);}}.load{width: 100px;height: 100px;margin: 110px auto 0;border: solid 10px #8822aa;border-radius: 50%;border-right-color: transparent;border-bottom-color: transparent ;-webkit-transform: all 0.5s ease-in;-webkit-animation-name: rotate;-webkit-animation-duration: 1.0s;-webkit-animation-iteration-count: infinite;-webkit-animation-timing-function: linear;transition: all 0.5s ease-in;animation-name: rotate;animation-iteration-count: infinite;animation-timing-function: linear;}</style></head>
<body class="flex flex-col min-h-scrren bg-gray-100 font-sans antialised"><nav class="bg-blue-600 p-4 text-white flex justify-between"><div><h1 class="text-3xl font-bold">AI 博客生成器</h1></div><div><a href="#" class="text-white hover:underline">注销</a></div></nav>    <br><br><div class="flex-grow container mx-auto mt-10 px-4 sm:px-0"><div class="max-w-3xl mx-auto bg-white p-6 rounded-lg shadow-md transition-transform transform hover:scale-105 flex flex-col"><div class="text-center"><h2 class="text-2xl font-semibold mb-4">欢迎来到AI博客生成器</h2><p class="text-gray-700">使用人工智能从YouTube视频中生成高质量的博客文章。只需输入链接到下面的YouTube视频,让人工智能为你创建内容!</p></div><br><div><h2 class="text-xl mb-4 font-semibold">请输入YouTube视频链接</h2><div class="flex space-x-4"><input id="youtubeLink" type="url" placeholder="请输入YouTube链接..." class="flex-grow p-2 border border-blue-400 rounded-l-md "><button id="generateBlogButton" class="bg-blue-600 text-blue px-4 py-2 rounded-r-md hover:gb-blue-700 transition-colors">提交</button></div></div><div style="display: none;" id="loading-circle" class="load"></div><section class="mt-10 flex-grow"><h2 class="text-xl mb-4 font-semibold">生产博客文章</h2><div id="blogContent" class="mt-2 text-gray-700 space-y-4"></div></section></div></div><footer class="text-center p-4 text-blacl mt-6">作者YouTube<a href="https://www.youtube.com/codewithtomi">链接</a></footer><script></script>
</body>
</html>

在这里插入图片描述

2、编写前端代码(登录注册界面)

2.1、创建html框架并添加cdn样式表

<!DOCTYPE html>
<html lang="en">
<head><meta charset="UTF-8"><meta name="viewport" content="width=device-width, initial-scale=1.0"><title>AI博客-登录</title><link href="https://cdn.jsdelivr.net/npm/tailwindcss@2.2.19/dist/tailwind.min.css" rel="stylesheet">
</head>
<body></body>
</html>

2.2、创建密码登录框(完整代码)

<!DOCTYPE html>
<html lang="en">
<head><meta charset="UTF-8"><meta name="viewport" content="width=device-width, initial-scale=1.0"><title>AI博客-登录</title><link href="https://cdn.jsdelivr.net/npm/tailwindcss@2.2.19/dist/tailwind.min.css" rel="stylesheet">
</head>
<body class="bg-gray-100 font-sans antialiased"><nav class="bg-blue-600 p-4 text-white flex justify-between"><div><h1 class="text-3xl font-bold">AI 博客生成器</h1></div><div><a href="#" class="text-white hover:underline">登录</a><a href="#" class="text-white hover:underline">注销</a></div></nav><div class="flex items-center justify-center h-screen"><div class="bg-white p-8 shadow-md rounded-lg max-w-md w-full"><form class="space-y-4"><h2 class="text-xl font-semibold">登录</h2><div><label for="username" class="block mb-1 font-medium">用户名</label><input type="text" id="username" name="username" placeholder="请输入您的用户名" class="w-full p-2 border rounded"></div><div><label for="password" class="block mb-1 font-medium">密码</label><input type="password" id="password" name="password" placeholder="请输入您的密码" class="w-full p-2 border rounded"></div><button type="submit" class="w-full bg-blue-600 text-white p-2 rounded hover:bg-blue-700">登录</button></form></div></div></body>
</html>

在这里插入图片描述

3、编写前端代码(注册页面)

3.1、完整代码

<!DOCTYPE html>
<html lang="en">
<head><meta charset="UTF-8"><meta name="viewport" content="width=device-width, initial-scale=1.0"><title>AI博客-注册</title><link href="https://cdn.jsdelivr.net/npm/tailwindcss@2.2.19/dist/tailwind.min.css" rel="stylesheet">
</head>
<body class="bg-gray-100 font-sans antialiased"><nav class="bg-blue-600 p-4 text-white flex justify-between"><div><h1 class="text-3xl font-bold">AI 博客生成器</h1></div><div><a href="#" class="text-white hover:underline">登录</a><a href="#" class="text-white hover:underline">注册</a></div></nav><br><div class="flex items-center justify-center h-screen"><div class="bg-white p-8 shadow-md rounded-lg max-w-md w-full"><form class="space-y-4"><h2 class="text-xl font-semibold">注册</h2><div><label for="username" class="block mb-1 font-medium">用户名</label><input type="text" id="username" name="username" placeholder="请输入您的用户名" class="w-full p-2 border rounded"></div><div><label for="email" class="block mb-1 font-medium">邮箱地址</label><input type="email" id="email" name="email" placeholder="请输入您的邮箱地址" class="w-full p-2 border rounded"></div><div><label for="password" class="block mb-1 font-medium">密码</label><input type="password" id="password" name="password" placeholder="请输入您的密码" class="w-full p-2 border rounded"></div><div><label for="repeatPassword" class="block mb-1 font-medium">密码确认</label><input type="password" id="repeatPassword" name="repeatPassword" placeholder="请再次输入您的密码" class="w-full p-2 border rounded"></div><button type="submit" class="w-full bg-blue-600 text-white p-2 rounded hover:bg-blue-700">注册</button></form></div></div></body>
</html>

在这里插入图片描述

4、编写前端代码(文章保存记录)

4.1、完整代码

<!DOCTYPE html>
<html lang="en">
<head><meta charset="UTF-8"><meta name="viewport" content="width=device-width, initial-scale=1.0"><title>AI博客-历史记录</title><link href="https://cdn.jsdelivr.net/npm/tailwindcss@2.2.19/dist/tailwind.min.css" rel="stylesheet">
</head>
<body class="bg-gray-100 font-sans antialiased"><nav class="bg-blue-600 p-4 text-white flex justify-between"><div><h1 class="text-3xl font-bold">AI 博客生成器</h1></div><div><a href="#" class="text-white hover:underline">登录</a><a href="#" class="text-white hover:underline">注册</a></div></nav><br><br><div class="container mx-auto mt-10 px-4 sm:px-0"><div class="max-w-3xl mx-auto bg-white p-6 rounded-lg shadow-md"><section><h2 class="text-xl mb-4 font-semibold">AI博客-历史记录</h2><div class="space-y-4"><div class="border border-gray-300 p-4 rounded-lg"><h3 class="text-lg font-semibold">博客文章标题1</h3><p>这是博客文章的内容,非常感谢</p></div><div class="border border-gray-300 p-4 rounded-lg"><h3 class="text-lg font-semibold">博客文章标题1</h3><p>这是博客文章的内容,非常感谢</p></div></div></section></div></div><br><br><br><br><br><br><br><footer class="text-center p-4 text-black mt-6"><a href="https://www.youtube.com/codewithtomi">作者YouTube链接</a></footer>
</body>
</html>

在这里插入图片描述

5、编写前端代码(文章页面)

5.1、完整代码

<!DOCTYPE html>
<html lang="en">
<head><meta charset="UTF-8"><meta name="viewport" content="width=device-width, initial-scale=1.0"><title>博客文章</title><link href="https://cdn.jsdelivr.net/npm/tailwindcss@2.2.19/dist/tailwind.min.css" rel="stylesheet">
</head>
<body class="bg-gray-100 font-sans antialiased"><nav class="bg-blue-600 p-4 text-white flex justify-between"><div><h1 class="text-3xl font-bold">AI 博客生成器</h1></div><div><a href="#" class="text-white hover:underline">登录</a><a href="#" class="text-white hover:underline">注册</a></div></nav><div class="container mx-auto mt-10 px-4 sm:px-0"><div class="max-w-3xl mx-auto bg-white p-6 rounded-lg shadow-md"><section><h2 class="text-xl mb-4 font-semibold">博客文章详情</h2><div class="border border-gray-300 p-4 rounded-lg"><h3 class="text-lg font-semibold">博客文章标题</h3><p class="text-gray-700">博客文章内容</p><hr class="my-4 border-gray-300"><h4 class="text-lg font-semibold">YouTube标题</h4><p class="text-gray-700">YouTube视频标签</p><h4 class="text-lg font-semibold mt-4">YouTube链接</h4><a href="#" class="text-blue-600 hover:underline">https://www.youtube.com</a></div></section></div></div><br><br><br><br><br><br><br><footer class="text-center p-4 text-black mt-6"><a href="https://www.youtube.com/codewithtomi">作者YouTube链接</a></footer></body>
</html>

三、Django代码(后端)

1、添加app功能

ai_blog_app是生成django模版时随着django生成的
在这里插入图片描述

INSTALLED_APPS = ['django.contrib.admin','django.contrib.auth','django.contrib.contenttypes','django.contrib.sessions','django.contrib.messages','django.contrib.staticfiles','blog_generato'
]

然后将ai_blog_app中的urls.py复制到blog_generato中
在这里插入图片描述
在blog_generato下的urls.py中添加url

from  . import views
from django.urls import pathurlpatterns = [path('', views.index,name="index"),
]

2、blog_generato添加index视图(views.py)

首先在ai_blog_app的urls.py文件中添加url路径

from django.contrib import admin
from django.urls import path,includeurlpatterns = [path('admin/', admin.site.urls),path('',include('blog_generato.urls'))
]

创建一个templates文件夹用来存放html前端代码,然后在ai_blog_app的settings.py问价中添加BASE_DIR , ‘templates’

TEMPLATES = [{'BACKEND': 'django.template.backends.django.DjangoTemplates','DIRS': [BASE_DIR , 'templates'],'APP_DIRS': True,'OPTIONS': {'context_processors': ['django.template.context_processors.debug','django.template.context_processors.request','django.contrib.auth.context_processors.auth','django.contrib.messages.context_processors.messages',],},},
]

3、添加数据库

首先连接mysql数据库
在这里插入图片描述

在这里插入图片描述
根据自己使用的数据库来选择

注意:记得pip instal pymysql来安装mysql,然后在ai_blog_app下的_init_.py中添加代码,且已经创建好了django中需要使用的mysql环境

import pymysqlpymysql.install_as_MySQLdb()

然后更改ai_blog_app下settings.py中的mysql配置

DATABASES = {'default': {'ENGINE': 'django.db.backends.mysql','NAME': 'ai_blog_app','USER': 'root','PASSWORD': 'yuan3128..','HOST': 'localhost','PORT': '3306',}

最后进行数据库迁移

PS E:\ai_blog_app> python manage.py makemigrations
PS E:\ai_blog_app> python manage.py migrate

4、创建管理员用户

PS E:\ai_blog_app> python manage.py createsuperuser
Username (leave blank to use 'yuanl'): (用户名)
Email address: (邮箱)
Password: (密码)
Password (again):(再次输入密码)
Superuser created successfully.

然后运行django项目,在浏览器中输入http://127.0.0.1:8000/admin进入后台管理页面
在这里插入图片描述

4.1、后台中文化

在seetings.py文件中将配置项LANGUAGE_CODE的值设置为“zh-Hans” ,TIME_ZONE的值设置为"Asia/Shanghai"

在seetings.py文件中配置项MIDDLEWARE(中间件)中添加本地化中间件
“django.middleware.locale.LocaleMiddleware”

LANGUAGE_CODE = 'zh-Hans'TIME_ZONE = 'UTC'USE_I18N = TrueUSE_TZ = True

4.2、在blog_generato下的urls.py中添加url

urlpatterns = [path('', views.index,name="index"),path('login', views.login, name="login"),path('signup', views.signup, name="signup"),path('logout', views.logout, name="logout"),
]

4.3、将注册登录html页面添加到views中

from django.shortcuts import render# Create your views here.
def index(request):return render(request,'index.html')def user_login(request):return render(request,'login.html')def user_signup(request):return render(request,'signup.html')

修改signup.html中的代码

 <div><a href="login" class="text-white hover:underline">登录</a><a href="signup" class="text-white hover:underline">注册</a></div>

修改login.html中的代码

 <div><a href="login" class="text-white hover:underline">登录</a><a href="signup" class="text-white hover:underline">注册</a></div>

5、获取ai转换

地址:https://www.assemblyai.com/

注意:assemblyai库和websockets版本在10.0到11.0之间(根据自己的版本进行安装)
在这里插入图片描述
修改ai_blog_app中settings.py文件,并创建一个media文件夹

"""
Django settings for ai_blog_app project.Generated by 'django-admin startproject' using Django 5.0.For more information on this file, see
https://docs.djangoproject.com/en/5.0/topics/settings/For the full list of settings and their values, see
https://docs.djangoproject.com/en/5.0/ref/settings/
"""
import os.path
from pathlib import Path
import os# Build paths inside the project like this: BASE_DIR / 'subdir'.
BASE_DIR = Path(__file__).resolve().parent.parent# Quick-start development settings - unsuitable for production
# See https://docs.djangoproject.com/en/5.0/howto/deployment/checklist/# SECURITY WARNING: keep the secret key used in production secret!
SECRET_KEY = 'django-insecure-am#drmftow4qax@!l4v%_jg%pcr5)!@ibi*%@g(%he%!-i88#8'# SECURITY WARNING: don't run with debug turned on in production!
DEBUG = TrueALLOWED_HOSTS = []# Application definitionINSTALLED_APPS = ['django.contrib.admin','django.contrib.auth','django.contrib.contenttypes','django.contrib.sessions','django.contrib.messages','django.contrib.staticfiles','blog_generato',
]MIDDLEWARE = ['django.middleware.security.SecurityMiddleware','django.contrib.sessions.middleware.SessionMiddleware','django.middleware.common.CommonMiddleware','django.middleware.csrf.CsrfViewMiddleware','django.contrib.auth.middleware.AuthenticationMiddleware','django.contrib.messages.middleware.MessageMiddleware','django.middleware.clickjacking.XFrameOptionsMiddleware',
]ROOT_URLCONF = 'ai_blog_app.urls'TEMPLATES = [{'BACKEND': 'django.template.backends.django.DjangoTemplates','DIRS': [BASE_DIR , 'templates'],'APP_DIRS': True,'OPTIONS': {'context_processors': ['django.template.context_processors.debug','django.template.context_processors.request','django.contrib.auth.context_processors.auth','django.contrib.messages.context_processors.messages',],},},
]WSGI_APPLICATION = 'ai_blog_app.wsgi.application'# Database
# https://docs.djangoproject.com/en/5.0/ref/settings/#databases# DATABASES = {
#     'default': {
#         'ENGINE': 'django.db.backends.sqlite3',
#         'NAME': BASE_DIR / 'db.sqlite3',
#     }
# }
DATABASES = {'default': {'ENGINE': 'django.db.backends.mysql','NAME': 'ai_blog_app','USER': 'root','PASSWORD': 'yuan3128..','HOST': '127.0.0.1','PORT': '3306',}
}# Password validation
# https://docs.djangoproject.com/en/5.0/ref/settings/#auth-password-validatorsAUTH_PASSWORD_VALIDATORS = [{'NAME': 'django.contrib.auth.password_validation.UserAttributeSimilarityValidator',},{'NAME': 'django.contrib.auth.password_validation.MinimumLengthValidator',},{'NAME': 'django.contrib.auth.password_validation.CommonPasswordValidator',},{'NAME': 'django.contrib.auth.password_validation.NumericPasswordValidator',},
]# Internationalization
# https://docs.djangoproject.com/en/5.0/topics/i18n/LANGUAGE_CODE = 'zh-Hans'TIME_ZONE = 'UTC'USE_I18N = TrueUSE_TZ = True# Static files (CSS, JavaScript, Images)
# https://docs.djangoproject.com/en/5.0/howto/static-files/STATIC_URL = 'static/'# Default primary key field type
# https://docs.djangoproject.com/en/5.0/ref/settings/#default-auto-fieldDEFAULT_AUTO_FIELD = 'django.db.models.BigAutoField'MEDIA_URL = '/media/'
MEDIA_ROOT = os.path.join(BASE_DIR,'media')LOGIN_URL = 'login'

6、获取openai秘钥

地址:https://platform.openai.com/

因为地区原因无法注册

所以转文字功能无法使用

四、修改后的完整代码(前后端)

在这里插入图片描述

1、 ai_blog_app–> settings.py

import os.path
from pathlib import Path
import os# Build paths inside the project like this: BASE_DIR / 'subdir'.
BASE_DIR = Path(__file__).resolve().parent.parent# Quick-start development settings - unsuitable for production
# See https://docs.djangoproject.com/en/5.0/howto/deployment/checklist/# SECURITY WARNING: keep the secret key used in production secret!
SECRET_KEY = 'django-insecure-am#drmftow4qax@!l4v%_jg%pcr5)!@ibi*%@g(%he%!-i88#8'# SECURITY WARNING: don't run with debug turned on in production!
DEBUG = TrueALLOWED_HOSTS = []# Application definitionINSTALLED_APPS = ['django.contrib.admin','django.contrib.auth','django.contrib.contenttypes','django.contrib.sessions','django.contrib.messages','django.contrib.staticfiles','blog_generato',
]MIDDLEWARE = ['django.middleware.security.SecurityMiddleware','django.contrib.sessions.middleware.SessionMiddleware','django.middleware.common.CommonMiddleware','django.middleware.csrf.CsrfViewMiddleware','django.contrib.auth.middleware.AuthenticationMiddleware','django.contrib.messages.middleware.MessageMiddleware','django.middleware.clickjacking.XFrameOptionsMiddleware',
]ROOT_URLCONF = 'ai_blog_app.urls'TEMPLATES = [{'BACKEND': 'django.template.backends.django.DjangoTemplates','DIRS': [BASE_DIR , 'templates'],'APP_DIRS': True,'OPTIONS': {'context_processors': ['django.template.context_processors.debug','django.template.context_processors.request','django.contrib.auth.context_processors.auth','django.contrib.messages.context_processors.messages',],},},
]WSGI_APPLICATION = 'ai_blog_app.wsgi.application'# Database
# https://docs.djangoproject.com/en/5.0/ref/settings/#databases# DATABASES = {
#     'default': {
#         'ENGINE': 'django.db.backends.sqlite3',
#         'NAME': BASE_DIR / 'db.sqlite3',
#     }
# }
DATABASES = {'default': {'ENGINE': 'django.db.backends.mysql','NAME': 'ai_blog_app','USER': 'root','PASSWORD': 'yuan3128..','HOST': '127.0.0.1','PORT': '3306',}
}# Password validation
# https://docs.djangoproject.com/en/5.0/ref/settings/#auth-password-validatorsAUTH_PASSWORD_VALIDATORS = [{'NAME': 'django.contrib.auth.password_validation.UserAttributeSimilarityValidator',},{'NAME': 'django.contrib.auth.password_validation.MinimumLengthValidator',},{'NAME': 'django.contrib.auth.password_validation.CommonPasswordValidator',},{'NAME': 'django.contrib.auth.password_validation.NumericPasswordValidator',},
]# Internationalization
# https://docs.djangoproject.com/en/5.0/topics/i18n/LANGUAGE_CODE = 'zh-Hans'TIME_ZONE = 'UTC'USE_I18N = TrueUSE_TZ = True# Static files (CSS, JavaScript, Images)
# https://docs.djangoproject.com/en/5.0/howto/static-files/STATIC_URL = 'static/'# Default primary key field type
# https://docs.djangoproject.com/en/5.0/ref/settings/#default-auto-fieldDEFAULT_AUTO_FIELD = 'django.db.models.BigAutoField'MEDIA_URL = '/media/'
MEDIA_ROOT = os.path.join(BASE_DIR,'media')LOGIN_URL = 'login'

2、ai_blog_app–> urls.py

from django.contrib import admin
from django.urls import path,include
from django.conf import settings
from django.conf.urls.static import staticurlpatterns = [path('admin/', admin.site.urls),path('',include('blog_generato.urls'))
]
urlpatterns =urlpatterns+static(settings.MEDIA_URL,document_root=settings.MEDIA_ROOT)

3、ai_blog_app --> init.py

import pymysqlpymysql.install_as_MySQLdb()

4、blog_generato --> admin.py

from django.contrib import admin
from .models import BlogPost# Register your models here.
admin.site.register(BlogPost)

5、blog_generato --> models.py

from django.db import models
from django.contrib.auth.models import User
# Create your models here.
class BlogPost(models.Model):user = models.ForeignKey(User,on_delete=models.CASCADE)youtube_title = models.CharField(max_length=3000)youtube_link = models.URLField()generated_content = models.TextField()created_at = models.DateTimeField(auto_now_add=True)def __str__(self):return  self.youtube_title

blog_generato --> urls.py

from . import views
from django.urls import pathurlpatterns = [path('', views.index, name="index"),path('login', views.user_login, name="login"),path('signup', views.user_signup, name="signup"),path('logout', views.user_logout, name="logout"),path('generate', views.generate_blog, name="generate"),path('blog-list', views.blog_list, name="blog-list"),path('blog-details/<int:pk>/', views.blog_details, name="blog-details"),
]

7、 blog_generato --> viwes.py

import json
import os.path
import os
from django.contrib.auth.models import User
from django.contrib.auth import authenticate,login,logout
from django.shortcuts import render,redirect
from django.contrib.auth.decorators import login_required
from django.views.decorators.csrf import csrf_exempt
from django.http import JsonResponse
from pytube import YouTube
from django.conf import settings
import assemblyai as aai
# (无法注册)import openai
from .models import BlogPost# Create your views here.
@login_required
def index(request):return render(request,'index.html')@csrf_exempt
def generate_blog(request):if request.method == 'POST':try:data = json.loads(request.body)yt_link = data['link']return JsonResponse({'content':yt_link})except(KeyError,json.JSONDecodeError):return JsonResponse({'error':'无效的链接'},status=304)title = yt_title(yt_link)transcription = get_transcription(yt_link)if not transcription:return JsonResponse({'error':'未能获得转录'},status=500)blog_content = generate_blog_from_transcription(transcription)if not blog_content:return JsonResponse({'error': '未能获得转录'}, status=500)new_blog_article = BlogPost.objects.create(user= request.user,youtube_title=title,youtube_link=yt_link,generated_content=blog_content,)new_blog_article.save()return JsonResponse({'content':blog_content})else:return JsonResponse({'error':'无效的请求'},status=404)def yt_title(link):yt = YouTube(link)title = yt.titlereturn titledef download_audio(link):yt = YouTube(link)video = yt.streams.filter(only_audio=True).first()out_file = video.download(output_path=settings.MEDIA_ROOT)base,ext = os.path.splitext(out_file)new_file = base + '.mp3'os.rename(out_file,new_file)return new_filedef get_transcription(link):audio_file = download_audio(link)aai.settings.api_key = '5184545617204a3f80ef1fffc0a1056c'transcriber = aai.Transcribertranscriber = transcriber.transcriber(audio_file)return transcriber.textdef generate_blog_from_transcription(transcription):openai.api_key =" "prompt = f"Base on the following transcript from a YouTuBe vido,write a comprehensive blog article,write it based on the transcript,but dont make it look like a youtube video,make it look like a proper blog article:\n\n{transcription}\n\nArticle:"response = openai.Completion.create(model = "text-davinci-003",prompt = prompt,max_tokens = 1000)generated_content = response.choices[0].text.strip()return generated_contentdef blog_list(request):blog_articles = BlogPost.objects.filter(user=request.user)return render(request,"all-logs.html",{'blog_articles':blog_articles})def blog_details(request,pk):blog_article_detail = BlogPost.objects.get(id=pk)if request.user == blog_article_detail.user:return  render(request,'blog-details.html',{'blog_article_detail':blog_article_detail})else:return redirect('/')def user_login(request):if request.method == 'POST':username = request.POST['username']password = request.POST['password']user = authenticate(request,username=username,password=password)if user is not None:login(request,user)return redirect('/')else:error_message='没有该用户或密码错误'return render(request,'login.html',{'error_message':error_message})return render(request,'login.html')def user_signup(request):if request.method == 'POST':username = request.POST['username']email = request.POST['email']password = request.POST['password']repeatPassword = request.POST['repeatPassword']if password == repeatPassword:try:user = User.objects.create_user(username,email,password)user.save()login(request,user)return redirect('/')except:error_message='创建账号失败'return render(request, 'signup.html', {'errot_message': error_message})else:error_message = '密码输入错误'return  render(request,'signup.html', {'errot_message':error_message})return render(request,'signup.html')def user_logout(request):logout(request)return redirect('/')

8、templates --> all-logs.html(修改后)

<!DOCTYPE html>
<html lang="en">
<head><meta charset="UTF-8"><meta name="viewport" content="width=device-width, initial-scale=1.0"><title>AI博客-历史记录</title><link href="https://cdn.jsdelivr.net/npm/tailwindcss@2.2.19/dist/tailwind.min.css" rel="stylesheet">
</head>
<body class="bg-gray-100 font-sans antialiased"><nav class="bg-blue-600 p-4 text-white flex justify-between"><div><h1 class="text-3xl font-bold">AI 博客生成器</h1></div><div><a href="#" class="text-white hover:underline mx-4">欢迎{{ user.username }}</a><a herf="/blog-list" class="text-white hover:underline mx-4">保存文章</a><a href="#" class="text-white hover:underline">注销</a></div></nav><br><br><div class="container mx-auto mt-10 px-4 sm:px-0"><div class="max-w-3xl mx-auto bg-white p-6 rounded-lg shadow-md"><section><h2 class="text-xl mb-4 font-semibold">AI博客-历史记录</h2><div class="space-y-4">{% for article in blog_articles reversed %}<a href="blog-details/{{ article.id }}"><div class="border border-gray-300 p-4 rounded-lg"><h3 class="text-lg font-semibold">{{ article.youtube_title }}</h3><p>{{ article.generated_content | truncatechars:200 }}</p></div></a>{% endfor %}</div></section></div></div><br><br><br><br><br><br><br><footer class="text-center p-4 text-black mt-6"><a href="https://www.youtube.com/codewithtomi">作者YouTube链接</a></footer>
</body>
</html>

9、templates -->blog-details.html(修改后)

<!DOCTYPE html>
<html lang="en">
<head><meta charset="UTF-8"><meta name="viewport" content="width=device-width, initial-scale=1.0"><title>博客文章</title><link href="https://cdn.jsdelivr.net/npm/tailwindcss@2.2.19/dist/tailwind.min.css" rel="stylesheet">
</head>
<body class="bg-gray-100 font-sans antialiased"><nav class="bg-blue-600 p-4 text-white flex justify-between"><div><h1 class="text-3xl font-bold">AI 博客生成器</h1></div><div><a href="#" class="text-white hover:underline mx-4">欢迎{{ user.username }}</a><a herf="/blog-list" class="text-white hover:underline mx-4">保存文章</a><a href="#" class="text-white hover:underline">注销</a></div></nav><div class="container mx-auto mt-10 px-4 sm:px-0"><div class="max-w-3xl mx-auto bg-white p-6 rounded-lg shadow-md"><section><h2 class="text-xl mb-4 font-semibold">博客文章详情</h2><div class="border border-gray-300 p-4 rounded-lg"><h3 class="text-lg font-semibold">{{ blog_article_detail.youtube_title }}</h3><p class="text-gray-700">{{ blog_article_detail.generated_content }}</p><hr class="my-4 border-gray-300"><h4 class="text-lg font-semibold">YouTube标题</h4><p class="text-gray-700">{{ blog_article_detail.youtube_title }}</p><h4 class="text-lg font-semibold mt-4">YouTube链接</h4><a href="{{ blog_article_detail.youtube_link }}" class="text-blue-600 hover:underline">{{ blog_article_detail.youtube_link }}</a></div></section></div></div><br><br><br><br><br><br><br><footer class="text-center p-4 text-black mt-6"><a href="https://www.youtube.com/codewithtomi">作者YouTube链接</a></footer></body>
</html>

10、templates -->index.html(修改后)

<!DOCTYPE html>
<html lang="en"><head><meta charset="UTF-8"><meta name="viewport" content="width=device-width, initial-scale=1.0"><title>AI 博客</title><link href="https://cdn.jsdelivr.net/npm/tailwindcss@2.2.19/dist/tailwind.min.css" rel="stylesheet"><style>@keyframes rotate {from {transform: rotate(0deg);}to {transform: rotate(360deg);}}@-webkit-keyframes rotate {from {-webkit-transform: rotate(0deg);}to {-webkit-transform: rotate(360deg);}}.load {width: 100px;height: 100px;margin: 110px auto 0;border: solid 10px #8822aa;border-radius: 50%;border-right-color: transparent;border-bottom-color: transparent;-webkit-transform: all 0.5s ease-in;-webkit-animation-name: rotate;-webkit-animation-duration: 1.0s;-webkit-animation-iteration-count: infinite;-webkit-animation-timing-function: linear;transition: all 0.5s ease-in;animation-name: rotate;animation-iteration-count: infinite;animation-timing-function: linear;}</style></head><body class="flex flex-col min-h-screen bg-gray-100 font-sans antialised"><nav class="bg-blue-600 p-4 text-white flex justify-between"><div><h1 class="text-3xl font-bold">AI 博客生成器</h1></div>
<div><a href="#" class="text-white hover:underline mx-4">欢迎{{ user.username }}</a><a herf="/blog-list" class="text-white hover:underline mx-4">保存文章</a><a href="#" class="text-white hover:underline">注销</a></div></nav><br><br><div class="flex-grow container mx-auto mt-10 px-4 sm:px-0"><divclass="max-w-3xl mx-auto bg-white p-6 rounded-lg shadow-md transition-transform transform hover:scale-105 flex flex-col"><div class="text-center"><h2 class="text-2xl font-semibold mb-4">欢迎来到AI博客生成器</h2><p class="text-gray-700">使用人工智能从YouTube视频中生成高质量的博客文章。只需输入链接到下面的YouTube视频,让人工智能为你创建内容!</p></div><br><div><h2 class="text-xl mb-4 font-semibold">请输入YouTube视频链接</h2><div class="flex space-x-4"><input id="youtubeLink" type="url" placeholder="请输入YouTube链接..."class="flex-grow p-2 border border-blue-400 rounded-l-md "><button id="generateBlogButton"class="bg-blue-600 text-blue px-4 py-2 rounded-r-md hover:bg-blue-700 transition-colors">提交</button></div></div><div style="display: none;" id="loading-circle" class="load"></div><section class="mt-10 flex-grow"><h2 class="text-xl mb-4 font-semibold">生产博客文章</h2><div id="blogContent" class="mt-2 text-gray-700 space-y-4"></div></section></div></div><footer class="text-center p-4 text-black mt-6"><a href="https://www.youtube.com/codewithtomi">作者YouTube链接</a></footer><script>document.getElementById('generateBlogButton').addEventListener('click',async () => {const youtubeLink = document.getElementById('youtubeLink').value;const blogContent = document.getElementById('blogContent');if(youtubeLink){document.getElementById('loading-circle').style.display = 'block';loadingIndicator.classList.remove('hidden');blogContent.innerHTML = '';const endpointUrl = '/generate';try {const response = await fetch(endpointUrl,{method:'POST',headers:{'Content-Type':'application/json',},body:JSON.stringify({link:youtubeLink})});const data = await response.json();blogContent.innerHTML = data.youtubeLink;} catch (error) {console.error("Error occurred:",error);alert("Something went wrong. Please try again later.");}document.getElementById('loading-circle').style.display = 'none';} else {alert("Please enter a YouTube link.");}});</script>
</body></html>

11、templates -->login.html(修改后)

<!DOCTYPE html>
<html lang="en">
<head><meta charset="UTF-8"><meta name="viewport" content="width=device-width, initial-scale=1.0"><title>AI博客-登录</title><link href="https://cdn.jsdelivr.net/npm/tailwindcss@2.2.19/dist/tailwind.min.css" rel="stylesheet">
</head>
<body class="bg-gray-100 font-sans antialiased"><nav class="bg-blue-600 p-4 text-white flex justify-between"><div><h1 class="text-3xl font-bold">AI 博客生成器</h1></div><div><a href="login" class="text-white hover:underline">登录</a><a href="signup" class="text-white hover:underline">注册</a></div></nav><div class="flex items-center justify-center h-screen"><div class="bg-white p-8 shadow-md rounded-lg max-w-md w-full"><form class="space-y-4" action="" method="POST">{% csrf_token %}{% if error_message %}<div align="center" style="color: red;"><h2>{{ 登录失败 }}登录失败或密码错误</h2></div>{% endif %}<h2 class="text-xl font-semibold">登录</h2><div><label for="username" class="block mb-1 font-medium">用户名</label><input type="text" id="username" name="username" placeholder="请输入您的用户名" class="w-full p-2 border rounded"></div><div><label for="password" class="block mb-1 font-medium">密码</label><input type="password" id="password" name="password" placeholder="请输入您的密码" class="w-full p-2 border rounded"></div><button type="submit" class="w-full bg-blue-600 text-white p-2 rounded hover:bg-blue-700">登录</button></form></div></div></body>
</html>

12、templates -->signup.html(修改后)

<!DOCTYPE html>
<html lang="en">
<head><meta charset="UTF-8"><meta name="viewport" content="width=device-width, initial-scale=1.0"><title>AI博客-注册</title><link href="https://cdn.jsdelivr.net/npm/tailwindcss@2.2.19/dist/tailwind.min.css" rel="stylesheet">
</head>
<body class="bg-gray-100 font-sans antialiased"><nav class="bg-blue-600 p-4 text-white flex justify-between"><div><h1 class="text-3xl font-bold">AI 博客生成器</h1></div><div><a href="login" class="text-white hover:underline">登录</a><a href="signup" class="text-white hover:underline">注册</a></div></nav><br><div class="flex items-center justify-center h-screen"><div class="bg-white p-8 shadow-md rounded-lg max-w-md w-full"><form class="space-y-4" action="" method="POST">{% csrf_token %}{% if error_message %}<div align="center" style="color: red;"><h2>{{ 注册失败 }}注册失败</h2></div>{% endif %}<h2 class="text-xl font-semibold">注册</h2><div><label for="username" class="block mb-1 font-medium">用户名</label><input type="text" id="username" name="username" placeholder="请输入您的用户名" class="w-full p-2 border rounded"></div><div><label for="email" class="block mb-1 font-medium">邮箱地址</label><input type="email" id="email" name="email" placeholder="请输入您的邮箱地址" class="w-full p-2 border rounded"></div><div><label for="password" class="block mb-1 font-medium">密码</label><input type="password" id="password" name="password" placeholder="请输入您的密码" class="w-full p-2 border rounded"></div><div><label for="repeatPassword" class="block mb-1 font-medium">密码确认</label><input type="password" id="repeatPassword" name="repeatPassword" placeholder="请再次输入您的密码" class="w-full p-2 border rounded"></div><button type="submit" class="w-full bg-blue-600 text-white p-2 rounded hover:bg-blue-700">注册</button></form></div></div></body>
</html>

本篇文章是从YouTube上学的,地址:www.youtube.com/@CodeWithTomi

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.rhkb.cn/news/318704.html

如若内容造成侵权/违法违规/事实不符,请联系长河编程网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!

相关文章

OpenCV(三)—— 车牌筛选

本篇文章要介绍如何对从候选车牌中选出最终进行字符识别的车牌。 无论是通过 Sobel 还是 HSV 计算出的候选车牌都可能不止一个&#xff0c;需要对它们进行评分&#xff0c;选出最终要进行识别的车牌。这个过程中会用到两个理论知识&#xff1a;支持向量机和 HOG 特征。 1、支…

华为机考入门python3--(19)牛客19- 简单错误记录

分类&#xff1a;字符串 知识点&#xff1a; 分割字符串 my_str.split(\\) 字符串只保留最后16位字符 my_str[-16:] 列表可以作为队列、栈 添加元素到第一个位置 my_list.insert(0, elem) 增加元素到最后一个位置 my_list.append(elem) 删除第一个 my_list.pop(0)…

C/C++开发环境配置

配置C/C开发环境 1.下载和配置MinGW-w64 编译器套件 下载地址&#xff1a;https://sourceforge.net/projects/mingw-w64/files/mingw-w64/mingw-w64-release/ 下载后解压并放至你容易管理的路径下&#xff08;我是将其放在了D盘的一个software的文件中管理&#xff09; 2.…

奈氏准则和香农定理

一、奈奎斯特和香农 哈里奈奎斯特&#xff08;Harry Nyquist&#xff09;(左) 克劳德艾尔伍德香农&#xff08;Claude Elwood Shannon&#xff09;(右) 我们应该在心里记住他们&#xff0c;记住所有为人类伟大事业做出贡献的人&#xff0c;因为他们我们的生活变得越来越精彩&…

【UnityRPG游戏制作】NPC交互逻辑、动玩法

&#x1f468;‍&#x1f4bb;个人主页&#xff1a;元宇宙-秩沅 &#x1f468;‍&#x1f4bb; hallo 欢迎 点赞&#x1f44d; 收藏⭐ 留言&#x1f4dd; 加关注✅! &#x1f468;‍&#x1f4bb; 本文由 秩沅 原创 &#x1f468;‍&#x1f4bb; 收录于专栏&#xff1a;就业…

多级留言/评论的功能实现——SpringBoot3后端篇

目录 功能描述数据库表设计后端接口设计实体类entity 完整实体类dto 封装请求数据dto 封装分页请求数据vo 请求返回数据 Controller控制层Service层接口实现类 Mapper层Mybatis 操作数据库 补充&#xff1a;返回的数据结构自动创建实体类 最近毕设做完了&#xff0c;开始来梳理…

✔ ★Java大项目——用Java模拟RabbitMQ实现一个消息队列(二)【创建核心类、封装数据库操作】

✔ ★Java大项目——用Java模拟RabbitMQ实现一个消息队列 四. 项⽬创建五. 创建核⼼类 ★创建 Exchange&#xff08;名字、类型、持久化、自动删除、参数&#xff09;创建 MSGQueue&#xff08;名字、持久化、独占标识&#xff09;创建 Binding&#xff08;交换机名字、队列名字…

UDP编程流程(UDP客户端、服务器互发消息流程)

一、UDP编程流程 1.1、 UDP概述 UDP&#xff0c;即用户数据报协议&#xff0c;是一种面向无连接的传输层协议。相比于TCP协议&#xff0c;UDP具有以下特点&#xff1a; 速度较快&#xff1a;由于UDP不需要建立连接和进行复杂的握手过程&#xff0c;因此在传输数据时速度稍快…

Arcpy批量克里金插值报错

Arcpy批量克里金插值报错 文章目录 Arcpy批量克里金插值报错问题解决参考 问题 在进行实验的时候&#xff0c;Arcpy中批量进行克里金插值报错&#xff0c;主要就是在运行这个工具的时候&#xff0c;一直报错&#xff0c;改了很多参数也不行 ERROR 010079: 无法估算半变异函数…

MySQL商城数据库88张表结构(46—50)

46、消息队列表 CREATE TABLE dingchengyu消息队列表 (id int(11) NOT NULL AUTO_INCREMENT COMMENT 序号,userId int(11) DEFAULT NULL COMMENT 用户id,msgTtype tinyint(4) DEFAULT 0 COMMENT 消息类型,createTime datetime DEFAULT NULL COMMENT 创建时间,sendTime datetim…

LabVIEW自动剪板机控制系统

LabVIEW自动剪板机控制系统 随着工业自动化的快速发展&#xff0c;钣金加工行业面临着生产效率和加工精度的双重挑战。传统的手动或脚踏式剪板机已无法满足现代生产的高效率和高精度要求&#xff0c;因此&#xff0c;自动剪板机控制系统的研究与开发成为了行业发展的必然趋势。…

【深度学习】序列模型

深度学习&#xff08;Deep Learning&#xff09;是机器学习的一个分支领域&#xff1a;它是从数据中学习表示的一种新方法&#xff0c;强调从连续的层中进行学习&#xff0c;这些层对应于越来越有意义的表示。 1. 为什么选择序列模型&#xff1f; 循环神经网络&#xff08;RNN…

[嵌入式系统-63]:RT-Thread-内核:内核在不同CPU架构上的移植和不同硬件板BSP上的移植

目录 内核移植 1. CPU 架构移植&#xff1a;由CPU厂家提供 1.1 实现全局中断开关&#xff1a;汇编语言实现 &#xff08;1&#xff09;关闭全局中断 &#xff08;2&#xff09;打开全局中断 1.2 实现线程栈初始化 1.3 实现上下文切换 &#xff08;1&#xff09;实现 rt…

零代码编程:用Kimichat从PDF文件中批量提取图片

一个PDF文件中&#xff0c;有很多图片&#xff0c;想批量提取出来&#xff0c;可以借助kimi智能助手。 在借助kimi智能助手中输入提示词&#xff1a; 你是一个Python编程专家&#xff0c;要完成一个网页爬取Python脚本的任务&#xff0c;具体步骤如下&#xff1a; 打开文件夹…

基于深度学习检测恶意流量识别框架(80+特征/99%识别率)

基于深度学习检测恶意流量识别框架 目录 基于深度学习检测恶意流量识别框架简要示例a.检测攻击类别b.模型训练结果输出参数c.前端检测页面d.前端训练界面e.前端审计界面&#xff08;后续更新了&#xff09;f.前端自学习界面&#xff08;自学习模式转换&#xff09;f1.自学习模式…

数据结构与算法之经典排序算法

一、简单排序 在我们的程序中&#xff0c;排序是非常常见的一种需求&#xff0c;提供一些数据元素&#xff0c;把这些数据元素按照一定的规则进行排序。比如查询一些订单按照订单的日期进行排序&#xff0c;再比如查询一些商品&#xff0c;按照商品的价格进行排序等等。所以&a…

021、Python+fastapi,第一个Python项目走向第21步:ubuntu 24.04 docker 安装mysql8、redis(二)

系列文章目录 pythonvue3fastapiai 学习_浪淘沙jkp的博客-CSDN博客https://blog.csdn.net/jiangkp/category_12623996.html 前言 安装redis 我会以三种方式安装&#xff0c; 第一、直接最简单安装&#xff0c;适用于测试环境玩玩 第二、conf配置安装 第三、集群环境安装 一…

电脑崩溃了,之前备份的GHO文件怎么恢复到新硬盘?

前言 之前咱们说到用WinPE系统给电脑做一个GHO镜像备份&#xff0c;这个备份可以用于硬盘完全崩溃换盘的情况下使用。 那么这个GHO镜像文件怎么用呢&#xff1f; 咱们今天详细来讲讲&#xff01; 如果你的电脑系统硬盘崩溃了或者是坏掉了&#xff0c;那么就需要使用之前备份…

ElementUI从unpkg.com完整下载到本地的方法 - 解决unpkg.com不稳定的问题 - 自建镜像站 - 不想打包只想cdn一下

方法 方法1&#xff09;随便弄个文件夹&#xff0c;根据官网npm方法下载包&#xff0c;提取即可 npm i element-ui -S cd /node_modules/element-ui/ ls src 安装npm方法&#xff1a;https://nodejs.org/en 方法2&#xff09;不推荐 - 在github中搜索对应的库zip包&#xff0…

C++仿函数周边及包装器

我最近开了几个专栏&#xff0c;诚信互三&#xff01; > |||《算法专栏》&#xff1a;&#xff1a;刷题教程来自网站《代码随想录》。||| > |||《C专栏》&#xff1a;&#xff1a;记录我学习C的经历&#xff0c;看完你一定会有收获。||| > |||《Linux专栏》&#xff1…