Create templates /index.html
Browse files- templates /index.html +87 -0
templates /index.html
ADDED
|
@@ -0,0 +1,87 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
<!DOCTYPE html>
|
| 2 |
+
<html lang="en">
|
| 3 |
+
<head>
|
| 4 |
+
<meta charset="UTF-8">
|
| 5 |
+
<title>Flask API Test on Hugging Face</title>
|
| 6 |
+
<style>
|
| 7 |
+
body {
|
| 8 |
+
font-family: Arial, sans-serif;
|
| 9 |
+
margin: 20px;
|
| 10 |
+
}
|
| 11 |
+
textarea, input[type="text"] {
|
| 12 |
+
width: 100%;
|
| 13 |
+
max-width: 600px;
|
| 14 |
+
}
|
| 15 |
+
.result {
|
| 16 |
+
margin-top: 20px;
|
| 17 |
+
padding: 10px;
|
| 18 |
+
border: 1px solid #ddd;
|
| 19 |
+
background: #f9f9f9;
|
| 20 |
+
white-space: pre-wrap;
|
| 21 |
+
}
|
| 22 |
+
</style>
|
| 23 |
+
</head>
|
| 24 |
+
<body>
|
| 25 |
+
<h1>Flask API Test</h1>
|
| 26 |
+
|
| 27 |
+
<h2>Text to Text</h2>
|
| 28 |
+
<form id="textToTextForm">
|
| 29 |
+
<label for="message">Enter message:</label><br>
|
| 30 |
+
<textarea id="message" name="message" rows="4" placeholder="Type your message here..."></textarea><br><br>
|
| 31 |
+
<button type="submit">Submit</button>
|
| 32 |
+
</form>
|
| 33 |
+
<div class="result" id="textToTextResult"></div>
|
| 34 |
+
|
| 35 |
+
<h2>Text to Speech</h2>
|
| 36 |
+
<form id="textToSpeechForm">
|
| 37 |
+
<label for="tts_message">Enter message for TTS:</label><br>
|
| 38 |
+
<textarea id="tts_message" name="tts_message" rows="4" placeholder="Type your message here..."></textarea><br><br>
|
| 39 |
+
<label for="output_filename">Output Filename:</label><br>
|
| 40 |
+
<input type="text" id="output_filename" name="output_filename" value="output.wav"><br><br>
|
| 41 |
+
<button type="submit">Submit</button>
|
| 42 |
+
</form>
|
| 43 |
+
<div class="result" id="textToSpeechResult"></div>
|
| 44 |
+
|
| 45 |
+
<script>
|
| 46 |
+
// Text to Text Endpoint
|
| 47 |
+
document.getElementById('textToTextForm').addEventListener('submit', async function(e) {
|
| 48 |
+
e.preventDefault();
|
| 49 |
+
const message = document.getElementById('message').value;
|
| 50 |
+
const payload = { message: message, Saved_response: "" };
|
| 51 |
+
try {
|
| 52 |
+
const response = await fetch('/text_to_text', {
|
| 53 |
+
method: 'POST',
|
| 54 |
+
headers: { 'Content-Type': 'application/json' },
|
| 55 |
+
body: JSON.stringify(payload)
|
| 56 |
+
});
|
| 57 |
+
const result = await response.json();
|
| 58 |
+
document.getElementById('textToTextResult').innerText = JSON.stringify(result, null, 2);
|
| 59 |
+
} catch (error) {
|
| 60 |
+
document.getElementById('textToTextResult').innerText = 'Error: ' + error;
|
| 61 |
+
}
|
| 62 |
+
});
|
| 63 |
+
|
| 64 |
+
// Text to Speech Endpoint
|
| 65 |
+
document.getElementById('textToSpeechForm').addEventListener('submit', async function(e) {
|
| 66 |
+
e.preventDefault();
|
| 67 |
+
const message = document.getElementById('tts_message').value;
|
| 68 |
+
const outputFilename = document.getElementById('output_filename').value;
|
| 69 |
+
const payload = { message: message, output_filename: outputFilename, Saved_response: "" };
|
| 70 |
+
try {
|
| 71 |
+
const response = await fetch('/text_to_speech', {
|
| 72 |
+
method: 'POST',
|
| 73 |
+
headers: { 'Content-Type': 'application/json' },
|
| 74 |
+
body: JSON.stringify(payload)
|
| 75 |
+
});
|
| 76 |
+
const result = await response.json();
|
| 77 |
+
// Display the JSON response and also offer a download link if needed.
|
| 78 |
+
document.getElementById('textToSpeechResult').innerHTML =
|
| 79 |
+
`<pre>${JSON.stringify(result, null, 2)}</pre>
|
| 80 |
+
<p><a href="${result.output_filename}" download>Download ${result.output_filename}</a></p>`;
|
| 81 |
+
} catch (error) {
|
| 82 |
+
document.getElementById('textToSpeechResult').innerText = 'Error: ' + error;
|
| 83 |
+
}
|
| 84 |
+
});
|
| 85 |
+
</script>
|
| 86 |
+
</body>
|
| 87 |
+
</html>
|