Ireneo commited on
Commit
4f00760
1 Parent(s): 60b66fc

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +41 -15
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
- # Simulate the typing effect
8
- def simulate_typing(input_text):
9
- typing_speed = 0.05 # Adjust the speed of typing
10
- generated_text = model.predict(input_text)
11
- for char in generated_text:
12
- time.sleep(typing_speed)
13
- # Update the text display area in the Android app with each character
14
- # You'll need to implement this part in your Android app using appropriate methods.
15
- # For example, you can update the TextView in Android with the new character.
16
- return generated_text
 
 
 
 
 
17
 
18
- # Launch the interface
19
- gr.Interface(fn=simulate_typing, inputs=gr.inputs.Textbox(label="Input Text", placeholder="Enter your story here..."),
20
- outputs=gr.outputs.Textbox(label="Generated Story"), title="Tiny Stories Generator",
21
- description="This model generates creative stories based on the input text provided.").launch()
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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()