Spaces:
Build error
Build error
Update src/App.js
Browse files- src/App.js +61 -20
src/App.js
CHANGED
|
@@ -1,25 +1,66 @@
|
|
| 1 |
-
import
|
| 2 |
-
import
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 3 |
|
| 4 |
-
function App() {
|
| 5 |
return (
|
| 6 |
-
<div className="
|
| 7 |
-
|
| 8 |
-
|
| 9 |
-
<
|
| 10 |
-
|
| 11 |
-
|
| 12 |
-
|
| 13 |
-
|
| 14 |
-
|
| 15 |
-
|
| 16 |
-
|
| 17 |
-
|
| 18 |
-
|
| 19 |
-
|
| 20 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 21 |
</div>
|
| 22 |
);
|
| 23 |
}
|
| 24 |
-
|
| 25 |
-
export default App;
|
|
|
|
| 1 |
+
import React, { useState } from "react";
|
| 2 |
+
import { askGroq } from "../api/groqClient";
|
| 3 |
+
|
| 4 |
+
const products = [
|
| 5 |
+
{ id: 1, name: "Wireless Headphones", price: "$99" },
|
| 6 |
+
{ id: 2, name: "Smart Watch", price: "$199" },
|
| 7 |
+
{ id: 3, name: "AI Laptop", price: "$1299" },
|
| 8 |
+
];
|
| 9 |
+
|
| 10 |
+
export default function Home() {
|
| 11 |
+
const [query, setQuery] = useState("");
|
| 12 |
+
const [reply, setReply] = useState("");
|
| 13 |
+
|
| 14 |
+
const handleSubmit = async (e) => {
|
| 15 |
+
e.preventDefault();
|
| 16 |
+
const response = await askGroq(query);
|
| 17 |
+
setReply(response);
|
| 18 |
+
};
|
| 19 |
|
|
|
|
| 20 |
return (
|
| 21 |
+
<div className="min-h-screen bg-gray-100">
|
| 22 |
+
{/* Navbar */}
|
| 23 |
+
<nav className="bg-blue-700 text-white px-6 py-4 shadow">
|
| 24 |
+
<h1 className="text-xl font-bold">🛍️ AI Commerce</h1>
|
| 25 |
+
</nav>
|
| 26 |
+
|
| 27 |
+
{/* Product List */}
|
| 28 |
+
<div className="p-6">
|
| 29 |
+
<h2 className="text-2xl font-semibold mb-4">Featured Products</h2>
|
| 30 |
+
<div className="grid md:grid-cols-3 gap-6">
|
| 31 |
+
{products.map((p) => (
|
| 32 |
+
<div key={p.id} className="bg-white p-4 rounded shadow">
|
| 33 |
+
<h3 className="text-lg font-bold">{p.name}</h3>
|
| 34 |
+
<p className="text-gray-600">{p.price}</p>
|
| 35 |
+
<button className="mt-2 px-4 py-1 bg-blue-500 text-white rounded hover:bg-blue-600">
|
| 36 |
+
Buy Now
|
| 37 |
+
</button>
|
| 38 |
+
</div>
|
| 39 |
+
))}
|
| 40 |
+
</div>
|
| 41 |
+
</div>
|
| 42 |
+
|
| 43 |
+
{/* Chatbot */}
|
| 44 |
+
<div className="p-6 bg-white shadow mt-8">
|
| 45 |
+
<h2 className="text-xl font-bold mb-2">🤖 AI Assistant</h2>
|
| 46 |
+
<form onSubmit={handleSubmit} className="flex flex-col md:flex-row gap-4">
|
| 47 |
+
<input
|
| 48 |
+
type="text"
|
| 49 |
+
value={query}
|
| 50 |
+
onChange={(e) => setQuery(e.target.value)}
|
| 51 |
+
placeholder="Ask about recommendation, purchase behavior, or revenue..."
|
| 52 |
+
className="flex-1 border border-gray-300 rounded p-2"
|
| 53 |
+
/>
|
| 54 |
+
<button className="bg-green-600 text-white px-4 py-2 rounded hover:bg-green-700">
|
| 55 |
+
Ask
|
| 56 |
+
</button>
|
| 57 |
+
</form>
|
| 58 |
+
{reply && (
|
| 59 |
+
<div className="mt-4 bg-gray-100 p-3 rounded text-gray-800">
|
| 60 |
+
<strong>AI:</strong> {reply}
|
| 61 |
+
</div>
|
| 62 |
+
)}
|
| 63 |
+
</div>
|
| 64 |
</div>
|
| 65 |
);
|
| 66 |
}
|
|
|
|
|
|