Spaces:
Running
Running
Commit
·
70ce1b2
1
Parent(s):
5e69775
Reduce 1 worker
Browse files
app.py
CHANGED
@@ -17,12 +17,10 @@ The chatbot instructs Gemini Flash to format its answer using markdown.
|
|
17 |
import os
|
18 |
import faiss
|
19 |
import numpy as np
|
20 |
-
import gc
|
21 |
import time
|
22 |
from fastapi import FastAPI
|
23 |
from fastapi.responses import JSONResponse
|
24 |
from pathlib import Path
|
25 |
-
# import requests
|
26 |
import threading
|
27 |
from dotenv import load_dotenv
|
28 |
|
@@ -122,9 +120,9 @@ else:
|
|
122 |
print("✅ Loaded existing QA data from MongoDB.")
|
123 |
# Use an aggregation pipeline with allowDiskUse to sort by "i" without creating an index.
|
124 |
qa_docs = list(qa_collection.aggregate([
|
125 |
-
|
126 |
-
|
127 |
-
|
128 |
qa_data = qa_docs
|
129 |
print("📦 Total QA entries loaded:", len(qa_data))
|
130 |
|
@@ -265,7 +263,7 @@ import uvicorn
|
|
265 |
if __name__ == "__main__":
|
266 |
try:
|
267 |
print("✅ Server is starting...")
|
268 |
-
uvicorn.run(app, host="0.0.0.0", port=7860)
|
269 |
except Exception as e:
|
270 |
print(f"❌ Server startup failed: {e}")
|
271 |
exit(1)
|
|
|
17 |
import os
|
18 |
import faiss
|
19 |
import numpy as np
|
|
|
20 |
import time
|
21 |
from fastapi import FastAPI
|
22 |
from fastapi.responses import JSONResponse
|
23 |
from pathlib import Path
|
|
|
24 |
import threading
|
25 |
from dotenv import load_dotenv
|
26 |
|
|
|
120 |
print("✅ Loaded existing QA data from MongoDB.")
|
121 |
# Use an aggregation pipeline with allowDiskUse to sort by "i" without creating an index.
|
122 |
qa_docs = list(qa_collection.aggregate([
|
123 |
+
{"$sort": {"i": 1}},
|
124 |
+
{"$project": {"_id": 0}}
|
125 |
+
], allowDiskUse=True))
|
126 |
qa_data = qa_docs
|
127 |
print("📦 Total QA entries loaded:", len(qa_data))
|
128 |
|
|
|
263 |
if __name__ == "__main__":
|
264 |
try:
|
265 |
print("✅ Server is starting...")
|
266 |
+
uvicorn.run(app, host="0.0.0.0", port=7860, workers=1) # Default 2 workers, cut to 1
|
267 |
except Exception as e:
|
268 |
print(f"❌ Server startup failed: {e}")
|
269 |
exit(1)
|