Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Return data to client #10

Open
dahifi opened this issue Jan 29, 2024 · 1 comment
Open

Return data to client #10

dahifi opened this issue Jan 29, 2024 · 1 comment

Comments

@dahifi
Copy link
Contributor

dahifi commented Jan 29, 2024

For returning the processed data to a React frontend application, especially when dealing with asynchronous operations like audio processing and ASR transcription, you can consider the following approach:

Overview

  1. Frontend Upload: The React application uploads the audio file to Google Cloud Storage using signed URLs, ensuring secure and temporary access for the upload operation.

  2. Backend Processing: After the audio file is processed through your pipeline (ASR, parsing, transcription, CSV generation, and summarization), the resulting data needs to be made accessible to the React application.

  3. Data Retrieval: The frontend periodically polls or listens for a notification indicating the completion of the processing, and then fetches the results.

Detailed Approach

Step 1: Frontend Upload

  • The React application obtains a signed URL from a backend service (e.g., a Cloud Function or an App Engine service).
  • The user uploads the audio file directly to the specified Google Cloud Storage bucket using the signed URL.

Step 2: Backend Processing

  • The processing workflow is triggered as discussed previously, resulting in various output files (transcription, CSV, summary) stored in Cloud Storage.

Step 3: Data Retrieval Options

You have multiple options for notifying the frontend and allowing the user to retrieve the processed data:

  1. Polling:

    • The frontend periodically sends requests to a backend service to check the status of the processing.
    • Once the processing is complete, the backend service provides URLs to access the processed data, which can be secured with signed URLs for temporary access.
  2. Push Notifications with Cloud Pub/Sub and Firebase Cloud Messaging (FCM):

    • Utilize Cloud Pub/Sub to publish processing completion messages.
    • A backend service subscribes to the Pub/Sub topic and uses Firebase Cloud Messaging to push notifications to the React application.
    • Upon receiving a notification, the frontend fetches the processed data from the provided URLs.
  3. WebSocket Connection:

    • Establish a WebSocket connection between the frontend and a backend service.
    • The backend service sends real-time updates to the frontend about the processing status and results.
    • This approach provides a more interactive experience but requires maintaining a persistent connection.
  4. Using Firestore as a Real-time Database:

    • Store the processing status and results URLs in a Firestore document.
    • The React application listens to changes on this document using Firestore's real-time capabilities.
    • When the document updates upon processing completion, the frontend automatically receives the new data and fetches the results.

Security Considerations

  • Ensure that access to the processed data is secured, preferably using signed URLs for Cloud Storage objects, which provide temporary access to the files.
  • Implement proper authentication and authorization mechanisms to ensure that users can only access their data.

Example: Using Polling and Signed URLs

Backend Service (Cloud Function or App Engine)

  • Provides an endpoint for the React app to check the processing status.
  • Once processing is complete, it generates signed URLs for accessing the output files and returns them to the frontend.

Frontend Polling Logic

const checkProcessingStatus = async () => {
  const response = await fetch('/api/check-status');
  const data = await response.json();

  if (data.status === 'completed') {
    // Processing is complete, access the data using the provided signed URLs
    const transcriptionUrl = data.urls.transcription;
    const csvUrl = data.urls.csv;
    // Fetch the transcription and CSV using the signed URLs
    // Update the UI accordingly
  } else {
    // Continue polling if processing is not yet complete
    setTimeout(checkProcessingStatus, 5000); // Poll every 5 seconds
  }
};

// Start polling
checkProcessingStatus();

This approach, while simple, allows the React application to securely upload audio files and retrieve processed data asynchronously, providing a seamless user experience.

@dahifi
Copy link
Contributor Author

dahifi commented Feb 5, 2024

Code currently returns the json object to console and appends the text response in the app.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant