This project is a FastAPI-based web application that extracts transcripts from YouTube videos and generates summaries using OpenAI's OpenRouter API. It is designed to process YouTube video URLs, fetch their transcripts, and return concise summaries.
- Extracts transcripts from YouTube videos using the
youtube-transcript-api
. - Summarizes video content using OpenAI's language models via the OpenRouter API.
- Provides a RESTful API with endpoints for summarization and basic health checks.
- Python 3.9 or higher
- Dependencies listed in
requirements.txt
-
Clone the Repository:
git clone <repository-url> cd <repository-folder>
-
Set Up a Virtual Environment:
python -m venv venv source venv/bin/activate # On Windows: venv\Scripts\activate
-
Install Dependencies:
pip install -r requirements.txt
-
Set Up Environment Variables:
- Create a
.env
file in the project root directory and add the following variables:OPENROUTER_API_KEY=<your_openrouter_api_key> YOUR_SITE_URL=<your_site_url> YOUR_SITE_NAME=<your_site_name> MODEL=<openai_model_name> # e.g., gpt-4 or gpt-3.5-turbo
- Create a
Start the FastAPI server:
uvicorn main:app --reload
The server will start at http://127.0.0.1:8000
.
- URL:
/summarize
- Method:
POST
- Request Body:
{ "url": "https://www.youtube.com/watch?v=<video_id>" }
- Response:
{ "summary": "<summarized_text>" }
- URL:
/
- Method:
GET
- Response:
{ "greeting": "Hello, World!", "message": "Welcome to FastAPI!" }
- The user sends a YouTube video URL to the
/summarize
endpoint. - The app extracts the video ID from the URL.
- The transcript is fetched using the
youtube-transcript-api
. - The transcript is sent to OpenRouter's API for summarization.
- A concise summary is returned to the user.
- Handles invalid YouTube URLs with appropriate error messages.
- Catches exceptions during transcript fetching or summarization and returns meaningful HTTP error codes.
Key dependencies include:
FastAPI
: For building the web API.Pydantic
: For request and response validation.youtube-transcript-api
: For fetching YouTube video transcripts.openai
: For interacting with OpenRouter's API.python-dotenv
: For managing environment variables.
- Add support for multilingual transcripts and summaries.
- Implement caching for frequently summarized videos.
- Enhance error handling for unsupported videos (e.g., no captions).