DEV Community

Cover image for Deployment of the GenAI-Educational-Assistant Streamlit App on AWS EC2 using Visual Studio Code (VSC)

Deployment of the GenAI-Educational-Assistant Streamlit App on AWS EC2 using Visual Studio Code (VSC)

Introduction: The Dream of a Young Coder

Once upon a time, in a bustling city brimming with technology enthusiasts and aspiring developers, there was a young coder named Kha. Ever since discovering the wonders of artificial intelligence (AI), Kha had been deeply fascinated by its potential to transform lives, especially in the field of education. With an insatiable curiosity, Kha dove into learning everything about AI—machine learning algorithms, natural language processing (NLP), and the vast possibilities of cloud computing. However, Kha wasn’t satisfied with merely acquiring knowledge; the true dream was to build something impactful, something that could help students worldwide learn more effectively.

Kha envisioned a virtual educational assistant—powered by generative AI—that could provide personalized learning experiences, answer complex questions, and guide students through challenging topics. The idea was simple yet profound: an AI assistant that could be accessed by anyone, anywhere, providing tailored educational support.

Discovering the Power of Amazon Web Services

One evening, while browsing through an online forum dedicated to AI enthusiasts, Kha stumbled upon a discussion about Amazon Web Services (AWS) and its potential for deploying AI applications. Intrigued, Kha spent the next few days researching AWS services, quickly realizing that AWS was the perfect platform to bring the GenAI-Educational-Assistant to life. The scalable and flexible infrastructure of AWS, combined with its vast array of AI and machine learning services, provided everything needed to build, deploy, and manage a powerful AI-driven application.

With renewed enthusiasm, Kha embarked on the journey to create the GenAI-Educational-Assistant. The first step was setting up an environment where the AI could be developed, tested, and eventually deployed. After careful consideration, Kha chose Amazon Bedrock, an AWS service designed specifically for deploying generative AI applications. Bedrock provided a comprehensive suite of tools and pre-trained models that could be customized for the educational assistant, saving valuable development time.

Step 1: Setting Up the AWS Environment

Kha began by logging into the AWS Management Console and navigating to Amazon Bedrock. The interface was user-friendly, allowing Kha to quickly select and deploy pre-trained models suitable for educational content generation.

1. **Launch Bedrock and Set Up the Environment:

  • Kha started by accessing Amazon Bedrock from the AWS Management Console.
  • Selected a pre-trained model from the available options tailored to NLP tasks.
  • Created a new project within Bedrock, which would serve as the workspace for developing the GenAI-Educational-Assistant.

2. Configure Security and Permissions:

  • Ensured that the necessary IAM roles were in place, granting the application the required permissions to access and use other AWS services.
  • Configured security groups to restrict access to only the necessary ports and IP addresses, thereby enhancing the security of the application.

3. Deploying a Development Environment:

  • Using an Amazon EC2 instance, Kha set up a development environment. This instance would be used to code, test, and deploy updates to the GenAI-Educational-Assistant.

Step 2: Developing the GenAI-Educational-Assistant

With the environment set up, Kha began the development process. The first task was to create the core logic of the educational assistant, focusing on how it would generate responses to students' queries.

1. Cloning the Project Repository:

  • Kha cloned the project repository from GitHub, which contained the foundational code for the assistant.
  • This included Python scripts that would handle user inputs, query the AI models hosted on Amazon Bedrock, and generate appropriate responses.

2. Customizing the Pre-trained Models:

  • Kha used Amazon Bedrock’s customization capabilities to fine-tune the pre-trained models. This involved feeding the models with educational datasets to improve their accuracy and relevance to students' needs.

3. Developing the User Interface:

  • For the front end, Kha chose Streamlit, a Python-based framework that allowed for quick development of interactive web applications.
  • The Streamlit app was designed to be intuitive, with a simple interface where students could input their questions and receive detailed, AI-generated explanations.

Step 3: Deploying and Testing the Application

After weeks of development, it was time to deploy the GenAI-Educational-Assistant for testing. Kha decided to run the application on the EC2 instance to simulate real-world usage.

1. Running the Streamlit Application:

  • The application was started on the EC2 instance, with the Streamlit app running on port 8080.
  • Kha accessed the application through the instance’s public IP, testing various features to ensure everything was functioning as expected.

2. Testing and Optimization:

  • Kha tested the application by inputting various educational queries, observing how well the AI-generated responses met the needs of different educational levels.
  • Based on feedback from initial testing, Kha made adjustments to the model parameters and optimized the Python code to improve performance.

Step 4: Preparing for Production Launch

Satisfied with the performance of the application, Kha began preparing for a public launch. This involved scaling the infrastructure to handle increased traffic and ensuring that the application was secure and reliable.

1. Scaling the EC2 Instance:

  • Kha upgraded the EC2 instance to a more powerful type to handle more simultaneous users.
  • Configured Auto Scaling to automatically adjust the number of instances based on user demand, ensuring the application remained responsive even during peak usage times.

2. Implementing Security Best Practices:

  • To protect user data, Kha implemented SSL encryption, ensuring that all communications between users and the server were secure.
  • Additional security measures, such as setting up a Web Application Firewall (WAF) and enabling DDoS protection, were put in place.

3. Monitoring and Maintenance:

  • AWS CloudWatch was set up to monitor the application’s performance, with alerts configured for any unusual activity.
  • Kha also set up regular backups and implemented a disaster recovery plan to ensure the application’s availability in case of any issues.

