AnlaAnla 1 місяць тому
батько
коміт
9636273c86

+ 229 - 0
Test/view_results.html

@@ -0,0 +1,229 @@
+<!DOCTYPE html>
+<html lang="zh-CN">
+<head>
+    <meta charset="UTF-8">
+    <meta name="viewport" content="width=device-width, initial-scale=1.0">
+    <title>拆卡视频高光时刻展示</title>
+    <style>
+        body {
+            font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
+            background-color: #f4f4f9;
+            margin: 0;
+            padding: 20px;
+            color: #333;
+        }
+
+        .container {
+            max-width: 900px;
+            margin: 0 auto;
+        }
+
+        h1 {
+            text-align: center;
+            color: #4a5568;
+        }
+
+        /* 输入区域样式 */
+        .input-section {
+            background: white;
+            padding: 20px;
+            border-radius: 12px;
+            box-shadow: 0 4px 6px rgba(0,0,0,0.1);
+            margin-bottom: 30px;
+        }
+
+        textarea {
+            width: 100%;
+            height: 150px;
+            border: 1px solid #ddd;
+            border-radius: 8px;
+            padding: 10px;
+            font-family: monospace;
+            box-sizing: border-box; /* 确保padding不撑大宽度 */
+        }
+
+        button {
+            background-color: #4299e1;
+            color: white;
+            border: none;
+            padding: 10px 20px;
+            border-radius: 6px;
+            cursor: pointer;
+            font-size: 16px;
+            margin-top: 10px;
+            transition: background 0.3s;
+        }
+
+        button:hover {
+            background-color: #3182ce;
+        }
+
+        /* 列表展示样式 */
+        .card-list {
+            display: flex;
+            flex-direction: column;
+            gap: 20px;
+        }
+
+        .card-item {
+            display: flex;
+            background: white;
+            border-radius: 12px;
+            overflow: hidden;
+            box-shadow: 0 4px 6px rgba(0,0,0,0.05);
+            transition: transform 0.2s;
+        }
+
+        .card-item:hover {
+            transform: translateY(-2px);
+            box-shadow: 0 8px 12px rgba(0,0,0,0.1);
+        }
+
+        .card-image {
+            width: 300px;
+            background-color: #eee;
+            flex-shrink: 0;
+        }
+
+        .card-image img {
+            width: 100%;
+            height: 100%;
+            object-fit: cover;
+            display: block;
+        }
+
+        .card-content {
+            padding: 20px;
+            flex-grow: 1;
+            display: flex;
+            flex-direction: column;
+            justify-content: center;
+        }
+
+        .timestamp {
+            background-color: #edf2f7;
+            color: #718096;
+            padding: 4px 8px;
+            border-radius: 4px;
+            font-size: 0.85em;
+            display: inline-block;
+            margin-bottom: 10px;
+            width: fit-content;
+        }
+
+        .card-title {
+            font-size: 1.4em;
+            font-weight: bold;
+            margin: 0 0 5px 0;
+            color: #2d3748;
+        }
+
+        .card-subtitle {
+            color: #718096;
+            font-size: 1em;
+            margin-bottom: 15px;
+        }
+
+        .info-row {
+            display: flex;
+            justify-content: space-between;
+            margin-top: auto;
+            border-top: 1px solid #edf2f7;
+            padding-top: 10px;
+        }
+
+        .rarity {
+            font-weight: bold;
+            color: #e53e3e;
+        }
+
+        .series {
+            color: #4a5568;
+        }
+
+        /* 移动端适配 */
+        @media (max-width: 600px) {
+            .card-item {
+                flex-direction: column;
+            }
+            .card-image {
+                width: 100%;
+                height: 200px;
+            }
+        }
+    </style>
+</head>
+<body>
+
+<div class="container">
+    <h1>🃏 拆卡结果展示</h1>
+
+    <!-- 输入区域 -->
+    <div class="input-section">
+        <h3>粘贴 JSON 数据:</h3>
+        <textarea id="jsonInput" placeholder='[
+  {
+    "time": "00:16:32",
+    "card_name_cn": "船长皮卡丘",
+    ...
+  }
+]'></textarea>
+        <button onclick="renderCards()">生成列表</button>
+    </div>
+
+    <!-- 结果区域 -->
+    <div id="resultList" class="card-list">
+        <!-- 卡片会在这里生成 -->
+    </div>
+</div>
+
+<script>
+    function renderCards() {
+        const input = document.getElementById('jsonInput').value;
+        const container = document.getElementById('resultList');
+
+        // 清空现有列表
+        container.innerHTML = '';
+
+        try {
+            const data = JSON.parse(input);
+
+            if (!Array.isArray(data)) {
+                alert('❌ 输入的不是 JSON 数组格式');
+                return;
+            }
+
+            data.forEach(item => {
+                // 创建卡片 HTML
+                const cardHtml = `
+                    <div class="card-item">
+                        <div class="card-image">
+                            ${item.frame_image_path
+                                ? `<img src="${item.frame_image_path}" alt="${item.card_name_cn}" onerror="this.src='https://via.placeholder.com/300x200?text=Image+Not+Found'">`
+                                : '<div style="height:100%; display:flex; align-items:center; justify-content:center; color:#999;">无图片</div>'}
+                        </div>
+                        <div class="card-content">
+                            <div class="timestamp">⏰ ${item.time}</div>
+                            <h2 class="card-title">${item.card_name_cn || '未知中文名'}</h2>
+                            <div class="card-subtitle">${item.card_name_en || ''}</div>
+
+                            <div class="info-row">
+                                <span class="series">📦 系列: ${item.series || '未知'}</span>
+                                <span class="rarity">${item.rarity_desc || '未知稀有度'}</span>
+                            </div>
+                        </div>
+                    </div>
+                `;
+
+                // 插入 DOM
+                container.insertAdjacentHTML('beforeend', cardHtml);
+            });
+
+        } catch (e) {
+            alert('❌ JSON 解析失败,请检查格式是否正确。\n错误信息: ' + e.message);
+        }
+    }
+</script>
+
+</body>
+</html>

