python+html+openai api实现一个全自动ai视频面试评测系统代码

代码语言:python

所属分类:其他

代码描述:python+html+openai api实现一个全自动ai视频面试评测系统代码,输入职位,将链接分享给面试者,面试者打开网页后ai自动出题并录制面试者回答的视频,最后ai根据多个题目的回答视频表现给出评分,全程自动化操作。

代码标签: python html openai 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
from openai import OpenAI

# ================= 配置区域 =================
API_KEY = "YOUR_OPENAI_API_KEY"  # 替换为你的 OpenAI API Key
UPLOAD_FOLDER = 'static/uploads'
DB_NAME = 'interview_system_openai.db'
SECRET_KEY = 'openai_secret_key_demo'

# 初始化 OpenAI 客户端
client = OpenAI(api_key=API_KEY)

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()
    # 管理员表
    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)''')
    # 答题详情表 (增加 transcript 字段用于存储识别出的文字)
    c.execute('''CREATE TABLE IF NOT EXISTS answers 
                 (id INTEGER PRIMARY KEY AUTOINCREMENT, candidate_id INTEGER, 
                  question_text TEXT, video_path TEXT, transcript 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 模板 (保持前端逻辑一致) =================

LOGIN_HTML = """
<!DOCTYPE html>
<html>
<head><title>OpenAI 面试系统 - 登录</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); width: 300px; }
input { display: block; margin: 10px 0; padding: 8px; width: 100%; box-sizing: border-box; }
button { width: 100%; padding: 10px; background: #10a37f; color: white; border: none; border-radius: 4px; cursor: pointer; }
button:hover { background: #0d8a6b; }
</style>
</head>
<body>
<div class="card">
    <h2 style="text-align:center">管理员登录</h2>
    <form method="post">
        <input type="text" name="username" placeholder="用户名 (admin)" required.........完整代码请登录后点击上方下载按钮下载查看

网友评论0