Wall06 commited on
Commit
42679ea
·
verified ·
1 Parent(s): b435483

Create templates/index.html

Browse files
Files changed (1) hide show
  1. templates/index.html +138 -0
templates/index.html ADDED
@@ -0,0 +1,138 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <!DOCTYPE html>
2
+ <html lang="en">
3
+ <head>
4
+ <meta charset="UTF-8">
5
+ <meta name="viewport" content="width=device-width, initial-scale=1.0">
6
+ <title>MenuVision AI</title>
7
+ <script type="module" src="https://ajax.googleapis.com/ajax/libs/model-viewer/3.4.0/model-viewer.min.js"></script>
8
+ <script src="https://cdn.tailwindcss.com"></script>
9
+
10
+ <style>
11
+ body { background-color: #1a1a2e; color: white; font-family: sans-serif; }
12
+ .ar-window { height: 500px; width: 100%; background: #fff; border-radius: 15px; overflow: hidden; }
13
+ /* AR Button Style */
14
+ #ar-button {
15
+ background: linear-gradient(90deg, #ff4b1f, #ff9068);
16
+ color: white; border: none; padding: 10px 20px; border-radius: 30px;
17
+ position: absolute; bottom: 20px; left: 50%; transform: translateX(-50%);
18
+ font-weight: bold; cursor: pointer; z-index: 100;
19
+ }
20
+ </style>
21
+ </head>
22
+ <body class="p-4">
23
+
24
+ <header class="text-center mb-8">
25
+ <h1 class="text-4xl font-bold text-transparent bg-clip-text bg-gradient-to-r from-blue-400 to-pink-600">
26
+ MenuVision AI
27
+ </h1>
28
+ <p class="text-gray-400">Real-world 3D Food & Code Visualization</p>
29
+ </header>
30
+
31
+ <div class="max-w-md mx-auto bg-gray-800 p-4 rounded-xl mb-8 shadow-2xl border border-gray-700">
32
+ <h2 class="text-xl font-bold mb-4">🍕 3D Food on Table</h2>
33
+
34
+ <div class="mb-4">
35
+ <label class="block text-sm text-gray-400 mb-2">Upload Food Image to Analyze:</label>
36
+ <input type="file" id="foodInput" class="block w-full text-sm text-gray-400 file:mr-4 file:py-2 file:px-4 file:rounded-full file:border-0 file:bg-blue-600 file:text-white">
37
+ </div>
38
+
39
+ <div class="ar-window relative">
40
+ <model-viewer
41
+ id="food-viewer"
42
+ src="/static/models/default.glb"
43
+ alt="3D Food"
44
+ ar
45
+ ar-modes="webxr scene-viewer quick-look"
46
+ camera-controls
47
+ auto-rotate
48
+ shadow-intensity="1"
49
+ scale="0.5 0.5 0.5"> <button slot="ar-button" id="ar-button">
50
+ 👋 Place on Real Table
51
+ </button>
52
+ </model-viewer>
53
+ </div>
54
+ <div id="food-stats" class="mt-2 text-center text-green-400 font-mono hidden">
55
+ Analyzing...
56
+ </div>
57
+ </div>
58
+
59
+ <div class="max-w-md mx-auto bg-gray-800 p-4 rounded-xl mb-8 border border-gray-700">
60
+ <h2 class="text-xl font-bold mb-4">🧠 AI Code Visualizer</h2>
61
+ <textarea id="codeInput" class="w-full p-2 bg-gray-900 rounded h-24 text-xs font-mono" placeholder="Paste python code logic here..."></textarea>
62
+ <button onclick="generateDiagram()" class="w-full bg-blue-600 mt-2 py-2 rounded hover:bg-blue-500">Generate Visual Diagram</button>
63
+
64
+ <div id="diagramResult" class="mt-4 text-center">
65
+ </div>
66
+ </div>
67
+
68
+ <div class="max-w-md mx-auto bg-gray-800 p-4 rounded-xl border border-gray-700">
69
+ <h2 class="text-xl font-bold mb-2">💬 AI Guide</h2>
70
+ <div id="chatHistory" class="h-20 overflow-y-auto mb-2 text-sm text-gray-300"></div>
71
+ <div class="flex">
72
+ <input type="text" id="chatInput" class="flex-1 p-2 bg-gray-900 rounded-l" placeholder="Ask about the food...">
73
+ <button onclick="sendChat()" class="bg-green-600 px-4 rounded-r">Send</button>
74
+ </div>
75
+ </div>
76
+
77
+ <script>
78
+ // --- 1. HANDLE FOOD UPLOAD & AR SWITCHING ---
79
+ const foodInput = document.getElementById('foodInput');
80
+ const viewer = document.getElementById('food-viewer');
81
+ const stats = document.getElementById('food-stats');
82
+
83
+ foodInput.addEventListener('change', async (e) => {
84
+ const file = e.target.files[0];
85
+ if (!file) return;
86
+
87
+ stats.classList.remove('hidden');
88
+ stats.innerText = "🔍 AI Analyzing Food Structure...";
89
+
90
+ const formData = new FormData();
91
+ formData.append('image', file);
92
+
93
+ // Send to Backend
94
+ const response = await fetch('/analyze_food', { method: 'POST', body: formData });
95
+ const data = await response.json();
96
+
97
+ // Update UI with AI results
98
+ stats.innerText = `✅ Detected: ${data.food_detected.toUpperCase()} (Confidence: ${data.confidence})`;
99
+
100
+ // SWAP THE 3D MODEL
101
+ // This is the key: The AR model changes based on the "AI" analysis
102
+ viewer.src = data.model_url;
103
+ });
104
+
105
+ // --- 2. HANDLE CODE DIAGRAM GENERATION ---
106
+ async function generateDiagram() {
107
+ const code = document.getElementById('codeInput').value;
108
+ const res = await fetch('/generate_code_diagram', {
109
+ method: 'POST',
110
+ headers: {'Content-Type': 'application/json'},
111
+ body: JSON.stringify({ code: code })
112
+ });
113
+ const data = await res.json();
114
+
115
+ const imgHtml = `<img src="${data.diagram_url}" class="w-full rounded border border-blue-500" alt="Code Flow">`;
116
+ document.getElementById('diagramResult').innerHTML = imgHtml;
117
+ }
118
+
119
+ // --- 3. HANDLE CHAT ---
120
+ async function sendChat() {
121
+ const input = document.getElementById('chatInput');
122
+ const history = document.getElementById('chatHistory');
123
+ const msg = input.value;
124
+
125
+ history.innerHTML += `<div>You: ${msg}</div>`;
126
+ input.value = "";
127
+
128
+ const res = await fetch('/chat_guide', {
129
+ method: 'POST',
130
+ headers: {'Content-Type': 'application/json'},
131
+ body: JSON.stringify({ message: msg })
132
+ });
133
+ const data = await res.json();
134
+ history.innerHTML += `<div class="text-green-400">AI: ${data.reply}</div>`;
135
+ }
136
+ </script>
137
+ </body>
138
+ </html>