Spaces:
Runtime error
Runtime error
File size: 6,748 Bytes
43317b5 |
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 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 |
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>CSV File Editor</title>
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.5.2/css/bootstrap.min.css">
<style>
.container {
margin-top: 20px;
}
.btn {
margin-top: 20px;
}
.form-control {
width: 100%;
}
.data-section {
margin-top: 40px;
}
.table-container {
overflow-x: auto;
}
.table-wrapper {
display: flex;
justify-content: space-between;
gap: 20px;
}
.table-wrapper table {
width: 100%;
}
</style>
</head>
<body>
<div class="container">
<h2 class="mb-4">Upload, View, and Edit CSV File</h2>
<!-- CSV Upload Section -->
<form method="POST" action="/upload_csv" enctype="multipart/form-data">
<div class="form-group">
<label for="csvFile">Upload CSV File:</label>
<input type="file" name="csv_file" id="csvFile" class="form-control-file" accept=".csv" required>
<button type="submit" class="btn btn-primary">Upload CSV</button>
</form>
<!-- Instruction Section -->
<form method="POST" action="/edit_csv">
<!-- Buttons for Speech Recording -->
<div class="mt-4">
<button type="button" id="recordButton" class="btn btn-danger">🎤 Record</button>
<button type="button" id="stopButton" class="btn btn-secondary" disabled>⏹ Stop</button>
</div>
<div class="form-group mt-4">
<label for="transcription">Instruction:</label>
<textarea name="transcription" id="transcription" class="form-control" rows="3" placeholder="Provide instructions for CSV manipulation..."></textarea>
</div>
<button type="submit" class="btn btn-success">Process Instruction</button>
</form>
<!-- Original and Updated Data Section -->
<div class="data-section">
<h3>Data Comparison</h3>
<div class="table-wrapper">
<!-- Original Data -->
{% if original_data %}
<div>
<h4>Original Data</h4>
<div class="table-container">
<table class="table table-bordered">
<thead>
<tr>
{% for column in columns %}
<th>{{ column }}</th>
{% endfor %}
</tr>
</thead>
<tbody>
{% for row in original_data %}
<tr>
{% for column in columns %}
<td>{{ row[column] }}</td>
{% endfor %}
</tr>
{% endfor %}
</tbody>
</table>
</div>
</div>
{% endif %}
<!-- Updated Data -->
{% if updated_data %}
<div>
<h4>Updated Data</h4>
<div class="table-container">
<table class="table table-bordered">
<thead>
<tr>
{% for column in columns %}
<th>{{ column }}</th>
{% endfor %}
</tr>
</thead>
<tbody>
{% for row in updated_data %}
<tr>
{% for column in columns %}
<td>{{ row[column] }}</td>
{% endfor %}
</tr>
{% endfor %}
</tbody>
</table>
</div>
</div>
{% endif %}
</div>
</div>
</div>
<script>
let mediaRecorder;
let audioChunks = [];
document.getElementById('recordButton').addEventListener('click', function () {
navigator.mediaDevices.getUserMedia({ audio: true })
.then(stream => {
mediaRecorder = new MediaRecorder(stream);
mediaRecorder.start();
audioChunks = [];
mediaRecorder.ondataavailable = event => {
audioChunks.push(event.data);
};
mediaRecorder.onstart = () => {
document.getElementById('recordButton').disabled = true;
document.getElementById('stopButton').disabled = false;
};
mediaRecorder.onstop = () => {
document.getElementById('recordButton').disabled = false;
document.getElementById('stopButton').disabled = true;
const audioBlob = new Blob(audioChunks, { type: 'audio/wav' });
const formData = new FormData();
formData.append('audio', audioBlob, 'recording.wav');
// Send the audio blob to the backend for transcription
fetch('/process_audio', {
method: 'POST',
body: formData
})
.then(response => response.json())
.then(data => {
document.getElementById('transcription').value = data.transcription;
})
.catch(error => {
console.error('Error:', error);
});
};
})
.catch(error => {
console.error('Error accessing microphone:', error);
});
});
document.getElementById('stopButton').addEventListener('click', function () {
mediaRecorder.stop();
});
</script>
</body>
</html>
|