Step 5: Launch and Beyond

The day finally arrived when Kha was ready to launch the GenAI-Educational-Assistant to the public. The application was made available to students and educators worldwide, who quickly began to benefit from its capabilities.

1. Initial Reception:

  • The response was overwhelmingly positive. Students appreciated the personalized learning experience, while educators found the tool invaluable for supplementing their teaching materials.
  • The AI-driven assistant quickly became a trusted resource, helping students understand complex subjects with ease.

2. Continuous Improvement:

  • Kha remained committed to improving the application, regularly updating the AI models with new educational content and adding new features based on user feedback.
  • The success of the GenAI-Educational-Assistant inspired Kha to explore other potential applications of generative AI, leading to new projects and innovations.

Conclusion: The Impact of a Dream Realized

Months after the launch, Kha received numerous messages of gratitude from students and educators alike. One message, in particular, stood out—a student from a remote area, who had limited access to educational resources, shared how the GenAI-Educational-Assistant had transformed their learning experience.

"Thank you for creating this assistant," the message read. "It has changed my life."

Kha knew that the journey was far from over. The GenAI-Educational-Assistant would continue to grow, evolve, and impact countless lives around the world. And it all started with a dream, a passion for AI, and the powerful tools provided by Amazon Web Services.

Step-by-Step Deployment Guide: Building Your Own GenAI-Educational-Assistant

Now that you’ve followed Kha’s story, you might be inspired to create your own AI-driven application. Below is a detailed step-by-step guide to help you deploy the GenAI-Educational-Assistant using Amazon Bedrock and other AWS services.

Prerequisites

  1. AWS Account: Ensure you have an active AWS account.
  2. IAM Role/Policy: Attach an appropriate IAM role with permissions for necessary AWS services.
  3. Security Group: Ensure the security group attached to your EC2 instance allows inbound traffic on port 22 for SSH and port 8080 for the Streamlit app.

Step 1: Launch and Connect to the EC2 Instance

  1. Launch EC2 Instance:

    • Navigate to the EC2 dashboard on AWS Management Console.
    • Launch an EC2 instance using a Linux AMI.
    • Choose an instance type, e.g., t2.micro.
    • Configure the instance details, and attach the necessary IAM role.
    • Configure security group settings, allowing inbound traffic on ports 22 (SSH) and 8080 (Streamlit).
    • Review and launch the instance.
  2. Connect to the EC2 Instance:

    • Use SSH to connect to your EC2 instance from your local machine:
     ssh -i /path/to/your-key.pem ec2-user@your-ec2-public-ip
    

Step 2: Set Up Your Environment on EC2

  1. Install Python:

    • Ensure Python 3 is installed on the EC2 instance:
     sudo yum install python3 -y  # For Amazon Linux
     sudo apt-get install python3 -y  # For Ubuntu
    
  2. Set Up Python Virtual Environment:

    • Install virtualenv and create a virtual environment:
     sudo pip3 install virtualenv
     virtualenv venv
     source venv/bin/activate
    
  3. Install AWS CLI:

    • Install the AWS CLI to interact with AWS services:
     curl "https://awscli.amazonaws.com/awscli-exe-linux-x86_64.zip" -o "awscliv2.zip"
     unzip awscliv2.zip
     sudo ./aws/install
     aws configure
    

Step 3: Clone the Repository and Install Dependencies

  1. Clone the Repository:

    • Clone the GenAI-Educational-Assistant repository from GitHub to your EC2 instance:
     git clone https://github.com/awsstudygroup/GenAI-Educational-Assistant.git
     cd GenAI-Educational-Assistant
    
  2. Install Required Python Packages:

    • Install the dependencies listed in the requirements.txt file:
     pip3 install -r requirements.txt
    

Step 4: Run the Streamlit Application

  1. Run the Streamlit App:

    • Start the Streamlit application on port 8080:
     streamlit run Home.py --server.port 8080
    
  2. Access the Application:

    • Open your browser and navigate to http://your-ec2-public-ip:8080 to view and interact with the Streamlit app.

Step 5: Develop and Manage the Application using Visual Studio Code (VSC)

  1. Set Up VSC for Remote Development:

    • Install the Remote - SSH extension in VSC.
    • Connect to your EC2 instance using VSC by configuring the SSH settings.
  2. Develop and Test:

    • You can now use VSC to develop and manage the GenAI-Educational-Assistant application directly on your EC2 instance. Any changes you make can be tested by rerunning the Streamlit app.

Step 6: Secure and Optimize the Deployment

  1. Security Enhancements:

    • Ensure the security group rules are tightened to allow only necessary traffic.
    • Consider using an SSL certificate if deploying for production purposes.
  2. Cost Optimization:

    • Monitor the EC2 instance's usage and consider using Spot Instances or setting up Auto Scaling for cost efficiency.

Step 7: Monitoring and Maintenance

  1. Monitoring:

    • Use AWS CloudWatch to monitor the performance and logs of the EC2 instance and the Streamlit app.
    • Set up alarms for any critical metrics.
  2. Updates and Maintenance:

    • Regularly pull updates from the GitHub repository and update dependencies to maintain security and functionality.

Conclusion

By following these steps, you’ll be able to deploy a GenAI-Educational-Assistant using Amazon Bedrock and other AWS services, creating a scalable, secure, and impactful educational tool. Whether you're a student, educator, or developer, this application demonstrates the transformative potential of generative AI in education, paving the way for a more personalized and accessible learning experience for all.

Top comments (0)