Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -25,13 +25,18 @@ load_dotenv()
|
|
| 25 |
|
| 26 |
app = Flask(__name__)
|
| 27 |
app.secret_key = os.getenv("SECRET_KEY", "default_secret_key")
|
| 28 |
-
|
| 29 |
-
app.config['
|
|
|
|
| 30 |
|
| 31 |
# Faiss Configuration
|
| 32 |
-
FAISS_INDEX_DIR = "faiss_indices"
|
| 33 |
EMBEDDING_DIM = 768 # all-mpnet-base-v2 embedding dimension
|
| 34 |
|
|
|
|
|
|
|
|
|
|
|
|
|
| 35 |
# Chunking Configuration
|
| 36 |
CHUNK_SIZE = 1000
|
| 37 |
CHUNK_OVERLAP = 200
|
|
@@ -44,7 +49,9 @@ model = AutoModel.from_pretrained("sentence-transformers/all-mpnet-base-v2")
|
|
| 44 |
# Initialize Mistral client directly (like test.py)
|
| 45 |
from mistralai import Mistral
|
| 46 |
|
| 47 |
-
mistral_api_key = "
|
|
|
|
|
|
|
| 48 |
mistral_client = Mistral(api_key=mistral_api_key)
|
| 49 |
|
| 50 |
# API throttling configuration
|
|
@@ -892,4 +899,5 @@ def download_saved_pdf():
|
|
| 892 |
if __name__ == '__main__':
|
| 893 |
os.makedirs(app.config['UPLOAD_FOLDER'], exist_ok=True)
|
| 894 |
os.makedirs(FAISS_INDEX_DIR, exist_ok=True)
|
| 895 |
-
|
|
|
|
|
|
| 25 |
|
| 26 |
app = Flask(__name__)
|
| 27 |
app.secret_key = os.getenv("SECRET_KEY", "default_secret_key")
|
| 28 |
+
APP_ROOT = os.path.abspath(os.path.dirname(__file__))
|
| 29 |
+
app.config['UPLOAD_FOLDER'] = os.path.join(APP_ROOT, 'uploads')
|
| 30 |
+
app.config['MAX_CONTENT_LENGTH'] = 50 * 1024 * 1024 # 50MB limit
|
| 31 |
|
| 32 |
# Faiss Configuration
|
| 33 |
+
FAISS_INDEX_DIR = os.path.join(APP_ROOT, "faiss_indices")
|
| 34 |
EMBEDDING_DIM = 768 # all-mpnet-base-v2 embedding dimension
|
| 35 |
|
| 36 |
+
# Ensure writable directories exist when running under gunicorn
|
| 37 |
+
os.makedirs(app.config['UPLOAD_FOLDER'], exist_ok=True)
|
| 38 |
+
os.makedirs(FAISS_INDEX_DIR, exist_ok=True)
|
| 39 |
+
|
| 40 |
# Chunking Configuration
|
| 41 |
CHUNK_SIZE = 1000
|
| 42 |
CHUNK_OVERLAP = 200
|
|
|
|
| 49 |
# Initialize Mistral client directly (like test.py)
|
| 50 |
from mistralai import Mistral
|
| 51 |
|
| 52 |
+
mistral_api_key = os.getenv("MISTRAL_API_KEY", "")
|
| 53 |
+
if not mistral_api_key:
|
| 54 |
+
raise RuntimeError("MISTRAL_API_KEY not set. Please configure it as an environment variable.")
|
| 55 |
mistral_client = Mistral(api_key=mistral_api_key)
|
| 56 |
|
| 57 |
# API throttling configuration
|
|
|
|
| 899 |
if __name__ == '__main__':
|
| 900 |
os.makedirs(app.config['UPLOAD_FOLDER'], exist_ok=True)
|
| 901 |
os.makedirs(FAISS_INDEX_DIR, exist_ok=True)
|
| 902 |
+
port = int(os.getenv("PORT", "7860"))
|
| 903 |
+
app.run(host="0.0.0.0", port=port, debug=True)
|