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 sentence_transformers import SentenceTransformer
|
| 4 |
from pinecone import Pinecone
|
|
@@ -335,6 +335,7 @@ def semantic_search(query: str, top_k=1, category_filter=None, language='en'):
|
|
| 335 |
"summary": summary,
|
| 336 |
"costLKR": costLKR,
|
| 337 |
"category": category,
|
|
|
|
| 338 |
"pdfUrl": f"assets/pdfs/{file_path}" if file_path else "",
|
| 339 |
"thumbUrl": f"assets/thumbs/{thumb_url}" if thumb_url else "",
|
| 340 |
"score": score,
|
|
@@ -393,6 +394,7 @@ def get_all_proposals(category_filter=None, language='en'):
|
|
| 393 |
"summary": summary,
|
| 394 |
"costLKR": costLKR,
|
| 395 |
"category": category,
|
|
|
|
| 396 |
"pdfUrl": f"assets/pdfs/{file_path}" if file_path else "",
|
| 397 |
"thumbUrl": f"assets/thumbs/{thumb_url}" if thumb_url else "",
|
| 398 |
"score": 1.0, # Default score for all proposals
|
|
@@ -560,6 +562,21 @@ def get_stats():
|
|
| 560 |
except Exception as e:
|
| 561 |
return jsonify({"error": str(e)}), 500
|
| 562 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 563 |
@app.route('/', methods=['GET'])
|
| 564 |
def home():
|
| 565 |
"""Home endpoint with API documentation"""
|
|
|
|
| 1 |
+
from flask import Flask, request, jsonify, send_from_directory
|
| 2 |
from flask_cors import CORS
|
| 3 |
from sentence_transformers import SentenceTransformer
|
| 4 |
from pinecone import Pinecone
|
|
|
|
| 335 |
"summary": summary,
|
| 336 |
"costLKR": costLKR,
|
| 337 |
"category": category,
|
| 338 |
+
"badge": proposal_data.get("badge", ""), # Add badge field
|
| 339 |
"pdfUrl": f"assets/pdfs/{file_path}" if file_path else "",
|
| 340 |
"thumbUrl": f"assets/thumbs/{thumb_url}" if thumb_url else "",
|
| 341 |
"score": score,
|
|
|
|
| 394 |
"summary": summary,
|
| 395 |
"costLKR": costLKR,
|
| 396 |
"category": category,
|
| 397 |
+
"badge": proposal_data.get("badge", ""), # Add badge field
|
| 398 |
"pdfUrl": f"assets/pdfs/{file_path}" if file_path else "",
|
| 399 |
"thumbUrl": f"assets/thumbs/{thumb_url}" if thumb_url else "",
|
| 400 |
"score": 1.0, # Default score for all proposals
|
|
|
|
| 562 |
except Exception as e:
|
| 563 |
return jsonify({"error": str(e)}), 500
|
| 564 |
|
| 565 |
+
@app.route('/assets/<path:filename>')
|
| 566 |
+
def serve_assets(filename):
|
| 567 |
+
"""Serve static assets like badge images"""
|
| 568 |
+
try:
|
| 569 |
+
# Check if the file exists in the Budget_Proposals copy-2/assets directory
|
| 570 |
+
assets_dir = os.path.join("Budget_Proposals copy-2", "assets")
|
| 571 |
+
if os.path.exists(os.path.join(assets_dir, filename)):
|
| 572 |
+
return send_from_directory(assets_dir, filename)
|
| 573 |
+
else:
|
| 574 |
+
# Fallback to current directory assets
|
| 575 |
+
return send_from_directory("assets", filename)
|
| 576 |
+
except Exception as e:
|
| 577 |
+
logger.error(f"Error serving asset {filename}: {e}")
|
| 578 |
+
return jsonify({"error": f"Asset not found: {filename}"}), 404
|
| 579 |
+
|
| 580 |
@app.route('/', methods=['GET'])
|
| 581 |
def home():
|
| 582 |
"""Home endpoint with API documentation"""
|