Tafar commited on
Commit
ebf1343
1 Parent(s): 61af0ee

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +33 -13
app.py CHANGED
@@ -1,17 +1,39 @@
1
  import gradio as gr
 
 
 
 
 
 
 
 
 
2
 
3
- class TafGPT:
4
- def generate_response(self, user_input):
5
- # Replace this with your own logic or use external APIs for more advanced responses
6
- if "artificial intelligence" in user_input.lower():
7
- response = "Taf-gpt: Artificial Intelligence (AI) refers to the simulation of human intelligence in machines, enabling them to perform tasks that typically require human intelligence."
8
- else:
9
- response = f"Taf-gpt: Thank you for asking: I'm a simple chatbot in development soon I will be able to help you with more requests."
 
 
 
 
 
 
 
 
 
10
 
11
- return response
12
 
13
- # Create an instance of TafGPT
14
- taf_gpt = TafGPT()
 
 
 
 
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()