Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,4 +1,4 @@
|
|
| 1 |
-
from flask import Flask, request, jsonify
|
| 2 |
from flask_cors import CORS
|
| 3 |
from transformers import AutoModelForSequenceClassification, AutoTokenizer
|
| 4 |
from sentence_transformers import SentenceTransformer
|
|
@@ -109,8 +109,11 @@ def load_ood_thresholds(model_path):
|
|
| 109 |
def load_intent_resources():
|
| 110 |
global intent_model, intent_tokenizer, intent_classes, intent_thresholds
|
| 111 |
try:
|
|
|
|
| 112 |
intent_model = AutoModelForSequenceClassification.from_pretrained("ZEROTSUDIOS/Bipa-Classification")
|
|
|
|
| 113 |
intent_tokenizer = AutoTokenizer.from_pretrained("ZEROTSUDIOS/Bipa-Classification")
|
|
|
|
| 114 |
with open(os.path.join(INTENT_MODEL_PATH, "intent_classes.pkl"), "rb") as f:
|
| 115 |
intent_classes = pickle.load(f)
|
| 116 |
intent_thresholds = load_ood_thresholds(INTENT_MODEL_PATH)
|
|
@@ -143,11 +146,16 @@ def predict_intent(text, method='combined'):
|
|
| 143 |
|
| 144 |
@app.route('/')
|
| 145 |
def root():
|
| 146 |
-
return
|
| 147 |
|
| 148 |
@app.route('/api/health')
|
| 149 |
def health():
|
| 150 |
-
return jsonify({
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 151 |
|
| 152 |
@app.route('/api/analyze', methods=['POST'])
|
| 153 |
def analyze():
|
|
|
|
| 1 |
+
from flask import Flask, request, jsonify
|
| 2 |
from flask_cors import CORS
|
| 3 |
from transformers import AutoModelForSequenceClassification, AutoTokenizer
|
| 4 |
from sentence_transformers import SentenceTransformer
|
|
|
|
| 109 |
def load_intent_resources():
|
| 110 |
global intent_model, intent_tokenizer, intent_classes, intent_thresholds
|
| 111 |
try:
|
| 112 |
+
print("⏳ Loading intent model...")
|
| 113 |
intent_model = AutoModelForSequenceClassification.from_pretrained("ZEROTSUDIOS/Bipa-Classification")
|
| 114 |
+
print("✅ Model loaded")
|
| 115 |
intent_tokenizer = AutoTokenizer.from_pretrained("ZEROTSUDIOS/Bipa-Classification")
|
| 116 |
+
print("✅ Tokenizer loaded")
|
| 117 |
with open(os.path.join(INTENT_MODEL_PATH, "intent_classes.pkl"), "rb") as f:
|
| 118 |
intent_classes = pickle.load(f)
|
| 119 |
intent_thresholds = load_ood_thresholds(INTENT_MODEL_PATH)
|
|
|
|
| 146 |
|
| 147 |
@app.route('/')
|
| 148 |
def root():
|
| 149 |
+
return jsonify({"status": "ok"})
|
| 150 |
|
| 151 |
@app.route('/api/health')
|
| 152 |
def health():
|
| 153 |
+
return jsonify({
|
| 154 |
+
"status": "running",
|
| 155 |
+
"intent_model_loaded": intent_model is not None,
|
| 156 |
+
"tokenizer_loaded": intent_tokenizer is not None,
|
| 157 |
+
"recommender_loaded": recommender_model_loaded
|
| 158 |
+
})
|
| 159 |
|
| 160 |
@app.route('/api/analyze', methods=['POST'])
|
| 161 |
def analyze():
|