"use client"; import { useState } from "react"; import { FileUpload } from "@/components/FileUpload"; import { PromptInput } from "@/components/PromptInput"; import { ResultDisplay } from "@/components/ResultDisplay"; import { FileIcon, FileText } from "lucide-react"; import { Card, CardContent, CardHeader, CardTitle } from "@/components/ui/card"; export default function Home() { const [schema, setSchema] = useState(null); const [file, setFile] = useState(null); const [result, setResult] = useState(null); const [loading, setLoading] = useState(false); const handleFileSelect = (selectedFile: File) => { setFile(selectedFile); }; const handlePromptSubmit = async (prompt: string) => { try { setLoading(true); // First, get the JSON schema const schemaResponse = await fetch("/api/schema", { method: "POST", headers: { "Content-Type": "application/json", }, body: JSON.stringify({ prompt }), }); const { schema } = await schemaResponse.json(); setSchema(schema); // Then, process the PDF with the schema const formData = new FormData(); formData.append("file", file!); formData.append("schema", JSON.stringify(schema)); const extractResponse = await fetch("/api/extract", { method: "POST", body: formData, }); const data = await extractResponse.json(); setResult(data); } catch (error) { console.error("Error processing request:", error); } finally { setLoading(false); } }; const handleReset = () => { setFile(null); setResult(null); setSchema(null); setLoading(false); }; return (
PDF to Structured Data powered by Google DeepMind Gemini 2.0 Flash {!result && !loading ? ( <> ) : loading ? (
Processing...
) : ( )}
); }