-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
291c4e9
commit 5dd3288
Showing
5 changed files
with
106 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,94 @@ | ||
import React, { useState } from "react"; | ||
import axios, { AxiosResponse } from "axios"; | ||
|
||
const OpenAiAnalysis = () => { | ||
const [loading, setLoading] = useState<boolean>(false); | ||
const [errorMessage, setErrorMessage] = useState<string>(""); | ||
const [file, setFile] = useState<any>(); | ||
const [analysisResponse, setAnalysisResponse] = useState<AxiosResponse<any, any>>(); | ||
|
||
const getFile = (event: any) => { | ||
const selectedFile = event.target.files[0]; | ||
if (selectedFile.type !== "application/pdf") { | ||
setErrorMessage("File type must be PDF. Please upload a different file."); | ||
return; | ||
} | ||
|
||
setErrorMessage(""); | ||
setFile(selectedFile); | ||
}; | ||
|
||
const getAnalysis = (event: any) => { | ||
if (!file) { | ||
setErrorMessage("Please upload a PDF file to run analysis."); | ||
return; | ||
} | ||
|
||
setLoading(true); | ||
setErrorMessage(""); | ||
const formData = new FormData(); | ||
formData.append("file", file); | ||
|
||
axios | ||
.post("https://cf-contract-analysis-mvp.azurewebsites.net/api/open-ai/analyze-contract", formData, { | ||
headers: { | ||
"Content-Type": "multipart/form-data", | ||
}, | ||
}) | ||
.then((response) => { | ||
console.log(response); | ||
setAnalysisResponse(response); | ||
setLoading(false); | ||
}) | ||
.catch((error: any) => { | ||
setErrorMessage(`${error.message}. Please try again later.`); | ||
setLoading(false); | ||
}); | ||
}; | ||
|
||
if (loading) { | ||
return ( | ||
<div className="bg-gray-dark min-h-screen flex flex-col items-center text-2xl text-white"> | ||
<h1 className="text-white my-auto">Loading</h1> | ||
</div> | ||
); | ||
} | ||
|
||
return ( | ||
<div className="bg-gray-dark min-h-screen flex flex-col items-center text-2xl text-white"> | ||
<a href="/" className="absolute top-6 left-6 text-sm font-bold underline"> | ||
Return Home | ||
</a> | ||
<h1 className="text-3xl font-bold my-12 text-white">Document Analysis</h1> | ||
<div className="flex flex-row items-center justify-center"> | ||
<div className="mx-auto max-w-xs"> | ||
<input | ||
onChange={getFile} | ||
type="file" | ||
className="block w-full bg-slate-300 rounded-md text-black text-sm file:mr-4 file:rounded-md file:border-0 file:bg-sky-500 file:py-2.5 file:px-4 file:text-sm file:font-semibold file:text-black cursor-pointer hover:file:bg-sky-700 focus:outline-none disabled:pointer-events-none disabled:opacity-60" | ||
/> | ||
</div> | ||
</div> | ||
<button | ||
onClick={getAnalysis} | ||
className="bg-sky-500 rounded p-2 text-sm font-bold text-black my-8 hover:bg-sky-700" | ||
> | ||
Analyze Contract | ||
</button> | ||
{errorMessage !== "" && <p className="text-base text-red-400">{errorMessage}</p>} | ||
{analysisResponse && ( | ||
<> | ||
{analysisResponse.data?.map((result: any, index: number) => { | ||
return ( | ||
<p key={index} className="text-base my-10"> | ||
{result} | ||
</p> | ||
); | ||
})} | ||
</> | ||
)} | ||
</div> | ||
); | ||
}; | ||
|
||
export default OpenAiAnalysis; |