-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Transcription endpoint to Upload Photo implemeneted
- Loading branch information
naheyansheikh
committed
Dec 6, 2024
1 parent
531e6da
commit 2de023b
Showing
10 changed files
with
259 additions
and
21 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -44,5 +44,6 @@ | |
"jest": "^29.7.0", | ||
"react-test-renderer": "^18.3.1", | ||
"vite": "^5.4.1" | ||
} | ||
}, | ||
"proxy": "http://localhost:5000" | ||
} |
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
28 changes: 28 additions & 0 deletions
28
frontend/src/pages/load_transcription/LoadTranscription.css
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,28 @@ | ||
.transcription-container { | ||
padding: 20px; | ||
} | ||
|
||
.transcription-header { | ||
display: flex; | ||
align-items: center; | ||
gap: 16px; | ||
margin-bottom: 20px; | ||
} | ||
|
||
.back-button { | ||
background: none; | ||
border: none; | ||
cursor: pointer; | ||
} | ||
|
||
.back-icon { | ||
width: 24px; | ||
height: 24px; | ||
} | ||
|
||
.transcription-content { | ||
background: white; | ||
padding: 20px; | ||
border-radius: 8px; | ||
white-space: pre-wrap; | ||
} |
30 changes: 30 additions & 0 deletions
30
frontend/src/pages/load_transcription/LoadTranscription.jsx
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,30 @@ | ||
import { useLocation, useNavigate } from "react-router-dom"; | ||
import { NavContentWrapper } from "../../components/NavContentWrapper/NavContentWrapper"; | ||
import { ChevronLeftIcon } from "@heroicons/react/24/solid"; | ||
import "./LoadTranscription.css"; | ||
|
||
export default function LoadTranscription() { | ||
const location = useLocation(); | ||
const navigate = useNavigate(); | ||
const transcription = location.state?.transcription; | ||
|
||
return ( | ||
<NavContentWrapper> | ||
<div className="transcription-container"> | ||
<div className="transcription-header"> | ||
<button | ||
className="back-button" | ||
onClick={() => navigate("/upload-photo")} | ||
> | ||
<ChevronLeftIcon className="back-icon" /> | ||
</button> | ||
<h2>Transcription Result</h2> | ||
</div> | ||
|
||
<div className="transcription-content"> | ||
{transcription || "No transcription data available"} | ||
</div> | ||
</div> | ||
</NavContentWrapper> | ||
); | ||
} |
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,46 @@ | ||
.loading-screen { | ||
display: flex; | ||
flex-direction: column; | ||
align-items: center; | ||
justify-content: center; | ||
height: 100vh; | ||
text-align: center; | ||
} | ||
|
||
.loading-screen h2, h3 { | ||
margin: 5px 0; | ||
color: #333; | ||
} | ||
|
||
.progress-bar-container { | ||
width: 60%; | ||
height: 20px; | ||
border-radius: 30px; | ||
border: 1px solid #244B94; | ||
background-color: #FFFF; | ||
margin: 40px 0; | ||
position: relative; | ||
} | ||
|
||
.progress-bar { | ||
height: 100%; | ||
background: #244B94; | ||
border-radius: 20px; | ||
transition: width 0.3s ease; | ||
} | ||
|
||
.progress-text { | ||
position: absolute; | ||
right: -40px; | ||
top: -2px; | ||
color: #000000; | ||
} | ||
|
||
.cancel-icon { | ||
margin-right: 8px; | ||
font-size: 18px; | ||
} | ||
|
||
.cancel-button:hover { | ||
background: #f5f5f5; | ||
} |
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,85 @@ | ||
import { useEffect, useState } from "react"; | ||
import { useLocation, useNavigate } from "react-router-dom"; | ||
import { CLButtonSecondary } from "../../components/Buttons/CLButtons"; | ||
import "./LoadingScreen.css"; | ||
|
||
export default function LoadingScreen() { | ||
const location = useLocation(); | ||
const navigate = useNavigate(); | ||
const [progress, setProgress] = useState(0); | ||
const imageFile = location.state?.imageFile; | ||
|
||
useEffect(() => { | ||
if (!imageFile) { | ||
navigate("/upload-photo"); | ||
return; | ||
} | ||
|
||
const handleTranscription = async () => { | ||
try { | ||
const formData = new FormData(); | ||
formData.append("image", imageFile); | ||
|
||
// Progress simulation | ||
let currentProgress = 0; | ||
const progressInterval = setInterval(() => { | ||
const increment = Math.random() * 3 + 1; // Random increment between 1-4 | ||
currentProgress = Math.min(currentProgress + increment, 85); | ||
setProgress(Math.round(currentProgress)); | ||
}, 300); | ||
|
||
const response = await fetch("/api/transcribe", { | ||
method: "POST", | ||
body: formData, | ||
}); | ||
|
||
clearInterval(progressInterval); | ||
|
||
const data = await response.json(); | ||
|
||
if (!response.ok) { | ||
throw new Error( | ||
data.error || `HTTP error! status: ${response.status}` | ||
); | ||
} | ||
|
||
// Complete the progress bar | ||
setProgress(100); | ||
|
||
await new Promise((resolve) => setTimeout(resolve, 500)); | ||
|
||
// Navigate to results | ||
navigate("/load-transcription", { | ||
state: { transcription: data.transcription }, | ||
replace: true, | ||
}); | ||
} catch (error) { | ||
console.error("Error during transcription:", error); | ||
alert("Failed to transcribe image: " + error.message); | ||
navigate(-1); | ||
} | ||
}; | ||
|
||
handleTranscription(); | ||
}, [imageFile, navigate]); | ||
|
||
return ( | ||
<div className="loading-screen"> | ||
<h2>Transcribing photos</h2> | ||
<h3>to standardized template...</h3> | ||
|
||
<div className="progress-bar-container"> | ||
<div className="progress-bar" style={{ width: `${progress}%` }} /> | ||
<span className="progress-text">{progress}%</span> | ||
</div> | ||
|
||
<CLButtonSecondary | ||
onClick={() => navigate("/upload-photo")} | ||
width={"250px"} | ||
> | ||
<span className="cancel-icon">×</span> | ||
Cancel Transcription | ||
</CLButtonSecondary> | ||
</div> | ||
); | ||
} |
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