Skip to content

This project is for learning and practicing APIs integration and Flask.

License

Notifications You must be signed in to change notification settings

ibrahima1289/python-api

 
 

Repository files navigation

API-Powered Applications

python-api
This project is for learning and practicing APIs integration and Flask. See sources linked below.
We are building Flask web applications with a user interfaces:

  • An AI-powered chatbot with ChatGPT gpt-3.5-turbo model
  • A Python YouTube video Downloader
  • And more to come ...

0. Good to know

  • Basic cloud computing knowledge
  • SSH into a server
  • Basic scripting

1. Software Tools

  • Languages: Python, HTML, CSS, Flask
  • CI/CD: Jenkins
  • Source Control: Git, GitHub
  • CSP: AWS

2. Architechtures

  • Apllications Architechtures
  • CI/CD Pipeline

This is the workflow of the pipeline.

3. Set Up Virtual Environment for local testing

  1. Create a folder and cd into it and set up the file architecture.

  2. Create the virtual environment:

python3 -m venv virtual_environment_name

  1. Activate the virtial environment
source virtual_environment_name/bin/activate

Note: Use a .gitignore file to avoid inporting the virtual environment folder (and/or other unwanted files) to GitHub.
Use deactivate to deactivate the virtual environment.

  1. Install Requirements:
  • Set up virtual environment.
  • Install the requirements using pip.
pip install --upgrade
pip install flask
pip install pytest
pip install openai
pip install pytube3
pip install youtube_transcript_api

  • You can also add the requirements.txt file in your project folder and install from it by using the command below.
pip install -r requirements.txt

Here is how to get the requirements.txt file.

Set up local Environment Variables for API Keys

  • Local Environment Variables (in Linux Ubuntu WSL)
    • Get your OpenAI API key. Make sure you do not overwrite your .bashrc file.
    echo "export OPENAI_API_KEY='key_value'" >> ~/.bashrc
    source ~/.bashrc
    
  • (Online) Environment Variables

Start the Flask server

  1. Run the command python3 flask-app-file.py or simply flask run.

  1. Now, you can go to the localhost or 127.0.0.1/5000 to see the home page. The port number maybe different - double check!

  1. Click on 1st button and enter your request to the ChatGPT API.

  1. You can also test the YouTube Transcribe
  • Go on YouTube and get a valid URL
  • Paste the URL in the form - you can get to the form by clicking the button YouTube Transcribe.

Make sure you clean up your system, the YouTube Transcribe app will download .mp4 files like it shows below. You can also ignore the files in .gitignore file:

  1. Set up test files to test your code. You can use a simple status code check with pytest.

4. CI/CD - Backend

  • Set up Jenkins server and integrate it to GitHub using a webhook.
  • You can also set up email notification in case the pipeline fails.

Set up Build, Test, and Deploy (Push docker image) stages

5. CI/CD Frontend

6. Set up Docker and DockerHub

  • Follow this link to set up a docker/dockerhub account.

Containerize the application

  1. Choose NGINX or Apache for Frontend
  2. Set up deploy stage - push docker image to AWS using this AWS ECR - Medium doc or AWS ECR - OCTOPUS.
  3. For Practice, push docker image to DockerHub.

6. Set Up AWS (EC2 Server with Docker installed or Use Fargate)

Sources Visited

  1. Install pip
  2. Python script source
  3. Set up Environment Variable for API Key
  4. HTML/CSS
  5. YouTube Transcript Generator
  6. codegpt | blog.devgenius | Youtube | AIAdvantage
  7. Fask app testing-1 | testing-2 | testing-3 | Jenkins-Pytest | Github-Action Pytest
  8. iamnearlythere.com
  9. EC2 ami locator
  10. Dockerfile Linter

About

This project is for learning and practicing APIs integration and Flask.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Languages

  • HTML 59.5%
  • Python 38.1%
  • Shell 2.4%