Update app.py
Browse files
app.py
CHANGED
|
@@ -1,17 +1,39 @@
|
|
| 1 |
import gradio as gr
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 2 |
|
| 3 |
-
|
| 4 |
-
|
| 5 |
-
|
| 6 |
-
|
| 7 |
-
|
| 8 |
-
|
| 9 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 10 |
|
| 11 |
-
|
| 12 |
|
| 13 |
-
|
| 14 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 15 |
|
| 16 |
# Define Gradio interface
|
| 17 |
iface = gr.Interface(
|
|
@@ -23,8 +45,6 @@ iface = gr.Interface(
|
|
| 23 |
description="Welcome to Taf-gpt! Enter your message below.",
|
| 24 |
)
|
| 25 |
|
|
|
|
| 26 |
# Launch the Gradio interface
|
| 27 |
iface.launch()
|
| 28 |
-
|
| 29 |
-
# Example chat: Asking about artificial intelligence
|
| 30 |
-
print(taf_gpt.generate_response("What is artificial intelligence?"))
|
|
|
|
| 1 |
import gradio as gr
|
| 2 |
+
import numpy as np
|
| 3 |
+
import keras_nlp
|
| 4 |
+
import tensorflow as tf
|
| 5 |
+
import tensorflow_datasets as tfds
|
| 6 |
+
import tensorflow_text as tf_text
|
| 7 |
+
from tensorflow import keras
|
| 8 |
+
from tensorflow.lite.python import interpreter
|
| 9 |
+
import time
|
| 10 |
+
pip install -q git+https://github.com/keras-team/keras-nlp.git@google-io-2023 tensorflow-text==2.12
|
| 11 |
|
| 12 |
+
gpt2_tokenizer = keras_nlp.models.GPT2Tokenizer.from_preset("gpt2_base_en")
|
| 13 |
+
gpt2_preprocessor = keras_nlp.models.GPT2CausalLMPreprocessor.from_preset(
|
| 14 |
+
"gpt2_base_en",
|
| 15 |
+
sequence_length=256,
|
| 16 |
+
add_end_token=True,
|
| 17 |
+
)
|
| 18 |
+
gpt2_lm = keras_nlp.models.GPT2CausalLM.from_preset("gpt2_base_en", preprocessor=gpt2_preprocessor)
|
| 19 |
+
|
| 20 |
+
start = time.time()
|
| 21 |
+
|
| 22 |
+
output = gpt2_lm.generate("My trip to New York was", max_length=200)
|
| 23 |
+
print("\nGPT-2 output:")
|
| 24 |
+
print(output.numpy().decode("utf-8"))
|
| 25 |
+
|
| 26 |
+
end = time.time()
|
| 27 |
+
print("TOTAL TIME ELAPSED: ", end - start)
|
| 28 |
|
| 29 |
+
start = time.time()
|
| 30 |
|
| 31 |
+
output = gpt2_lm.generate("That Italian restaurant is", max_length=200)
|
| 32 |
+
print("\nGPT-2 output:")
|
| 33 |
+
print(output.numpy().decode("utf-8"))
|
| 34 |
+
|
| 35 |
+
end = time.time()
|
| 36 |
+
print("TOTAL TIME ELAPSED: ", end - start)
|
| 37 |
|
| 38 |
# Define Gradio interface
|
| 39 |
iface = gr.Interface(
|
|
|
|
| 45 |
description="Welcome to Taf-gpt! Enter your message below.",
|
| 46 |
)
|
| 47 |
|
| 48 |
+
|
| 49 |
# Launch the Gradio interface
|
| 50 |
iface.launch()
|
|
|
|
|
|
|
|
|