Spaces:
Sleeping
Sleeping
Upload app.py
Browse files
app.py
CHANGED
|
@@ -1,14 +1,10 @@
|
|
| 1 |
import gradio as gr
|
| 2 |
import pickle
|
| 3 |
-
import re
|
| 4 |
-
import string
|
| 5 |
import tensorflow as tf
|
| 6 |
import keras.ops as ops
|
| 7 |
import keras
|
| 8 |
-
from keras.saving import register_keras_serializable
|
| 9 |
from keras import layers
|
| 10 |
from keras.layers import TextVectorization
|
| 11 |
-
from nltk.translate.bleu_score import sentence_bleu, SmoothingFunction
|
| 12 |
|
| 13 |
|
| 14 |
# from gradio_webrtc import WebRTC
|
|
@@ -196,7 +192,6 @@ transformer = keras.models.load_model(
|
|
| 196 |
id_vocab = id_vectorization.get_vocabulary()
|
| 197 |
id_index_lookup = dict(zip(range(len(id_vocab)), id_vocab))
|
| 198 |
max_decoded_sentence_lenth = 20
|
| 199 |
-
smoothing_function = SmoothingFunction().method2
|
| 200 |
|
| 201 |
def decode_sequence(input_sentence):
|
| 202 |
tokenized_input_sentence = en_vectorization([input_sentence])
|
|
@@ -217,7 +212,7 @@ def decode_sequence(input_sentence):
|
|
| 217 |
decoded_sentence += " " + sampled_token
|
| 218 |
if sampled_token == "end":
|
| 219 |
break
|
| 220 |
-
return decoded_sentence.replace("[start]", "").replace("end", "").
|
| 221 |
|
| 222 |
# image = WebRTC(label="Stream")
|
| 223 |
|
|
|
|
| 1 |
import gradio as gr
|
| 2 |
import pickle
|
|
|
|
|
|
|
| 3 |
import tensorflow as tf
|
| 4 |
import keras.ops as ops
|
| 5 |
import keras
|
|
|
|
| 6 |
from keras import layers
|
| 7 |
from keras.layers import TextVectorization
|
|
|
|
| 8 |
|
| 9 |
|
| 10 |
# from gradio_webrtc import WebRTC
|
|
|
|
| 192 |
id_vocab = id_vectorization.get_vocabulary()
|
| 193 |
id_index_lookup = dict(zip(range(len(id_vocab)), id_vocab))
|
| 194 |
max_decoded_sentence_lenth = 20
|
|
|
|
| 195 |
|
| 196 |
def decode_sequence(input_sentence):
|
| 197 |
tokenized_input_sentence = en_vectorization([input_sentence])
|
|
|
|
| 212 |
decoded_sentence += " " + sampled_token
|
| 213 |
if sampled_token == "end":
|
| 214 |
break
|
| 215 |
+
return decoded_sentence.replace("[start]", "").replace("end", "").lstrip().rstrip()
|
| 216 |
|
| 217 |
# image = WebRTC(label="Stream")
|
| 218 |
|