+ 2 - 2
app/api/routes.py

@@ -1,5 +1,5 @@
 from fastapi import APIRouter, HTTPException, UploadFile, File
-from app.schemas.models import VideoFrameRequest, CardInfoOutput
+from app.schemas.models import VideoFrameRequest, CardInfoOutput, CardInfoInput
 from app.services.llm_service import LLMService
 from app.services.video_service import VideoService
 from typing import List
@@ -14,7 +14,7 @@ video_service = VideoService()
 
 
 # --- 接口 1: 文本总结 (改为文件上传) ---
-@router.post("/summarize", response_model=List[CardInfoOutput])
+@router.post("/summarize", response_model=List[CardInfoInput])
 async def summarize_text(file: UploadFile = File(...)):
     """
     上传 txt 文件,返回提取的卡片信息 JSON 列表

+ 2 - 0
app/core/config.py

@@ -2,6 +2,8 @@ import os
 
 
 class Settings:
+    BASE_URL: str = "http://192.168.31.183:7721"
+
     # 你的 API 配置
     API_URL: str = "http://100.64.0.8/v1/workflows/run"
     API_KEY: str = "Bearer app-qR46FHcfLyKz2kb0tiiRfV50"

+ 3 - 1
app/services/video_service.py

@@ -53,7 +53,9 @@ class VideoService:
 
                 try:
                     cv2.imwrite(save_path, frame)
-                    card_output.frame_image_path = save_path
+
+                    image_url = f"{settings.BASE_URL}/static/frames/{filename}"
+                    card_output.frame_image_path = image_url
                     success_count += 1
                     logger.info(f"   ✅ 保存成功: {filename}")
                 except Exception as e:

+ 229 - 0
static/view_results.html

@@ -0,0 +1,229 @@
+<!DOCTYPE html>
+<html lang="zh-CN">
+<head>
+    <meta charset="UTF-8">
+    <meta name="viewport" content="width=device-width, initial-scale=1.0">
+    <title>拆卡视频高光时刻展示</title>
+    <style>
+        body {
+            font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
+            background-color: #f4f4f9;
+            margin: 0;
+            padding: 20px;
+            color: #333;
+        }
+
+        .container {
+            max-width: 900px;
+            margin: 0 auto;
+        }
+
+        h1 {
+            text-align: center;
+            color: #4a5568;
+        }
+
+        /* 输入区域样式 */
+        .input-section {
+            background: white;
+            padding: 20px;
+            border-radius: 12px;
+            box-shadow: 0 4px 6px rgba(0,0,0,0.1);
+            margin-bottom: 30px;
+        }
+
+        textarea {
+            width: 100%;
+            height: 150px;
+            border: 1px solid #ddd;
+            border-radius: 8px;
+            padding: 10px;
+            font-family: monospace;
+            box-sizing: border-box; /* 确保padding不撑大宽度 */
+        }
+
+        button {
+            background-color: #4299e1;
+            color: white;
+            border: none;
+            padding: 10px 20px;
+            border-radius: 6px;
+            cursor: pointer;
+            font-size: 16px;
+            margin-top: 10px;
+            transition: background 0.3s;
+        }
+
+        button:hover {
+            background-color: #3182ce;
+        }
+
+        /* 列表展示样式 */
+        .card-list {
+            display: flex;
+            flex-direction: column;
+            gap: 20px;
+        }
+
+        .card-item {
+            display: flex;
+            background: white;
+            border-radius: 12px;
+            overflow: hidden;
+            box-shadow: 0 4px 6px rgba(0,0,0,0.05);
+            transition: transform 0.2s;
+        }
+
+        .card-item:hover {
+            transform: translateY(-2px);
+            box-shadow: 0 8px 12px rgba(0,0,0,0.1);
+        }
+
+        .card-image {
+            width: 300px;
+            background-color: #eee;
+            flex-shrink: 0;
+        }
+
+        .card-image img {
+            width: 100%;
+            height: 100%;
+            object-fit: cover;
+            display: block;
+        }
+
+        .card-content {
+            padding: 20px;
+            flex-grow: 1;
+            display: flex;
+            flex-direction: column;
+            justify-content: center;
+        }
+
+        .timestamp {
+            background-color: #edf2f7;
+            color: #718096;
+            padding: 4px 8px;
+            border-radius: 4px;
+            font-size: 0.85em;
+            display: inline-block;
+            margin-bottom: 10px;
+            width: fit-content;
+        }
+
+        .card-title {
+            font-size: 1.4em;
+            font-weight: bold;
+            margin: 0 0 5px 0;
+            color: #2d3748;
+        }
+
+        .card-subtitle {
+            color: #718096;
+            font-size: 1em;
+            margin-bottom: 15px;
+        }
+
+        .info-row {
+            display: flex;
+            justify-content: space-between;
+            margin-top: auto;
+            border-top: 1px solid #edf2f7;
+            padding-top: 10px;
+        }
+
+        .rarity {
+            font-weight: bold;
+            color: #e53e3e;
+        }
+
+        .series {
+            color: #4a5568;
+        }
+
+        /* 移动端适配 */
+        @media (max-width: 600px) {
+            .card-item {
+                flex-direction: column;
+            }
+            .card-image {
+                width: 100%;
+                height: 200px;
+            }
+        }
+    </style>
+</head>
+<body>
+
+<div class="container">
+    <h1>🃏 拆卡结果展示</h1>
+
+    <!-- 输入区域 -->
+    <div class="input-section">
+        <h3>粘贴 JSON 数据:</h3>
+        <textarea id="jsonInput" placeholder='[
+  {
+    "time": "00:16:32",
+    "card_name_cn": "船长皮卡丘",
+    ...
+  }
+]'></textarea>
+        <button onclick="renderCards()">生成列表</button>
+    </div>
+
+    <!-- 结果区域 -->
+    <div id="resultList" class="card-list">
+        <!-- 卡片会在这里生成 -->
+    </div>
+</div>
+
+<script>
+    function renderCards() {
+        const input = document.getElementById('jsonInput').value;
+        const container = document.getElementById('resultList');
+
+        // 清空现有列表
+        container.innerHTML = '';
+
+        try {
+            const data = JSON.parse(input);
+
+            if (!Array.isArray(data)) {
+                alert('❌ 输入的不是 JSON 数组格式');
+                return;
+            }
+
+            data.forEach(item => {
+                // 创建卡片 HTML
+                const cardHtml = `
+                    <div class="card-item">
+                        <div class="card-image">
+                            ${item.frame_image_path
+                                ? `<img src="${item.frame_image_path}" alt="${item.card_name_cn}" onerror="this.src='https://via.placeholder.com/300x200?text=Image+Not+Found'">`
+                                : '<div style="height:100%; display:flex; align-items:center; justify-content:center; color:#999;">无图片</div>'}
+                        </div>
+                        <div class="card-content">
+                            <div class="timestamp">⏰ ${item.time}</div>
+                            <h2 class="card-title">${item.card_name_cn || '未知中文名'}</h2>
+                            <div class="card-subtitle">${item.card_name_en || ''}</div>
+
+                            <div class="info-row">
+                                <span class="series">📦 系列: ${item.series || '未知'}</span>
+                                <span class="rarity">${item.rarity_desc || '未知稀有度'}</span>
+                            </div>
+                        </div>
+                    </div>
+                `;
+
+                // 插入 DOM
+                container.insertAdjacentHTML('beforeend', cardHtml);
+            });
+
+        } catch (e) {
+            alert('❌ JSON 解析失败,请检查格式是否正确。\n错误信息: ' + e.message);
+        }
+    }
+</script>
+
+</body>
+</html>