made changes to punkt
Browse files- app/main.py +14 -3
- spaces_app.py +3 -1
app/main.py
CHANGED
@@ -439,10 +439,21 @@ async def startup_event():
|
|
439 |
# Download NLTK data
|
440 |
logger.info("Downloading NLTK data...")
|
441 |
try:
|
442 |
-
|
443 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
444 |
except Exception as e:
|
445 |
-
logger.error(f"Error
|
446 |
raise Exception(f"Failed to initialize application: {str(e)}")
|
447 |
|
448 |
# Initialize the model and index
|
|
|
439 |
# Download NLTK data
|
440 |
logger.info("Downloading NLTK data...")
|
441 |
try:
|
442 |
+
# Check if punkt is already downloaded
|
443 |
+
import nltk.data
|
444 |
+
try:
|
445 |
+
nltk.data.find('tokenizers/punkt', paths=[nltk_data_dir])
|
446 |
+
logger.info("NLTK punkt already downloaded")
|
447 |
+
except LookupError:
|
448 |
+
await asyncio.to_thread(nltk.download, 'punkt', download_dir=nltk_data_dir, quiet=True)
|
449 |
+
|
450 |
+
try:
|
451 |
+
nltk.data.find('tokenizers/punkt_tab', paths=[nltk_data_dir])
|
452 |
+
logger.info("NLTK punkt_tab already downloaded")
|
453 |
+
except LookupError:
|
454 |
+
await asyncio.to_thread(nltk.download, 'punkt_tab', download_dir=nltk_data_dir, quiet=True)
|
455 |
except Exception as e:
|
456 |
+
logger.error(f"Error handling NLTK data: {str(e)}")
|
457 |
raise Exception(f"Failed to initialize application: {str(e)}")
|
458 |
|
459 |
# Initialize the model and index
|
spaces_app.py
CHANGED
@@ -22,7 +22,9 @@ logger = logging.getLogger(__name__)
|
|
22 |
|
23 |
# Initialize the FastAPI app in a separate thread
|
24 |
def start_fastapi():
|
25 |
-
|
|
|
|
|
26 |
|
27 |
# Start FastAPI in a separate thread
|
28 |
thread = Thread(target=start_fastapi, daemon=True)
|
|
|
22 |
|
23 |
# Initialize the FastAPI app in a separate thread
|
24 |
def start_fastapi():
|
25 |
+
# Don't run startup event here, as we'll run it manually
|
26 |
+
# This prevents duplicate initialization
|
27 |
+
uvicorn.run(fastapi_app, host="0.0.0.0", port=8080, lifespan="off")
|
28 |
|
29 |
# Start FastAPI in a separate thread
|
30 |
thread = Thread(target=start_fastapi, daemon=True)
|