# app.py import os from flask import Flask, render_template, request, jsonify, send_from_directory from graphviz import Digraph import random app = Flask(__name__) # CONFIGURATION UPLOAD_FOLDER = 'static/uploads' DIAGRAM_FOLDER = 'static/diagrams' MODEL_FOLDER = 'static/models' os.makedirs(UPLOAD_FOLDER, exist_ok=True) os.makedirs(DIAGRAM_FOLDER, exist_ok=True) # --- FEATURE 1: AI CODE VISUALIZATION ENGINE --- @app.route('/generate_code_diagram', methods=['POST']) def generate_code_diagram(): """ Takes code/logic text and creates a visual flowchart image. In a real app, you would use an LLM to parse complex code. Here, we simulate the visualization of logic flow. """ data = request.json code_text = data.get('code', '') # Create a visual graph (The "Code Image") dot = Digraph(comment='Code Flow', format='png') dot.attr(rankdir='TB', size='8,5') # Logic to turn text into nodes (Simulated AI parsing) dot.node('A', 'Start: User Input') dot.node('B', 'AI Analysis') dot.node('C', 'Generate 3D Asset') dot.node('D', 'AR Deployment') dot.edge('A', 'B', label='Upload Image') dot.edge('B', 'C', label='Identify Food') dot.edge('C', 'D', label='Render GLB') # Save the diagram filename = f"flow_{random.randint(1000,9999)}" filepath = os.path.join(DIAGRAM_FOLDER, filename) dot.render(filepath) return jsonify({'diagram_url': f"/{filepath}.png"}) # --- FEATURE 2: AI FOOD ANALYSIS & 3D SELECTOR --- @app.route('/analyze_food', methods=['POST']) def analyze_food(): """ 1. Receives food image. 2. 'AI' identifies it (Simulated for this demo). 3. Returns the correct 3D model file for the table. """ if 'image' not in request.files: return jsonify({'error': 'No image uploaded'}), 400 file = request.files['image'] # Save file logic here... # MOCK AI RECOGNITION LOGIC # In a real app, use TensorFlow/YOLO here to detect "Pizza" or "Burger" # For demo, we randomly detect one to show the switching capability. detected_food = random.choice(['burger', 'pizza']) response_data = { 'food_detected': detected_food, 'confidence': '98%', 'model_url': f"/static/models/{detected_food}.glb", # Returns the 3D file path 'calories': '450 kcal' } return jsonify(response_data) # --- FEATURE 3: AI GUIDE CHAT --- @app.route('/chat_guide', methods=['POST']) def chat_guide(): user_msg = request.json.get('message', '').lower() if "price" in user_msg: reply = "This dish costs $12.99 based on the portion size shown." elif "spicy" in user_msg: reply = "This dish is rated 2/5 on the spice scale." else: reply = "I am your MenuVision Assistant. Upload a photo to see it in 3D on your table!" return jsonify({'reply': reply}) @app.route('/') def index(): return render_template('index.html') if __name__ == '__main__': # Run on 0.0.0.0 so you can access it from your phone app.run(host='0.0.0.0', port=5000, debug=True)