Spaces:
Configuration error
Configuration error
Rename app.py to app2.py
Browse files- app.py → app2.py +19 -6
app.py → app2.py
RENAMED
|
@@ -24,8 +24,15 @@ def get_model_prediction(title, keywords, subheadings):
|
|
| 24 |
'keywords': keywords,
|
| 25 |
'subheadings': subheadings
|
| 26 |
}
|
| 27 |
-
|
| 28 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 29 |
|
| 30 |
@app.route('/predict', methods=['POST'])
|
| 31 |
def predict():
|
|
@@ -34,15 +41,22 @@ def predict():
|
|
| 34 |
keywords = data.get('keywords')
|
| 35 |
subheadings = data.get('subheadings')
|
| 36 |
|
|
|
|
|
|
|
|
|
|
|
|
|
| 37 |
# MongoDB'den ilgili verileri çekme
|
| 38 |
query = {
|
| 39 |
'title': title,
|
| 40 |
'keywords': {'$in': keywords.split(',')},
|
| 41 |
'subheadings': {'$in': subheadings.split(',')}
|
| 42 |
}
|
| 43 |
-
|
| 44 |
-
|
| 45 |
-
|
|
|
|
|
|
|
|
|
|
| 46 |
predictions = []
|
| 47 |
for doc in documents:
|
| 48 |
result = get_model_prediction(doc['title'], doc['keywords'], doc['subheadings'])
|
|
@@ -60,4 +74,3 @@ def predict():
|
|
| 60 |
|
| 61 |
if __name__ == "__main__":
|
| 62 |
app.run(host='0.0.0.0', port=8080)
|
| 63 |
-
|
|
|
|
| 24 |
'keywords': keywords,
|
| 25 |
'subheadings': subheadings
|
| 26 |
}
|
| 27 |
+
try:
|
| 28 |
+
response = requests.post(MODEL_API_URL, headers=headers, json=payload)
|
| 29 |
+
response.raise_for_status() # HTTP hatalarını yakalar
|
| 30 |
+
result = response.json()
|
| 31 |
+
return result
|
| 32 |
+
except requests.exceptions.HTTPError as http_err:
|
| 33 |
+
return {'error': f'HTTP error occurred: {http_err}'}
|
| 34 |
+
except Exception as err:
|
| 35 |
+
return {'error': f'Other error occurred: {err}'}
|
| 36 |
|
| 37 |
@app.route('/predict', methods=['POST'])
|
| 38 |
def predict():
|
|
|
|
| 41 |
keywords = data.get('keywords')
|
| 42 |
subheadings = data.get('subheadings')
|
| 43 |
|
| 44 |
+
# Giriş verilerini doğrulama
|
| 45 |
+
if not title or not keywords or not subheadings:
|
| 46 |
+
return jsonify({'error': 'Title, keywords, and subheadings are required'}), 400
|
| 47 |
+
|
| 48 |
# MongoDB'den ilgili verileri çekme
|
| 49 |
query = {
|
| 50 |
'title': title,
|
| 51 |
'keywords': {'$in': keywords.split(',')},
|
| 52 |
'subheadings': {'$in': subheadings.split(',')}
|
| 53 |
}
|
| 54 |
+
try:
|
| 55 |
+
documents = list(collection.find(query))
|
| 56 |
+
except Exception as e:
|
| 57 |
+
return jsonify({'error': f'Error querying MongoDB: {e}'}), 500
|
| 58 |
+
|
| 59 |
+
# Model API'den tahmin alma
|
| 60 |
predictions = []
|
| 61 |
for doc in documents:
|
| 62 |
result = get_model_prediction(doc['title'], doc['keywords'], doc['subheadings'])
|
|
|
|
| 74 |
|
| 75 |
if __name__ == "__main__":
|
| 76 |
app.run(host='0.0.0.0', port=8080)
|
|
|