first commit
This commit is contained in:
@@ -0,0 +1,53 @@
|
|||||||
|
from flask import Flask, request, jsonify, render_template
|
||||||
|
|
||||||
|
app = Flask(__name__)
|
||||||
|
|
||||||
|
@app.route('/product-recommendation', methods=['POST'])
|
||||||
|
def product_recommendation():
|
||||||
|
"""
|
||||||
|
Endpoint for product recommendations based on natural language queries.
|
||||||
|
Input: Form data containing 'query' (string).
|
||||||
|
Output: JSON with 'products' (array of objects) and 'response' (string).
|
||||||
|
"""
|
||||||
|
query = request.form.get('query', '')
|
||||||
|
# Process the query to find matching products
|
||||||
|
products = [] # Empty array, to be populated with product data
|
||||||
|
response = "" # Empty string, to be filled with a natural language response
|
||||||
|
return jsonify({"products": products, "response": response})
|
||||||
|
|
||||||
|
@app.route('/ocr-query', methods=['POST'])
|
||||||
|
def ocr_query():
|
||||||
|
"""
|
||||||
|
Endpoint to process handwritten queries extracted from uploaded images.
|
||||||
|
Input: Form data containing 'image_data' (file, base64-encoded image or direct file upload).
|
||||||
|
Output: JSON with 'products' (array of objects) and 'response' (string).
|
||||||
|
"""
|
||||||
|
image_file = request.files.get('image_data')
|
||||||
|
# Process the image to extract text and find matching products
|
||||||
|
products = [] # Empty array, to be populated with product data
|
||||||
|
response = "" # Empty string, to be filled with a natural language response
|
||||||
|
return jsonify({"products": products, "response": response})
|
||||||
|
|
||||||
|
@app.route('/image-product-search', methods=['POST'])
|
||||||
|
def image_product_search():
|
||||||
|
"""
|
||||||
|
Endpoint to identify and suggest products from uploaded product images.
|
||||||
|
Input: Form data containing 'product_image' (file, base64-encoded image or direct file upload).
|
||||||
|
Output: JSON with 'products' (array of objects) and 'response' (string).
|
||||||
|
"""
|
||||||
|
product_image = request.files.get('product_image')
|
||||||
|
# Process the product image to detect and match products
|
||||||
|
products = [] # Empty array, to be populated with product data
|
||||||
|
response = "" # Empty string, to be filled with a natural language response
|
||||||
|
return jsonify({"products": products, "response": response})
|
||||||
|
|
||||||
|
@app.route('/sample_response', methods=['GET'])
|
||||||
|
def sample_response():
|
||||||
|
"""
|
||||||
|
Endpoint to return a sample JSON response for the API.
|
||||||
|
Output: JSON with 'products' (array of objects) and 'response' (string).
|
||||||
|
"""
|
||||||
|
return render_template('sample_response.html')
|
||||||
|
|
||||||
|
if __name__ == '__main__':
|
||||||
|
app.run(debug=True)
|
||||||
Binary file not shown.
@@ -0,0 +1 @@
|
|||||||
|
flask
|
||||||
@@ -0,0 +1,86 @@
|
|||||||
|
<!DOCTYPE html>
|
||||||
|
<html lang="en">
|
||||||
|
<head>
|
||||||
|
<meta charset="UTF-8">
|
||||||
|
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||||
|
<title>Product Recommendations</title>
|
||||||
|
<style>
|
||||||
|
body {
|
||||||
|
font-family: Arial, sans-serif;
|
||||||
|
background-color: #f4f4f4;
|
||||||
|
margin: 0;
|
||||||
|
padding: 0;
|
||||||
|
}
|
||||||
|
.container {
|
||||||
|
width: 80%;
|
||||||
|
margin: 20px auto;
|
||||||
|
background: #fff;
|
||||||
|
padding: 20px;
|
||||||
|
box-shadow: 0 2px 4px rgba(0,0,0,0.1);
|
||||||
|
}
|
||||||
|
table {
|
||||||
|
width: 100%;
|
||||||
|
border-collapse: collapse;
|
||||||
|
margin-top: 20px;
|
||||||
|
}
|
||||||
|
th, td {
|
||||||
|
border: 1px solid #ddd;
|
||||||
|
padding: 8px;
|
||||||
|
text-align: left;
|
||||||
|
}
|
||||||
|
th {
|
||||||
|
background-color: #f2f2f2;
|
||||||
|
}
|
||||||
|
</style>
|
||||||
|
</head>
|
||||||
|
<body>
|
||||||
|
<div class="container">
|
||||||
|
<h1>Answer In Natural Language</h1>
|
||||||
|
<p>Experience exceptional sound with our High-Quality Headphones, featuring advanced noise cancellation and a comfortable over-ear design, perfect for any audio enthusiast. Streamline your workspace with our Ergonomic Wireless Mouse, designed to reduce wrist strain and improve precision without the clutter of wires. Enjoy barista-level espresso at home with our Compact Espresso Machine, which combines sleek design with quick and easy operation. Stay healthy and connected with our Smart Fitness Tracker, ideal for monitoring activity levels and health metrics efficiently. Illuminate any setting with our Ultra-Bright LED Torch, providing powerful lighting solutions for outdoor enthusiasts and emergency preparedness alike</p>
|
||||||
|
|
||||||
|
<h1>Selected Products</h1>
|
||||||
|
<table>
|
||||||
|
<thead>
|
||||||
|
<tr>
|
||||||
|
<th>Stock Code</th>
|
||||||
|
<th>Description</th>
|
||||||
|
<th>Unit Price</th>
|
||||||
|
<th>Country</th>
|
||||||
|
</tr>
|
||||||
|
</thead>
|
||||||
|
<tbody>
|
||||||
|
<tr>
|
||||||
|
<td>001</td>
|
||||||
|
<td>High-Quality Headphones</td>
|
||||||
|
<td>$50.00</td>
|
||||||
|
<td>USA</td>
|
||||||
|
</tr>
|
||||||
|
<tr>
|
||||||
|
<td>002</td>
|
||||||
|
<td>Ergonomic Wireless Mouse</td>
|
||||||
|
<td>$20.00</td>
|
||||||
|
<td>Canada</td>
|
||||||
|
</tr>
|
||||||
|
<tr>
|
||||||
|
<td>003</td>
|
||||||
|
<td>Compact Espresso Machine</td>
|
||||||
|
<td>$100.00</td>
|
||||||
|
<td>United Kingdom</td>
|
||||||
|
</tr>
|
||||||
|
<tr>
|
||||||
|
<td>004</td>
|
||||||
|
<td>Smart Fitness Tracker</td>
|
||||||
|
<td>$30.00</td>
|
||||||
|
<td>Australia</td>
|
||||||
|
</tr>
|
||||||
|
<tr>
|
||||||
|
<td>005</td>
|
||||||
|
<td>Ultra-Bright LED Torch</td>
|
||||||
|
<td>$25.00</td>
|
||||||
|
<td>New Zealand</td>
|
||||||
|
</tr>
|
||||||
|
</tbody>
|
||||||
|
</table>
|
||||||
|
</div>
|
||||||
|
</body>
|
||||||
|
</html>
|
||||||
Reference in New Issue
Block a user