python+html+gemini api实现一个全自动ai视频面试评测系统代码
代码语言:python
所属分类:其他
代码描述:python+html+gemini api实现一个全自动ai视频面试评测系统代码,输入职位,将链接分享给面试者,面试者打开网页后ai自动出题并录制面试者回答的视频,最后ai根据多个题目的回答视频表现给出评分,全程自动化操作。
代码标签: python html gemini api 全自动 ai 视频 面试 评测 系统 代码
下面为部分代码预览,完整代码请点击下载或在bfwstudio webide中打开
import os
import sqlite3
import json
import time
import uuid
import threading
from flask import Flask, request, render_template_string, session, redirect, url_for, jsonify, send_from_directory
from gtts import gTTS
import google.generativeai as genai
from werkzeug.utils import secure_filename
# =================配置区域=================
API_KEY = "AIza**************************************" # 替换为你的 Google Gemini API Key
UPLOAD_FOLDER = 'static/uploads'
DB_NAME = 'interview_system.db'
SECRET_KEY = 'super_secret_key_for_demo'
# 配置 Gemini
genai.configure(api_key=API_KEY)
model_text = genai.GenerativeModel('gemini-2.0-flash')
model_multimodal = genai.GenerativeModel('gemini-2.0-flash')
app = Flask(__name__)
app.secret_key = SECRET_KEY
app.config['UPLOAD_FOLDER'] = UPLOAD_FOLDER
# 确保上传目录存在
os.makedirs(UPLOAD_FOLDER, exist_ok=True)
# =================数据库初始化=================
def init_db():
conn = sqlite3.connect(DB_NAME)
c = conn.cursor()
# 管理员表 (默认 admin/admin)
c.execute('''CREATE TABLE IF NOT EXISTS admins (username TEXT, password TEXT)''')
# 岗位表
c.execute('''CREATE TABLE IF NOT EXISTS jobs
(id INTEGER PRIMARY KEY AUTOINCREMENT, title TEXT, requirements TEXT, question_count INTEGER)''')
# 面试记录表
c.execute('''CREATE TABLE IF NOT EXISTS candidates
(id INTEGER PRIMARY KEY AUTOINCREMENT, job_id INTEGER, name TEXT,
status TEXT DEFAULT 'pending', ai_feedback TEXT, final_score INTEGER,
timestamp DATETIME DEFAULT CURRENT_TIMESTAMP)''')
# 答题详情表
c.execute('''CREATE TABLE IF NOT EXISTS answers
(id INTEGER PRIMARY KEY AUTOINCREMENT, candidate_id INTEGER,
question_text TEXT, video_path TEXT, analysis TEXT)''')
# 插入默认管理员
c.execute("SELECT * FROM admins WHERE username='admin'")
if not c.fetchone():
c.execute("INSERT INTO admins VALUES ('admin', 'admin')")
conn.commit()
conn.close()
init_db()
# =================HTML 模板=================
# 1. 登录页面
LOGIN_HTML = """
<!DOCTYPE html>
<html>
<head><title>AI面试系统 - 登录</title>
<style>
body { font-family: sans-serif; display: flex; justify-content: center; align-items: center; height: 100vh; background: #f0f2f5; }
.card { background: white; padding: 2rem; border-radius: 8px; box-shadow: 0 2px 10px rgba(0,0,0,0.1); }
input { display: block; margin: 10px 0; padding: 8px; width: 100%; box-sizing: border-box; }
button { width: 100%; padding: 10px; background: #007bff; color: white; border: none; border-radius: 4px; cursor: pointer; }
button:hover { background: #0056b3; }
</style>
</head>
<body>
<div class="card">
<h2>管理员登录</h2>
<form method="post">
<input type="text" name="username" placeholder="用户名 (admin)" required>
<input type="password" name="password" placeholder="密码 (admin)" required>
<button type="submit">登录</button>
</form>
{% if error %}<p style="color:red">{{ error }}</p>{% endif %}
</div>
</body>
</html>
"""
# 2. 管理后台
DASHBOARD_HTML = """
<!DOCTYPE html>
<html>
<head>
<title>AI面试系统 - 后台</title>
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.1.3/dist/css/bootstrap.min.css" rel="stylesheet">
</head>
<body class="p-4">
<div class="d-flex justify-content-between align-items-center mb-4">
<h1>AI面试管理后台</h1>
<a href="/logout" class="btn btn-outline-danger">退出登录</a>
</div>
<div class="row">
<!-- 左侧:新建面试 -->
<div class="col-md-4">
<div class="card">
<div class="card-header">新建面试岗位</div>
<div class="card-body">
<form action="/create_job" method="post">
<div class="mb-3">
<label>岗位名称</label>
<input type="text" name="title" class="form-control" required placeholder="例如:Python工程师">
</div>
<div class="mb-3">
.........完整代码请登录后点击上方下载按钮下载查看















网友评论0