kdevoe commited on
Commit
ba56c16
·
1 Parent(s): 0b9a201

Adding timer

Browse files
Files changed (1) hide show
  1. app.py +13 -2
app.py CHANGED
@@ -1,4 +1,5 @@
1
  import gradio as gr
 
2
  from transformers import pipeline
3
 
4
  # Load the TinyLlama text generation pipeline
@@ -6,11 +7,21 @@ pipe = pipeline("text-generation", model="TinyLlama/TinyLlama-1.1B-Chat-v1.0")
6
 
7
  # Define the inference function
8
  def generate_text(prompt):
 
9
  results = pipe(prompt, max_length=50, num_return_sequences=1)
10
- return results[0]['generated_text']
 
 
11
 
12
  # Create a Gradio interface
13
- iface = gr.Interface(fn=generate_text, inputs="text", outputs="text", title="TinyLlama Text Generation")
 
 
 
 
 
 
 
14
 
15
  # Launch the interface
16
  iface.launch()
 
1
  import gradio as gr
2
+ import time
3
  from transformers import pipeline
4
 
5
  # Load the TinyLlama text generation pipeline
 
7
 
8
  # Define the inference function
9
  def generate_text(prompt):
10
+ start_time = time.time()
11
  results = pipe(prompt, max_length=50, num_return_sequences=1)
12
+ end_time = time.time()
13
+ response_time = end_time - start_time
14
+ return results[0]['generated_text'], f"{response_time:.2f} seconds"
15
 
16
  # Create a Gradio interface
17
+ iface = gr.Interface(
18
+ fn=generate_text,
19
+ inputs="text",
20
+ outputs=[
21
+ gr.outputs.Textbox(label="Generated Text"),
22
+ gr.outputs.Textbox(label="Response Time")
23
+ ],
24
+ title="TinyLlama Text Generation")
25
 
26
  # Launch the interface
27
  iface.launch()