Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -5,12 +5,19 @@ import os
|
|
| 5 |
|
| 6 |
app = Flask(__name__)
|
| 7 |
|
| 8 |
-
#
|
| 9 |
-
current_dir =
|
| 10 |
-
|
| 11 |
|
| 12 |
-
#
|
| 13 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 14 |
cross_encoder = CrossEncoder(model_name, max_length=256, num_labels=1)
|
| 15 |
|
| 16 |
# Function to preprocess text with Vietnamese word segmentation
|
|
|
|
| 5 |
|
| 6 |
app = Flask(__name__)
|
| 7 |
|
| 8 |
+
# Set the path to the VnCoreNLP JAR file
|
| 9 |
+
current_dir = os.path.dirname(os.path.abspath(__file__)) # Get the directory of app.py
|
| 10 |
+
vncorenlp_path = os.path.join(current_dir, "vncorenlp", "VnCoreNLP-1.2.jar")
|
| 11 |
|
| 12 |
+
# Check if the JAR file exists (for debugging)
|
| 13 |
+
if not os.path.exists(vncorenlp_path):
|
| 14 |
+
raise FileNotFoundError(f"VnCoreNLP JAR file not found at {vncorenlp_path}. Please ensure 'vncorenlp/VnCoreNLP-1.2.jar' is in the root directory.")
|
| 15 |
+
|
| 16 |
+
# Initialize vncorenlp with the JAR file path
|
| 17 |
+
word_segmenter = py_vncorenlp.VnCoreNLP(vncorenlp_path, annotators=["wseg"])
|
| 18 |
+
|
| 19 |
+
# Load your cross-encoder model
|
| 20 |
+
model_name = "truong1301/reranker_pho_BLAI" # Replace with your actual model if different
|
| 21 |
cross_encoder = CrossEncoder(model_name, max_length=256, num_labels=1)
|
| 22 |
|
| 23 |
# Function to preprocess text with Vietnamese word segmentation
|