Update app.py
Browse files
app.py
CHANGED
@@ -1,21 +1,47 @@
|
|
1 |
import gradio as gr
|
2 |
-
import time
|
3 |
|
4 |
# Load the model
|
5 |
model = gr.Interface.load("models/roneneldan/TinyStories-Instruct-33M")
|
6 |
|
7 |
-
#
|
8 |
-
|
9 |
-
|
10 |
-
|
11 |
-
|
12 |
-
|
13 |
-
|
14 |
-
|
15 |
-
|
16 |
-
|
|
|
|
|
|
|
|
|
|
|
17 |
|
18 |
-
|
19 |
-
|
20 |
-
|
21 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
import gradio as gr
|
|
|
2 |
|
3 |
# Load the model
|
4 |
model = gr.Interface.load("models/roneneldan/TinyStories-Instruct-33M")
|
5 |
|
6 |
+
# HTML template with JavaScript to update the text dynamically
|
7 |
+
html_code = """
|
8 |
+
<!DOCTYPE html>
|
9 |
+
<html>
|
10 |
+
<head>
|
11 |
+
<title>Tiny Stories Generator</title>
|
12 |
+
<script>
|
13 |
+
function generateStory() {
|
14 |
+
var inputText = document.getElementById("input-text").value;
|
15 |
+
gr.Interface.static.predict(inputText).then(function(outputText) {
|
16 |
+
document.getElementById("output-text").innerHTML = "";
|
17 |
+
typeText(inputText + " ");
|
18 |
+
typeText(outputText);
|
19 |
+
});
|
20 |
+
}
|
21 |
|
22 |
+
function typeText(text) {
|
23 |
+
var index = 0;
|
24 |
+
var typingSpeed = 50; // Adjust the speed of typing
|
25 |
+
var timer = setInterval(function() {
|
26 |
+
if (index < text.length) {
|
27 |
+
document.getElementById("output-text").innerHTML += text.charAt(index);
|
28 |
+
index++;
|
29 |
+
} else {
|
30 |
+
clearInterval(timer);
|
31 |
+
}
|
32 |
+
}, typingSpeed);
|
33 |
+
}
|
34 |
+
</script>
|
35 |
+
</head>
|
36 |
+
<body>
|
37 |
+
<div style="padding: 20px;">
|
38 |
+
<textarea id="input-text" placeholder="Enter your story here..." style="width: 100%; height: 200px;"></textarea>
|
39 |
+
<button onclick="generateStory()">Generate Story</button>
|
40 |
+
<div id="output-text" style="margin-top: 20px;"></div>
|
41 |
+
</div>
|
42 |
+
</body>
|
43 |
+
</html>
|
44 |
+
"""
|
45 |
+
|
46 |
+
# Launch the interface using the custom HTML code
|
47 |
+
gr.Interface(fn=lambda inputs: inputs, inputs=gr.inputs.Textbox(), outputs=gr.outputs.HTML(html_code)).launch()
|