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