Reverting back to original version
Browse files
app.py
CHANGED
|
@@ -1,30 +1,27 @@
|
|
| 1 |
import gradio as gr
|
| 2 |
-
|
| 3 |
-
import
|
| 4 |
|
| 5 |
-
# Load the
|
| 6 |
-
|
| 7 |
-
tokenizer = AutoTokenizer.from_pretrained(model_name)
|
| 8 |
-
model = AutoModelForCausalLM.from_pretrained(model_name)
|
| 9 |
|
| 10 |
-
#
|
| 11 |
-
|
| 12 |
-
|
| 13 |
-
|
| 14 |
-
|
| 15 |
-
|
| 16 |
-
|
| 17 |
-
for token in pipeline(prompt, max_length=100, num_return_sequences=1, do_sample=True, top_k=50, top_p=0.95):
|
| 18 |
-
output += token['generated_text']
|
| 19 |
-
yield output # Stream the output
|
| 20 |
-
await loop.run_in_executor(None, lambda: None) # Yield control to the event loop
|
| 21 |
|
| 22 |
# Create a Gradio interface
|
| 23 |
iface = gr.Interface(
|
| 24 |
fn=generate_text,
|
| 25 |
inputs=gr.Textbox(lines=2, placeholder="Enter your prompt here..."),
|
| 26 |
-
outputs=
|
| 27 |
-
|
|
|
|
|
|
|
|
|
|
| 28 |
)
|
| 29 |
|
| 30 |
# Launch the interface
|
|
|
|
| 1 |
import gradio as gr
|
| 2 |
+
import time
|
| 3 |
+
from transformers import pipeline
|
| 4 |
|
| 5 |
+
# Load the TinyLlama text generation pipeline
|
| 6 |
+
pipe = pipeline("text-generation", model="TinyLlama/TinyLlama-1.1B-Chat-v1.0")
|
|
|
|
|
|
|
| 7 |
|
| 8 |
+
# Define the inference function
|
| 9 |
+
def generate_text(prompt):
|
| 10 |
+
start_time = time.time()
|
| 11 |
+
results = pipe(prompt, max_length=100, 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=gr.Textbox(lines=2, placeholder="Enter your prompt here..."),
|
| 20 |
+
outputs=[
|
| 21 |
+
gr.Textbox(label="Generated Text"),
|
| 22 |
+
gr.Textbox(label="Response Time")
|
| 23 |
+
],
|
| 24 |
+
title="TinyLlama Text Generation"
|
| 25 |
)
|
| 26 |
|
| 27 |
# Launch the interface
|