File size: 1,323 Bytes
7f7b7e4 42587d6 7f7b7e4 |
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 |
import gradio as gr
import tensorflow as tf
from SpaceGen_preprocessing import *
from utils import *
# טוען את המודל
model_path = "SpaceGen_Large.keras"
model = tf.keras.models.load_model(model_path)
# פונקציית תיקון רווחים
def fix_space(text):
text = clean_sentence(text)
X = text_to_X(text)
predictions = model.predict(X, verbose=0)
predicted_labels = []
for pred in predictions[0]:
predicted_labels.append(1 if pred[1] > .5 else 0)
fixed_text = insert_spaces(text.replace(' ',''), find_indices(predicted_labels))
return fixed_text
default_text = "T hel ittlegi rlra nthro ughth epa rkc has ing abut terfly."
description = (
"SpaceGen is an academic project developed by Asaf Delmedigo and Romi Zarchi "
"during their graduate studies in Neuroscience and Data Science.\n"
"It demonstrates the use of an LSTM neural network for automatic detection "
"and correction of missing spaces in text.\n"
"Currently, the model supports English text only.\n"
"Feedback is welcome at: delmedigo.asaf@gmail.com"
)
demo = gr.Interface(
fn=fix_space,
inputs=gr.Textbox(label="Input Text", value=default_text),
outputs="text",
title="SpaceGen – Text Space Correction with LSTM",
description=description
)
demo.launch()
|