Esteves Enzo commited on
Commit
7faf18e
1 Parent(s): b5624f0
app/api/check-hair-color/route.ts CHANGED
@@ -6,11 +6,12 @@ export async function POST(request: Request) {
6
  const res = await request.formData();
7
  const file = res.get('file');
8
 
 
9
  const classifier: any = await PipelineSingleton.getInstance();
10
  if (!classifier) {
11
  return Response.json({ success: false })
12
  }
13
 
14
- const result = await classifier("https://www.international.gc.ca/world-monde/assets/images/issues_development-enjeux_developpement/gender_equality-egalite_des_genres/jacqueline_oneill.jpg", { topk: 4 });
15
  return Response.json({ data: result })
16
  }
 
6
  const res = await request.formData();
7
  const file = res.get('file');
8
 
9
+
10
  const classifier: any = await PipelineSingleton.getInstance();
11
  if (!classifier) {
12
  return Response.json({ success: false })
13
  }
14
 
15
+ const result = await classifier(file, { topk: 4 });
16
  return Response.json({ data: result })
17
  }
app/layout.tsx CHANGED
@@ -19,7 +19,7 @@ export default function RootLayout({
19
  <html lang="en">
20
  <body className={inter.className}>
21
  <div id="background__noisy" />
22
- <main className="min-h-screen max-w-2xl mx-auto flex-col gap-4 flex relative justify-center">
23
  <Header />
24
  {children}
25
  <div className="absolute -bottom-0 w-full blur-[240px] bg-gradient-to-r h-[300px] from-indigo-600 to-teal-400 rounded-t-full -z-[1]" />
 
19
  <html lang="en">
20
  <body className={inter.className}>
21
  <div id="background__noisy" />
22
+ <main className="min-h-screen max-w-2xl mx-auto flex-col gap-4 flex relative justify-center px-6">
23
  <Header />
24
  {children}
25
  <div className="absolute -bottom-0 w-full blur-[240px] bg-gradient-to-r h-[300px] from-indigo-600 to-teal-400 rounded-t-full -z-[1]" />
app/page.tsx CHANGED
@@ -8,7 +8,7 @@ export default function Home() {
8
  <div className="w-3 h-3 bg-indigo-500 rounded-full" />
9
  <div className="w-3 h-3 bg-teal-500 rounded-full" />
10
  </header>
11
- <main className="flex justify-between gap-6 p-6">
12
  <FormUpload />
13
  </main>
14
  </div>
 
8
  <div className="w-3 h-3 bg-indigo-500 rounded-full" />
9
  <div className="w-3 h-3 bg-teal-500 rounded-full" />
10
  </header>
11
+ <main className="flex flex-col-reverse lg:flex-row justify-between gap-6 p-6">
12
  <FormUpload />
13
  </main>
14
  </div>
components/form/hook.ts CHANGED
@@ -4,10 +4,11 @@ export const useClassifier = () => {
4
  const [results, setResults] = useState([]);
5
  const [loading, setLoading] = useState(false);
6
 
7
- const submit = async (file: File) => {
8
  if (file && !loading) {
9
  setLoading(true);
10
  const formData = new FormData();
 
11
  formData.append("file", file);
12
  const res = await fetch("/api/check-hair-color", {
13
  method: "POST",
 
4
  const [results, setResults] = useState([]);
5
  const [loading, setLoading] = useState(false);
6
 
7
+ const submit = async (file: string) => {
8
  if (file && !loading) {
9
  setLoading(true);
10
  const formData = new FormData();
11
+
12
  formData.append("file", file);
13
  const res = await fetch("/api/check-hair-color", {
14
  method: "POST",
components/form/index.tsx CHANGED
@@ -9,13 +9,15 @@ import { useClassifier } from "./hook";
9
 
10
  export const FormUpload = () => {
11
  const inputRef = useRef<HTMLInputElement>(null);
12
- const [file, setFile] = React.useState<File | null>(null);
13
  const { loading, results, submit } = useClassifier();
14
 
15
  const handleUpload = (e: React.ChangeEvent<HTMLInputElement>) => {
16
  const file = e.target.files?.[0];
17
  if (file) {
18
- setFile(file);
 
 
19
  }
20
  };
21
 
@@ -32,7 +34,7 @@ export const FormUpload = () => {
32
  <div
33
  className="w-full h-full bg-slate-900 mx-auto rounded-xl relative bg-cover bg-center flex items-start justify-end p-3 gap-2"
34
  style={{
35
- backgroundImage: `url(${URL.createObjectURL(file)})`,
36
  }}
37
  >
38
  <div
@@ -57,7 +59,7 @@ export const FormUpload = () => {
57
  </div>
58
  <button
59
  className={classNames(
60
- "text-white rounded-md px-4 text-sm py-2 mt-4 w-full bg-gradient-to-b from-slate-800 to-slate-800/50 shadow-lg transition-all duration-200",
61
  {
62
  "opacity-50 cursor-not-allowed": !file,
63
  "hover:scale-[103%]": file,
@@ -75,7 +77,7 @@ export const FormUpload = () => {
75
  onChange={handleUpload}
76
  />
77
  </div>
78
- <div className="w-[1px] bg-slate-500/30"></div>
79
  {loading ? (
80
  <div className="w-full flex-col flex items-center justify-center">
81
  <p className="text-slate-600 animate-pulse">Loading...</p>
 
9
 
10
  export const FormUpload = () => {
11
  const inputRef = useRef<HTMLInputElement>(null);
12
+ const [file, setFile] = React.useState<string | null>(null);
13
  const { loading, results, submit } = useClassifier();
14
 
15
  const handleUpload = (e: React.ChangeEvent<HTMLInputElement>) => {
16
  const file = e.target.files?.[0];
17
  if (file) {
18
+ const file_url = URL.createObjectURL(file);
19
+
20
+ setFile(file_url);
21
  }
22
  };
23
 
 
34
  <div
35
  className="w-full h-full bg-slate-900 mx-auto rounded-xl relative bg-cover bg-center flex items-start justify-end p-3 gap-2"
36
  style={{
37
+ backgroundImage: `url(${file})`,
38
  }}
39
  >
40
  <div
 
59
  </div>
60
  <button
61
  className={classNames(
62
+ "text-white rounded-lg px-4 text-sm py-2 mt-4 w-full bg-gradient-to-b from-slate-800 to-slate-800/50 shadow-lg transition-all duration-200",
63
  {
64
  "opacity-50 cursor-not-allowed": !file,
65
  "hover:scale-[103%]": file,
 
77
  onChange={handleUpload}
78
  />
79
  </div>
80
+ <div className="hidden lg:block w-[1px] bg-slate-500/30"></div>
81
  {loading ? (
82
  <div className="w-full flex-col flex items-center justify-center">
83
  <p className="text-slate-600 animate-pulse">Loading...</p>
components/header.tsx CHANGED
@@ -4,14 +4,15 @@ import HuggingFaceLogo from "@/assets/hf-logo.svg";
4
 
5
  export const Header = () => {
6
  return (
7
- <nav className="py-4 w-full flex items-center justify-between gap-4">
8
  <Image
9
  src={HuggingFaceLogo}
10
  alt="Hugging Face Logo"
11
  width={50}
12
  height={50}
 
13
  />
14
- <p className="text-xl text-white font-bold lowercase tracking-wider">
15
  What hair color is it?
16
  </p>
17
  </nav>
 
4
 
5
  export const Header = () => {
6
  return (
7
+ <nav className="py-4 w-full flex flex-col lg:flex-row items-center justify-between gap-4">
8
  <Image
9
  src={HuggingFaceLogo}
10
  alt="Hugging Face Logo"
11
  width={50}
12
  height={50}
13
+ className="w-[80px] h-[80px] lg:w-[50px] lg:h-[50px]"
14
  />
15
+ <p className="text-2xl lg:text-xl text-white font-bold tracking-wider">
16
  What hair color is it?
17
  </p>
18
  </nav>