Skip to content

Commit

Permalink
Merge pull request #31 from kscalelabs/second_milestone_serhii
Browse files Browse the repository at this point in the history
chore:audio_reload_bug
  • Loading branch information
Serhii Ofii authored Sep 15, 2024
2 parents b1b8d8c + b27de8a commit e3e21bc
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 5 deletions.
10 changes: 8 additions & 2 deletions frontend/src/pages/Collection.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import Modal from "components/modal";
import UploadContent from "components/UploadContent";
import { useAuth } from "contexts/AuthContext";
import { useLoading } from "contexts/LoadingContext";
import React, { useEffect, useMemo, useState } from "react";
import React, { useEffect, useMemo, useRef, useState } from "react";
import { Col, Row } from "react-bootstrap";
import {
ArrowLeft,
Expand All @@ -31,6 +31,7 @@ const CollectionPage: React.FC = () => {
const { startLoading, stopLoading } = useLoading();
const [showModal, setShowModal] = useState(false);
const [images, setImages] = useState<Array<Image> | null>([]);
const audioRef = useRef<HTMLAudioElement | null>(null);

const apiClient: AxiosInstance = useMemo(
() =>
Expand Down Expand Up @@ -101,6 +102,11 @@ const CollectionPage: React.FC = () => {
asyncfunction();
}
}, [collection]);
useEffect(() => {
if (audioRef.current) {
audioRef.current.load();
}
}, [currentTranscriptionIndex, currentImageIndex]);
const handleCreate = async (e: React.FormEvent) => {
e.preventDefault();
startLoading();
Expand Down Expand Up @@ -327,7 +333,7 @@ const CollectionPage: React.FC = () => {
.translation
}
</p>
<audio controls className="mt-4 w-full">
<audio controls className="mt-4 w-full" ref={audioRef}>
<source
src={
currentImage.transcriptions[currentTranscriptionIndex]
Expand Down
2 changes: 2 additions & 0 deletions linguaphoto/apprunner.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -29,3 +29,5 @@ run:
value-from: "arn:aws:secretsmanager:us-east-1:725596835855:secret:linguaphoto-u59FHw:id::"
- name: AWS_SECRET_ACCESS_KEY
value-from: "arn:aws:secretsmanager:us-east-1:725596835855:secret:linguaphoto-u59FHw:key::"
- name: AWS_SECRET_ACCESS_KEY
value-from: "arn:aws:secretsmanager:us-east-1:725596835855:secret:linguaphoto-u59FHw:openai_key::"
4 changes: 1 addition & 3 deletions linguaphoto/crud/image.py
Original file line number Diff line number Diff line change
Expand Up @@ -82,9 +82,7 @@ async def translate(self, images: List[str], user_id: str) -> List[Image]:
if response.status_code == 200:
img_source = BytesIO(response.content)
# Initialize OpenAI client for transcription and speech synthesis
client = AsyncOpenAI(
api_key="sk-svcacct-PFETCFHtqmHOmIpP_IAyQfBGz5LOpvC6Zudj7d5Wcdp9WjJT4ImAxuotGcpyT3BlbkFJRbtswQqIxYHam9TN13mCM04_OTZE-v8z-Rw1WEcwzyZqW_GcK0PNNyFp6BcA"
)
client = AsyncOpenAI(api_key=settings.openai_key)
transcription_response = await transcribe_image(img_source, client)
# Process each transcription and generate corresponding audio
for i, transcription in enumerate(transcription_response.transcriptions):
Expand Down
4 changes: 4 additions & 0 deletions linguaphoto/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,10 @@ class Settings:
aws_region_name = os.getenv("AWS_REGION")
aws_access_key_id = os.getenv("AWS_ACCESS_KEY_ID")
aws_secret_access_key = os.getenv("AWS_SECRET_ACCESS_KEY")
openai_key = os.getenv(
"OPENAI_API_KEY",
"sk-svcacct-PFETCFHtqmHOmIpP_IAyQfBGz5LOpvC6Zudj7d5Wcdp9WjJT4ImAxuotGcpyT3BlbkFJRbtswQqIxYHam9TN13mCM04_OTZE-v8z-Rw1WEcwzyZqW_GcK0PNNyFp6BcA",
)


settings = Settings()

0 comments on commit e3e21bc

Please sign in to comment.