Spaces:
Sleeping
Sleeping
Update streamlit_app.py
Browse files- streamlit_app.py +13 -2
streamlit_app.py
CHANGED
|
@@ -3,6 +3,7 @@ import fitz # PyMuPDF
|
|
| 3 |
import torch
|
| 4 |
import time
|
| 5 |
import re
|
|
|
|
| 6 |
import torch.nn.functional as F
|
| 7 |
from transformers import (
|
| 8 |
AutoTokenizer,
|
|
@@ -447,7 +448,10 @@ MODEL_OPTIONS = {
|
|
| 447 |
}
|
| 448 |
|
| 449 |
# FastText Configuration
|
| 450 |
-
FASTTEXT_MODEL_PATH = "doc_classifier.bin"
|
|
|
|
|
|
|
|
|
|
| 451 |
FASTTEXT_THRESHOLD = 0.45
|
| 452 |
|
| 453 |
# Add FastText to model options if available
|
|
@@ -485,10 +489,17 @@ def load_model(model_name):
|
|
| 485 |
st.error("FastText is not installed. Please install it using: pip install fasttext")
|
| 486 |
return None, None
|
| 487 |
try:
|
|
|
|
|
|
|
|
|
|
|
|
|
| 488 |
model = fasttext.load_model(FASTTEXT_MODEL_PATH)
|
| 489 |
return None, model # FastText doesn't need a tokenizer
|
| 490 |
except FileNotFoundError:
|
| 491 |
-
st.error(f"FastText model file not found: {FASTTEXT_MODEL_PATH}")
|
|
|
|
|
|
|
|
|
|
| 492 |
return None, None
|
| 493 |
else:
|
| 494 |
tokenizer = AutoTokenizer.from_pretrained(model_name)
|
|
|
|
| 3 |
import torch
|
| 4 |
import time
|
| 5 |
import re
|
| 6 |
+
import os
|
| 7 |
import torch.nn.functional as F
|
| 8 |
from transformers import (
|
| 9 |
AutoTokenizer,
|
|
|
|
| 448 |
}
|
| 449 |
|
| 450 |
# FastText Configuration
|
| 451 |
+
FASTTEXT_MODEL_PATH = os.path.join(os.path.dirname(__file__), "doc_classifier.bin")
|
| 452 |
+
# Fallback to relative path if __file__ is not available
|
| 453 |
+
if not os.path.exists(FASTTEXT_MODEL_PATH):
|
| 454 |
+
FASTTEXT_MODEL_PATH = "doc_classifier.bin"
|
| 455 |
FASTTEXT_THRESHOLD = 0.45
|
| 456 |
|
| 457 |
# Add FastText to model options if available
|
|
|
|
| 489 |
st.error("FastText is not installed. Please install it using: pip install fasttext")
|
| 490 |
return None, None
|
| 491 |
try:
|
| 492 |
+
# Check if model file exists
|
| 493 |
+
if not os.path.exists(FASTTEXT_MODEL_PATH):
|
| 494 |
+
st.error(f"❌ FastText model file not found: {FASTTEXT_MODEL_PATH}\n\nPlease ensure 'doc_classifier.bin' is in the same directory as streamlit_app.py")
|
| 495 |
+
return None, None
|
| 496 |
model = fasttext.load_model(FASTTEXT_MODEL_PATH)
|
| 497 |
return None, model # FastText doesn't need a tokenizer
|
| 498 |
except FileNotFoundError:
|
| 499 |
+
st.error(f"❌ FastText model file not found: {FASTTEXT_MODEL_PATH}\n\nPlease ensure 'doc_classifier.bin' is in the repository root.")
|
| 500 |
+
return None, None
|
| 501 |
+
except Exception as e:
|
| 502 |
+
st.error(f"❌ Error loading FastText model: {str(e)}\n\nPlease check that the model file is valid.")
|
| 503 |
return None, None
|
| 504 |
else:
|
| 505 |
tokenizer = AutoTokenizer.from_pretrained(model_name)
|