Spaces:
Sleeping
Sleeping
File size: 3,869 Bytes
416bd58 |
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 |
<!DOCTYPE html>
<html>
<head>
<title>Text Generation API</title>
<link
rel="stylesheet"
href="https://stackpath.bootstrapcdn.com/bootstrap/4.5.2/css/bootstrap.min.css"
/>
<style>
body {
background-color: #f8f9fa;
padding: 20px;
}
.container {
max-width: 600px;
margin: auto;
background: #fff;
padding: 20px;
border-radius: 8px;
box-shadow: 0 0 10px rgba(0, 0, 0, 0.1);
}
h1 {
text-align: center;
margin-bottom: 20px;
}
.form-group {
margin-bottom: 15px;
}
.btn {
width: 100%;
}
.output {
margin-top: 20px;
padding: 10px;
background: #e9ecef;
border-radius: 8px;
max-height: 300px;
/* Example: limit height with overflow */
overflow-y: auto;
/* Example: add scrollbars if content exceeds */
}
.spinner-border {
display: none;
}
</style>
</head>
<body>
<div class="container">
<h1>Text Generation API</h1>
<form id="generateForm">
<div class="form-group">
<label for="generateText">Enter text:</label>
<input
type="text"
class="form-control"
id="generateText"
name="text"
required
/>
</div>
<button type="submit" class="btn btn-primary">
Generate with Hugging Face
</button>
<div class="spinner-border text-primary" role="status" id="hfSpinner">
<span class="sr-only">Loading...</span>
</div>
</form>
<div id="output" class="output"></div>
<form id="cohereForm">
<div class="form-group">
<label for="cohereText">Enter text:</label>
<input
type="text"
class="form-control"
id="cohereText"
name="text"
required
/>
</div>
<button type="submit" class="btn btn-success">
Generate with Cohere AI
</button>
<div
class="spinner-border text-success"
role="status"
id="cohereSpinner"
>
<span class="sr-only">Loading...</span>
</div>
</form>
<div id="cohereOutput" class="output"></div>
</div>
<script>
document
.getElementById("generateForm")
.addEventListener("submit", async function (event) {
event.preventDefault();
document.getElementById("hfSpinner").style.display = "inline-block";
const text = document.getElementById("generateText").value;
const response = await fetch(
`/generate/?text=${encodeURIComponent(text)}`
);
const data = await response.json();
document.getElementById("hfSpinner").style.display = "none";
document.getElementById("output").innerHTML = data.output; // Use innerHTML instead of textContent
});
document
.getElementById("cohereForm")
.addEventListener("submit", async function (event) {
event.preventDefault();
document.getElementById("cohereSpinner").style.display =
"inline-block";
const text = document.getElementById("cohereText").value;
const response = await fetch(
`/cohereai/?text=${encodeURIComponent(text)}`
);
const data = await response.json();
document.getElementById("cohereSpinner").style.display = "none";
document.getElementById("cohereOutput").innerHTML = data.output; // Use innerHTML instead of textContent
});
</script>
</body>
</html>
|