Spaces:
Build error
Build error
Update app.py
Browse files
app.py
CHANGED
@@ -3,10 +3,11 @@ from gradio import mix
|
|
3 |
import tensorflow as tf
|
4 |
import numpy as np
|
5 |
import torch
|
6 |
-
from
|
|
|
|
|
7 |
from huggingface_hub import from_pretrained_keras
|
8 |
|
9 |
-
tokenizer = AutoTokenizer.from_pretrained("bert-base-cased")
|
10 |
model = from_pretrained_keras("keras-io/text-generation-miniature-gpt")
|
11 |
|
12 |
def tokenize_data(text):
|
@@ -21,14 +22,14 @@ def tokenize_data(text):
|
|
21 |
return inputs
|
22 |
|
23 |
def generate_answers(text):
|
24 |
-
|
25 |
-
|
26 |
-
predictions,
|
27 |
-
|
28 |
-
|
29 |
-
|
30 |
-
return
|
31 |
-
|
32 |
examples = [["Once upon a time, "], ["In a galaxy far far away"]]
|
33 |
title = "Text Generation with Miniature GPT"
|
34 |
description = "Gradio Demo for a miniature with GPT. To use it, simply add your text, or click one of the examples to load them. Read more at the links below."
|
|
|
3 |
import tensorflow as tf
|
4 |
import numpy as np
|
5 |
import torch
|
6 |
+
from keras.preprocessing.sequence import pad_sequences
|
7 |
+
import pickle
|
8 |
+
|
9 |
from huggingface_hub import from_pretrained_keras
|
10 |
|
|
|
11 |
model = from_pretrained_keras("keras-io/text-generation-miniature-gpt")
|
12 |
|
13 |
def tokenize_data(text):
|
|
|
22 |
return inputs
|
23 |
|
24 |
def generate_answers(text):
|
25 |
+
sequence_test = tokenizer.texts_to_sequences([text])
|
26 |
+
padded_test = pad_sequences(sequence_test, maxlen= 80, padding='post')
|
27 |
+
predictions,_ = model.predict(padded_test)
|
28 |
+
results = np.argmax(predictions, axis=1)[0]
|
29 |
+
answer = tokenizer.sequences_to_texts([results] )
|
30 |
+
answertoString = ' '.join([str(elem) for elem in answer])
|
31 |
+
return answertoString
|
32 |
+
|
33 |
examples = [["Once upon a time, "], ["In a galaxy far far away"]]
|
34 |
title = "Text Generation with Miniature GPT"
|
35 |
description = "Gradio Demo for a miniature with GPT. To use it, simply add your text, or click one of the examples to load them. Read more at the links below."
|