Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,7 +1,7 @@
|
|
| 1 |
import os
|
| 2 |
import sys
|
| 3 |
from flask import Flask, request, jsonify
|
| 4 |
-
from flask_cors import CORS #
|
| 5 |
import numpy as np
|
| 6 |
import json
|
| 7 |
import google.api_core.exceptions
|
|
@@ -19,11 +19,9 @@ load_dotenv()
|
|
| 19 |
app = Flask(__name__)
|
| 20 |
|
| 21 |
# --- CRITICAL FIX: CORS Configuration ---
|
| 22 |
-
#
|
| 23 |
-
#
|
| 24 |
-
|
| 25 |
-
cors_origins = "https://sales-doc.vercel.app" # Your exact Vercel frontend URL
|
| 26 |
-
CORS(app, resources={r"/*": {"origins": cors_origins, "allow_headers": ["Content-Type", "Authorization"]}})
|
| 27 |
|
| 28 |
# --- Global Model Instances ---
|
| 29 |
sales_agent = None
|
|
@@ -61,6 +59,7 @@ except ImportError as e:
|
|
| 61 |
print("Debug Point: Attempting to instantiate sales.Agent (core RL model).")
|
| 62 |
if sales is not None:
|
| 63 |
try:
|
|
|
|
| 64 |
sales_agent = sales.Agent(
|
| 65 |
model_path="https://huggingface.co/DeepMostInnovations/sales-conversion-model-reinf-learning/resolve/main/sales_conversion_model.zip",
|
| 66 |
auto_download=True,
|
|
@@ -95,7 +94,6 @@ if GEMINI_API_KEY:
|
|
| 95 |
print(f"Error Type: {type(e).__name__}")
|
| 96 |
print(f"Error Message: {e}")
|
| 97 |
print("Ensure your GEMINI_API_KEY is correct and has access to Gemini 1.5 Flash.")
|
| 98 |
-
print("This means LLM chat functionality and enriched metrics will not work.")
|
| 99 |
import traceback
|
| 100 |
traceback.print_exc()
|
| 101 |
gemini_model = None
|
|
|
|
| 1 |
import os
|
| 2 |
import sys
|
| 3 |
from flask import Flask, request, jsonify
|
| 4 |
+
from flask_cors import CORS # Ensure Flask-CORS is imported
|
| 5 |
import numpy as np
|
| 6 |
import json
|
| 7 |
import google.api_core.exceptions
|
|
|
|
| 19 |
app = Flask(__name__)
|
| 20 |
|
| 21 |
# --- CRITICAL FIX: CORS Configuration ---
|
| 22 |
+
# This MUST EXACTLY match your Vercel frontend URL, WITHOUT a trailing slash.
|
| 23 |
+
# We explicitly allow Content-Type and Authorization headers for preflight requests.
|
| 24 |
+
CORS(app, resources={r"/*": {"origins": "https://sales-doc.vercel.app", "allow_headers": ["Content-Type", "Authorization"]}})
|
|
|
|
|
|
|
| 25 |
|
| 26 |
# --- Global Model Instances ---
|
| 27 |
sales_agent = None
|
|
|
|
| 59 |
print("Debug Point: Attempting to instantiate sales.Agent (core RL model).")
|
| 60 |
if sales is not None:
|
| 61 |
try:
|
| 62 |
+
# Relying on Dockerfile to make /.deepmost writable
|
| 63 |
sales_agent = sales.Agent(
|
| 64 |
model_path="https://huggingface.co/DeepMostInnovations/sales-conversion-model-reinf-learning/resolve/main/sales_conversion_model.zip",
|
| 65 |
auto_download=True,
|
|
|
|
| 94 |
print(f"Error Type: {type(e).__name__}")
|
| 95 |
print(f"Error Message: {e}")
|
| 96 |
print("Ensure your GEMINI_API_KEY is correct and has access to Gemini 1.5 Flash.")
|
|
|
|
| 97 |
import traceback
|
| 98 |
traceback.print_exc()
|
| 99 |
gemini_model = None
|