forked from Deepika14145/QuickFactChecker
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapp.py
More file actions
57 lines (46 loc) · 1.93 KB
/
app.py
File metadata and controls
57 lines (46 loc) · 1.93 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
from flask import Flask, request, jsonify, render_template
from flask_cors import CORS
# import joblib # Uncomment if you have the model file
# Serve files from the Public folder
# static_url_path='' means static files are served from root ('/style.css', '/script.js')
app = Flask(__name__, static_folder='Public', template_folder='Public', static_url_path='')
CORS(app) # Enable CORS for all domains
# ------------------------------
# Load the model
# Uncomment if model_pipeline.pkl is available
# model_path = 'model/model_pipeline.pkl'
# model = joblib.load(model_path)
# ------------------------------
@app.route('/')
def index():
return render_template('index.html')
@app.route('/predict', methods=['POST'])
def predict():
try:
# Get JSON data
data = request.get_json(force=True)
if not data or 'text' not in data:
return jsonify({'error': 'Missing or incorrect key "text" in JSON data'}), 400
text = data['text']
# Handle empty or invalid input
if not isinstance(text, str) or not text.strip():
return jsonify({'error': '⚠️ Please enter some text before submitting.'}), 400
# ------------------------------
# Uncomment this once model is available
# prediction = model.predict([text])[0]
# prediction = int(prediction)
# return jsonify({'prediction': prediction})
# ------------------------------
# Temporary placeholder since model is not loaded
return jsonify({'message': 'Text received successfully!'})
except Exception as e:
print(f"Error in /predict: {e}") # Log the error for debugging
return jsonify({'error': 'Internal server error.'}), 500
# ✅ Health check route
@app.route('/health')
def health():
return jsonify({'status': 'ok'}), 200
if __name__ == '__main__':
import os
port = int(os.environ.get('PORT', 5000))
app.run(host='0.0.0.0', port=port, debug=False)