File size: 1,376 Bytes
dbae169
ebf1343
 
 
 
 
 
 
 
25afb2f
dbae169
ebf1343
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
dbae169
ebf1343
dbae169
ebf1343
 
 
 
 
 
dbae169
 
 
 
8a11efc
 
dbae169
8a11efc
 
dbae169
 
ebf1343
dbae169
b0c8222
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
import gradio as gr
import numpy as np
import keras_nlp
import tensorflow as tf
import tensorflow_datasets as tfds
import tensorflow_text as tf_text
from tensorflow import keras
from tensorflow.lite.python import interpreter
import time
#pip install -q git+https://github.com/keras-team/keras-nlp.git@google-io-2023 tensorflow-text==2.12

gpt2_tokenizer = keras_nlp.models.GPT2Tokenizer.from_preset("gpt2_base_en")
gpt2_preprocessor = keras_nlp.models.GPT2CausalLMPreprocessor.from_preset(
    "gpt2_base_en",
    sequence_length=256,
    add_end_token=True,
)
gpt2_lm = keras_nlp.models.GPT2CausalLM.from_preset("gpt2_base_en", preprocessor=gpt2_preprocessor)

start = time.time()

output = gpt2_lm.generate("My trip to New York was", max_length=200)
print("\nGPT-2 output:")
print(output.numpy().decode("utf-8"))

end = time.time()
print("TOTAL TIME ELAPSED: ", end - start)

start = time.time()

output = gpt2_lm.generate("That Italian restaurant is", max_length=200)
print("\nGPT-2 output:")
print(output.numpy().decode("utf-8"))

end = time.time()
print("TOTAL TIME ELAPSED: ", end - start)

# Define Gradio interface
iface = gr.Interface(
    fn=taf_gpt.generate_response,
    inputs="text",
    outputs="text",
    live=True,
    title="Taf-gpt Chatbot",
    description="Welcome to Taf-gpt! Enter your message below.",
)


# Launch the Gradio interface
iface.launch()