File size: 1,609 Bytes
40fb01d b748808 4f00760 b748808 4f00760 |
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 |
import gradio as gr
# Load the model
model = gr.Interface.load("models/roneneldan/TinyStories-Instruct-33M")
# HTML template with JavaScript to update the text dynamically
html_code = """
<!DOCTYPE html>
<html>
<head>
<title>Tiny Stories Generator</title>
<script>
function generateStory() {
var inputText = document.getElementById("input-text").value;
gr.Interface.static.predict(inputText).then(function(outputText) {
document.getElementById("output-text").innerHTML = "";
typeText(inputText + " ");
typeText(outputText);
});
}
function typeText(text) {
var index = 0;
var typingSpeed = 50; // Adjust the speed of typing
var timer = setInterval(function() {
if (index < text.length) {
document.getElementById("output-text").innerHTML += text.charAt(index);
index++;
} else {
clearInterval(timer);
}
}, typingSpeed);
}
</script>
</head>
<body>
<div style="padding: 20px;">
<textarea id="input-text" placeholder="Enter your story here..." style="width: 100%; height: 200px;"></textarea>
<button onclick="generateStory()">Generate Story</button>
<div id="output-text" style="margin-top: 20px;"></div>
</div>
</body>
</html>
"""
# Launch the interface using the custom HTML code
gr.Interface(fn=lambda inputs: inputs, inputs=gr.inputs.Textbox(), outputs=gr.outputs.HTML(html_code)).launch()
|