File size: 3,981 Bytes
08080e4
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Local Intro Scorer</title>
    <link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0/dist/css/bootstrap.min.css" rel="stylesheet">
    <style>
        body { background-color: #f8f9fa; padding-top: 50px; }
        .card-score { font-size: 2rem; font-weight: bold; color: #0d6efd; }
    </style>
</head>
<body>
    <div class="container">
        <h1 class="text-center mb-4">Introduction Scoring System (Local)</h1>
        
        <div class="row">
            <div class="col-md-6">
                <div class="card p-4">
                    <div class="mb-3">
                        <label for="transcript" class="form-label">Transcript</label>
                        <textarea class="form-control" id="transcript" rows="10" placeholder="Paste text here..."></textarea>
                    </div>
                    <div class="mb-3">
                        <label for="duration" class="form-label">Duration (seconds)</label>
                        <input type="number" class="form-control" id="duration" value="60">
                    </div>
                    <button onclick="analyze()" class="btn btn-primary w-100" id="btnAnalyze">Analyze</button>
                </div>
            </div>
            
            <div class="col-md-6">
                <div class="card p-4 h-100">
                    <h3>Results</h3>
                    <div id="loading" class="text-muted" style="display:none;">Processing...</div>
                    <div id="results-area" style="display:none;">
                        <div class="text-center mb-3">
                            <div>Total Score</div>
                            <div class="card-score" id="total-score">0/100</div>
                        </div>
                        <ul class="list-group" id="breakdown-list">
                            </ul>
                    </div>
                </div>
            </div>
        </div>
    </div>

    <script>
        async function analyze() {
            const transcript = document.getElementById('transcript').value;
            const duration = document.getElementById('duration').value;
            const btn = document.getElementById('btnAnalyze');
            const loading = document.getElementById('loading');
            const resArea = document.getElementById('results-area');
            
            if(!transcript) return alert("Please enter text");

            btn.disabled = true;
            loading.style.display = 'block';
            resArea.style.display = 'none';

            try {
                const response = await fetch('/api/score', {
                    method: 'POST',
                    headers: {'Content-Type': 'application/json'},
                    body: JSON.stringify({ transcript: transcript, duration: parseInt(duration) })
                });
                
                const data = await response.json();
                
                document.getElementById('total-score').innerText = data['Total Score'] + "/100";
                const list = document.getElementById('breakdown-list');
                list.innerHTML = "";

                for (const [key, val] of Object.entries(data['Breakdown'])) {
                    const li = document.createElement('li');
                    li.className = "list-group-item";
                    li.innerHTML = `<strong>${key}</strong>: ${val.score} pts <br><small class='text-muted'>${val.feedback}</small>`;
                    list.appendChild(li);
                }

                resArea.style.display = 'block';
            } catch (error) {
                alert("Error connecting to backend");
                console.error(error);
            } finally {
                btn.disabled = false;
                loading.style.display = 'none';
            }
        }
    </script>
</body>
</html>