Ireneo commited on
Commit
1160c53
1 Parent(s): 4f00760

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +10 -41
app.py CHANGED
@@ -3,45 +3,14 @@ import gradio as gr
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()
 
3
  # Load the model
4
  model = gr.Interface.load("models/roneneldan/TinyStories-Instruct-33M")
5
 
6
+ # Create the interface
7
+ interface = gr.Interface(
8
+ fn=model.predict,
9
+ inputs=gr.Textbox(prompt="Type a prompt here..."),
10
+ outputs=gr.Textbox(),
11
+ live=True,
12
+ capture_session=True
13
+ )
 
 
 
 
 
 
 
14
 
15
+ # Launch the interface
16
+ interface.launch()