asafd60 commited on
Commit
7f7b7e4
·
verified ·
1 Parent(s): 7afee34

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +38 -28
app.py CHANGED
@@ -1,28 +1,38 @@
1
- import gradio as gr
2
- import tensorflow as tf
3
- from SpaceGen_preprocessing import *
4
- from utils import *
5
-
6
-
7
- # Path to your Keras model
8
- model_path = "SpaceGen_Large.keras"
9
-
10
- # Load the model
11
- model = tf.keras.models.load_model(model_path)
12
-
13
-
14
- def fix_space(text):
15
- text = clean_sentence(text)
16
- X = text_to_X(text)
17
- predictions = model.predict(X, verbose=0)
18
- predicted_labels = []
19
- for pred in predictions[0]:
20
- predicted_labels.append(1 if pred[1] > .5 else 0)
21
- fixed_text = insert_spaces(text.replace(' ',''), find_indices(predicted_labels))
22
- return fixed_text
23
-
24
- default_text = "T hel ittlegi rlra nthro ughth epa rkc has ing abut terfly."
25
- demo = gr.Interface(fn=fix_space,
26
- inputs=gr.Textbox(label="Input Text", value=default_text),
27
- outputs="text")
28
- demo.launch()
 
 
 
 
 
 
 
 
 
 
 
1
+ import gradio as gr
2
+ import tensorflow as tf
3
+ from SpaceGen_preprocessing import *
4
+ from utils import *
5
+
6
+ # טוען את המודל
7
+ model_path = "SpaceGen_Large.keras"
8
+ model = tf.keras.models.load_model(model_path)
9
+
10
+ # פונקציית תיקון רווחים
11
+ def fix_space(text):
12
+ text = clean_sentence(text)
13
+ X = text_to_X(text)
14
+ predictions = model.predict(X, verbose=0)
15
+ predicted_labels = []
16
+ for pred in predictions[0]:
17
+ predicted_labels.append(1 if pred[1] > .5 else 0)
18
+ fixed_text = insert_spaces(text.replace(' ',''), find_indices(predicted_labels))
19
+ return fixed_text
20
+
21
+ default_text = "T hel ittlegi rlra nthro ughth epa rkc has ing abut terfly."
22
+
23
+ description = (
24
+ "פרויקט לימודי במדעי הנתונים ומדעי המוח.\n"
25
+ "המערכת מדגימה שימוש ברשת LSTM לזיהוי מיקום רווחים חסרים בטקסט.\n"
26
+ "נכון לעכשיו, המודל תומך באנגלית בלבד.\n"
27
+ "לשאלות וביקורות: [email protected]"
28
+ )
29
+
30
+ demo = gr.Interface(
31
+ fn=fix_space,
32
+ inputs=gr.Textbox(label="Input Text", value=default_text),
33
+ outputs="text",
34
+ title="SpaceGen – Text Space Correction with LSTM",
35
+ description=description
36
+ )
37
+
38
+ demo.launch()