This application helps in visual language learning by generating videos that combine image recognition, context-based text generation, speech synthesis, and video creation. The app leverages Google Cloud Vision API for object recognition, OpenAI's GPT-3.5 for context generation, Google Cloud Text-to-Speech API for converting text into speech, and FastAPI for handling the web service.
- Object Detection: Upload an image and detect the object using Google Cloud Vision API.
- Context Generation: Generate a context (sentence) in a chosen language where the detected object would be used, powered by OpenAI's GPT model.
- Text-to-Speech: Convert the generated text into speech using Google Cloud Text-to-Speech API.
- Video Creation: Combine the context (text), audio, and background images to create a video.
- Cloud Storage: Upload and share generated videos via a public URL from Google Cloud Storage.
- FastAPI: A modern web framework for building the API.
- OpenAI GPT-3: For generating sentences based on detected objects.
- Google Cloud APIs:
- Vision API: For object detection in uploaded images.
- Text-to-Speech API: For speech synthesis from the generated text.
- Cloud Storage: For storing and serving videos.
- MoviePy: For video processing, combining images, text, and audio.
- Pillow (PIL): For text rendering on images.
- OpenCV: For image processing like resizing background images.
- Python 3.7+
- Google Cloud Account with enabled APIs: Vision API, Text-to-Speech API, Cloud Storage
- OpenAI API key
-
Clone the repository:
git clone https://github.com/hk414/visual-learning-language.git cd visual-learning-language-app -
Install the required dependencies:
pip install -r requirements.txt
-
Set up your Google Cloud credentials:
- Download the service account key JSON file from Google Cloud Console and save it to your project directory.
- Set the
GOOGLE_APPLICATION_CREDENTIALSenvironment variable to the path of the JSON file.
Example for Unix-based systems:
export GOOGLE_APPLICATION_CREDENTIALS="path_to_your_service_account_key.json"
-
Set up your OpenAI API key:
- Create a
.envfile in the root directory and add your OpenAI API key:
OPENAI_API_KEY=your-openai-api-key GOOGLE_APPLICATION_CREDENTIALS=path_to_your_service_account_key.json
- Create a
-
Run the FastAPI app locally:
cd backend uvicorn main:app --reload -
The app will be available at
http://127.0.0.1:8000.
This endpoint generates a learning video from an uploaded image and the specified language.
- language (Form data, optional): The language for the generated sentence. Default is
Mandarin. - image (Form data, required): The image file to be uploaded (must be in
.jpg,.jpeg, or.pngformat).
curl -X 'POST' \
'http://127.0.0.1:8000/generate' \
-F 'language=Mandarin' \
-F 'image=@/path/to/image.jpg'{
"videoPath": "https://storage.googleapis.com/videos_15022025/videos/images%5C1000000034_video.mp4"
}The response contains the public URL to the generated video stored in Google Cloud Storage.
- The app uses Google Cloud Storage with the bucket name
videos_15022025to store the generated videos. - Background images can be customized by replacing the default
"background.jpg"in the video creation process. - The generated video will include a context-based sentence in the selected language and an audio overlay.
- Invalid API key: Make sure your
OPENAI_API_KEYand Google Cloud credentials are properly set up. - Invalid image format: Ensure the uploaded image is in
.jpg,.jpeg, or.pngformat.