Afeefa123 commited on
Commit
f863162
·
verified ·
1 Parent(s): 5ecbdf1

Update src/App.js

Browse files
Files changed (1) hide show
  1. 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
- 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
  }
 
 
 
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;