<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Stories by Saba Gul on Medium]]></title>
        <description><![CDATA[Stories by Saba Gul on Medium]]></description>
        <link>https://medium.com/@_sabagul_?source=rss-72aab5678257------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*C-k8Cyxq5ajudYrxNfyhpQ.jpeg</url>
            <title>Stories by Saba Gul on Medium</title>
            <link>https://medium.com/@_sabagul_?source=rss-72aab5678257------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Fri, 20 Nov 2026 20:38:46 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@_sabagul_/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[Vector Twin: Discover Your Celebrity Look-Alike with AI]]></title>
            <link>https://medium.com/@_sabagul_/vector-twin-discover-your-celebrity-look-alike-with-ai-7a0023a1dd6b?source=rss-72aab5678257------2</link>
            <guid isPermaLink="false">https://medium.com/p/7a0023a1dd6b</guid>
            <category><![CDATA[embedding-model]]></category>
            <category><![CDATA[vector-database]]></category>
            <category><![CDATA[vector-search]]></category>
            <category><![CDATA[qdrant]]></category>
            <category><![CDATA[fastapi]]></category>
            <dc:creator><![CDATA[Saba Gul]]></dc:creator>
            <pubDate>Tue, 19 Nov 2024 20:11:00 GMT</pubDate>
            <atom:updated>2024-11-19T20:11:00.146Z</atom:updated>
            <content:encoded><![CDATA[<p><em>Step-by-Step Guide to Building a Celebrity Matching System</em></p><h3>Introduction</h3><p>Ever wondered which celebrity you resemble? With <em>Vector Twin</em>, an AI-powered celebrity matching system, you can find your celebrity look-alike by simply uploading an image! This project demonstrates the powerful intersection of machine learning, vector search, and modern web frameworks to deliver a fast, accurate, and interactive user experience.</p><p>In this guide, we’ll walk through the system’s architecture and workflows, covering embedding generation, vector database integration, backend processing, and frontend interaction.</p><h3>Overview of the Project</h3><p>The <em>Vector Twin</em> system matches user-uploaded images to a celebrity database by:</p><ol><li>Generating high-dimensional facial embeddings.</li><li>Storing embeddings in a vector search database for similarity comparison.</li><li>Displaying top matches through an intuitive frontend interface.</li></ol><h3>System Components:</h3><ol><li><strong>Backend (FastAPI)</strong>: Processes images, generates embeddings, and interacts with the vector database.</li><li><strong>Frontend (Streamlit)</strong>: Provides a simple interface for uploading images and displaying results.</li><li><strong>Data Management</strong>:</li></ol><ul><li><strong>Qdrant</strong>: High-performance vector search database for embedding queries.</li><li><strong>Supabase</strong>: Manages metadata (e.g., celebrity names) and user authentication.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/952/1*cXSMha_p61xP87kK_w35UA.png" /></figure><h3>Step-by-Step Workflow</h3><h3>Step 1: Generating Face Embeddings</h3><p>The first step in the workflow is to generate facial embeddings from the uploaded image. <strong>Facial embeddings</strong> are essentially numerical representations of facial features that capture the unique characteristics of a person’s face in a format that can be easily compared to others.</p><h4><strong>Model</strong>:</h4><ul><li><em>InceptionResNetV1</em>, pre-trained on FaceNet.</li><li>Outputs 512-dimensional vectors representing unique facial features.</li><li><strong>Similarity Metric</strong>: Cosine similarity measures the closeness of embeddings.</li></ul><h3>Step 2: Storing Embeddings in Qdrant</h3><p>Once the embeddings are generated, we store them in <strong>Qdrant</strong>, a vector search database that is optimized for storing and querying high-dimensional vectors.</p><p><strong>Qdrant</strong> allows us to store large numbers of embeddings and efficiently search through them to find the most similar faces. The database stores these vectors along with associated metadata (such as the celebrity name). When a user uploads their image, the system will query the database to find embeddings with the highest similarity score.</p><h4><strong>Dataset</strong>:</h4><p><strong>Pins Face Recognition Dataset</strong> (from Kaggle): A diverse collection of celebrity face images used to create the embeddings.</p><h4><strong>Setup in Qdrant</strong>:</h4><ul><li>Create a collection specifying vector size (512) and distance metric (cosine similarity).</li><li>Store each embedding along with metadata like celebrity names.</li><li>During a search, uploaded embeddings are compared against stored embeddings to find the closest matches.</li></ul><h3>Step 3: User Management with Supabase</h3><p>To manage user data and authentication securely, we use <strong>Supabase</strong>. It provides an easy-to-use, open-source alternative to Firebase, handling user sign-ups, logins, and storing user-specific data.</p><p><strong>Supabase</strong> is integrated with the backend to:</p><ul><li>Authenticate users before they upload an image.</li><li>Store user-specific data (such as previous image uploads or search history) for a personalized experience.</li></ul><h3>Step 4: Backend Development with FastAPI</h3><p>The backend of <strong>Vector Twin</strong> is built with <strong>FastAPI</strong>, a modern web framework for building APIs. It handles image uploads, processes the images, generates embeddings, and interacts with <strong>Qdrant</strong> to find matching celebrity look-alikes.</p><p>Key features of the <strong>FastAPI</strong> backend:</p><ul><li><strong>Image Upload:</strong> Users upload their images via an API endpoint, which then processes the image and generates an embedding.</li><li><strong>Vector Search:</strong> The backend queries the <strong>Qdrant</strong> database to perform a vector search and retrieves the top matching celebrities.</li><li><strong>Error Handling:</strong> If no matches are found or any errors occur, the backend responds with appropriate error messages.</li></ul><h4>Example Endpoint:</h4><pre>@app.post(&quot;/upload-image/&quot;)<br>async def upload_image(file: UploadFile = File(...)):<br>    image_bytes = await file.read()<br>    embedding = generate_embedding(image_bytes)<br>    results = qdrant_client.search(<br>        collection_name=&quot;celebrity_embeddings&quot;,<br>        query_vector=embedding.tolist(),<br>        limit=10<br>    )<br>    return {&quot;matches&quot;: results}</pre><p>Access the backend locally at: <a href="http://127.0.0.1:8500/">http://127.0.0.1:8500</a>.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*zBBurBtdpzAdBnkxlHZblQ.png" /></figure><h3>Step 5: Frontend with Streamlit</h3><p>The frontend is built using <strong>Streamlit</strong>, a Python library for creating web applications. The <strong>Streamlit</strong> app allows users to easily upload images and view the results in a clean and simple UI.</p><h3>Frontend Workflow:</h3><ul><li>Users visit the <strong>Streamlit</strong> app, upload an image, and wait for the system to return the celebrity look-alike results.</li><li>The app communicates with the <strong>FastAPI</strong> backend to send the uploaded image and receive the matching celebrities.</li><li>Results are displayed in an intuitive format, showing the top matching celebrities and their similarity scores.</li></ul><h4>Code Example:</h4><pre>import streamlit as st<br>import requests<br>st.title(&quot;Celebrity Look-Alike Finder&quot;)<br>uploaded_image = st.file_uploader(&quot;Upload an Image&quot;, type=[&quot;jpg&quot;, &quot;png&quot;])<br>if uploaded_image:<br>    files = {&quot;file&quot;: uploaded_image}<br>    response = requests.post(&quot;http://127.0.0.1:8500/upload-image/&quot;, files=files)<br>    results = response.json()<br>    for result in results[&quot;matches&quot;]:<br>        st.image(result[&quot;image_url&quot;], caption=result[&quot;name&quot;], use_column_width=True)<br>        st.write(f&quot;Similarity Score: {result[&#39;score&#39;]}&quot;)</pre><p>Access the frontend locally at: <a href="http://127.0.0.1:8501/">http://127.0.0.1:8501</a>.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*H_cYE3dJweXMpZi3ErgV-A.png" /></figure><h3>Step 6: Bringing It All Together</h3><p>With the image uploaded, embeddings generated, and matching process complete, <strong>Vector Twin</strong> delivers a seamless experience for users to discover which celebrities resemble them. The process is fast, efficient, and accurate due to the combination of <strong>FastAPI</strong> for backend processing, <strong>Qdrant</strong> for vector search, and <strong>Streamlit</strong> for the frontend.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*kmNJmbWEtZHFRO_AgmJ1lw.png" /></figure><h3>Conclusion</h3><p>The <strong>Vector Twin</strong> project is an exciting example of how AI and machine learning can be leveraged to create engaging, real-world applications. By utilizing <strong>Qdrant</strong> for vector searches, <strong>FastAPI</strong> for backend development, and <strong>Streamlit</strong> for user interaction, the system provides an easy-to-use solution for finding celebrity look-alikes.</p><p>This project also highlights the power of <strong>open-source</strong> technologies and <strong>cloud infrastructure</strong> for building scalable and fast AI applications. As AI continues to advance, we can expect more creative and innovative applications in the future.</p><p><strong>Explore the Codebase</strong>: <a href="https://github.com/Saba-Gul/celebrity-vector-twin">GitHub Repo</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=7a0023a1dd6b" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Mastering Machine Learning Deployment with Google Kubernetes Engine: A Beginner’s Guide (Part-II)]]></title>
            <link>https://medium.com/@_sabagul_/mastering-machine-learning-deployment-with-google-kubernetes-engine-a-beginners-guide-part-ii-411a616b3890?source=rss-72aab5678257------2</link>
            <guid isPermaLink="false">https://medium.com/p/411a616b3890</guid>
            <category><![CDATA[deployment-pipelines]]></category>
            <category><![CDATA[kubernetes]]></category>
            <category><![CDATA[kubernetes-cluster]]></category>
            <category><![CDATA[gcp]]></category>
            <category><![CDATA[gke-ingress]]></category>
            <dc:creator><![CDATA[Saba Gul]]></dc:creator>
            <pubDate>Sun, 27 Oct 2024 05:39:33 GMT</pubDate>
            <atom:updated>2024-10-27T05:39:33.421Z</atom:updated>
            <content:encoded><![CDATA[<p>Deploying machine learning models is a crucial step in transitioning from research to real-world application, yet for many beginners, the process can be daunting. One of the most powerful ways to deploy and manage machine learning models at scale is through Google Kubernetes Engine (GKE). In this guide, we’ll break down the basics of deploying machine learning models on GKE, covering everything from setting up your environment to scaling and monitoring your deployment.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*MbNwcwiifxetoz-iFIPbng.png" /><figcaption>Photo by <a href="https://venturebeat.com/dev/google-announces-kubernetes-engine-1-10-update-with-new-enterprise-features/">VentureBeat</a></figcaption></figure><h3>Why Choose Google Kubernetes Engine?</h3><p>Google Kubernetes Engine is a managed Kubernetes service provided by Google Cloud Platform (GCP). Kubernetes, initially developed by Google, allows you to automate deploying, scaling, and managing containerized applications. GKE adds an extra layer of ease by handling much of the heavy lifting, including security, updates, and auto-scaling.</p><p>Using GKE for deploying machine learning models offers several benefits:</p><ul><li><strong>Scalability:</strong> Easily scale your model up or down based on demand.</li><li><strong>Reliability:</strong> With managed services, you have built-in support for high availability and fault tolerance.</li><li><strong>Efficiency:</strong> Reduce the complexity of infrastructure management, allowing you to focus on model performance and accuracy.</li></ul><p>Before diving into the deployment process, let’s go over some <strong>key Kubernetes concepts</strong> you’ll encounter.</p><h3>Key Kubernetes Terms</h3><ul><li><strong>Pods</strong>: The smallest deployable unit in Kubernetes. A pod usually contains one or more containers (often just one for simple applications) that share the same network and storage resources. Pods are ephemeral, meaning they are created, used, and deleted according to the workload needs.</li><li><strong>Nodes</strong>: Machines, either physical or virtual, that run your pods. Nodes handle the computing resources needed by the containers in the pods. Kubernetes clusters typically have multiple nodes to ensure high availability and scalability.</li><li><strong>Cluster</strong>: A group of nodes managed by Kubernetes. It represents the entirety of the environment where your application is running. In GKE, Google manages the control plane of the cluster, so you only need to focus on the worker nodes.</li><li><strong>Deployment</strong>: A configuration that defines how to deploy and manage pods. The deployment specifies the container image, number of replicas, and other configurations to keep the application running even if some pods fail.</li><li><strong>Service</strong>: A Kubernetes component that allows different parts of an application to communicate with each other. For instance, a LoadBalancer service exposes the deployment externally, allowing traffic from the internet to reach the application running inside Kubernetes.</li></ul><h3>YAML Files in Kubernetes</h3><p>Kubernetes uses YAML files to define the configuration of resources, like pods, deployments, and services. Here’s a breakdown of the essential parts of each YAML file we’ve seen:</p><ul><li><strong>Deployment YAML</strong>: Specifies how many copies of a pod (containerized application) to run and the container image to use.</li><li><strong>Service YAML</strong>: Defines how to make the application accessible, setting up types like LoadBalancer to handle incoming traffic.</li></ul><h3>Step 1: Set Up Your Google Cloud Environment</h3><ol><li><strong>Create a Google Cloud Account:</strong> If you haven’t already, set up an account on <a href="https://cloud.google.com/">Google Cloud</a>.</li><li><strong>Enable GKE API:</strong> In the Google Cloud Console, navigate to <strong>APIs &amp; Services</strong> and enable the Kubernetes Engine API.</li><li><strong>Install Google Cloud SDK and Kubectl:</strong> Install the Google Cloud SDK and the Kubernetes command-line tool (kubectl). These tools allow you to interact with your GCP resources and Kubernetes clusters directly from your local machine.</li></ol><pre># Install Google Cloud SDK<br>curl -O https://dl.google.com/dl/cloudsdk/channels/rapid/downloads/google-cloud-sdk-xxx.tar.gz<br>tar -xvf google-cloud-sdk-xxx.tar.gz<br>./google-cloud-sdk/install.sh<br><br># Install kubectl<br>gcloud components install kubectl</pre><p><strong>4. Authenticate with GCP:</strong> Use gcloud init to authenticate and configure your Google Cloud account.</p><h3>Step 2: Containerize Your Model</h3><p>To deploy a machine learning model, you’ll first need to package it as a Docker container. Docker allows you to bundle your application, dependencies, and environment configuration into one easily deployable unit.</p><ol><li><strong>Create a Dockerfile:</strong> This file outlines the steps to set up your container environment. Here’s an example Dockerfile for a model using Python and Flask.</li></ol><pre>FROM python:3.9-slim <br>COPY . /app <br>WORKDIR /app <br>RUN pip install -r requirements.txt <br>EXPOSE 80 <br>CMD [&quot;python&quot;, &quot;app.py&quot;]</pre><p><strong>2. Build the Docker Image:</strong> Run the following command in the terminal:</p><pre>docker build -t gke-ml-model:latest .</pre><p><strong>3. Push to Google Container Registry (GCR):</strong> This step is crucial because GKE will need to pull the container image from a registry. Use the commands below:</p><pre>gcloud auth configure-docker <br>docker tag gke-ml-model:latest gcr.io/[PROJECT-ID]/gke-ml-model:latest <br>docker push gcr.io/[PROJECT-ID]/gke-ml-model:latest</pre><p>Replace [PROJECT-ID] with your Google Cloud project ID.</p><h3>Step 3: Set Up a Kubernetes Cluster on GKE</h3><ol><li><strong>Create the Cluster:</strong> In the Google Cloud Console, navigate to <strong>Kubernetes Engine</strong> &gt; <strong>Clusters</strong> and create a new cluster. Choose the region, machine type, and other settings based on your budget and performance requirements.</li><li><strong>Connect to the Cluster:</strong> After the cluster is created, you can connect to it with kubectl:</li></ol><pre>gcloud container clusters get-credentials [CLUSTER-NAME] --zone [ZONE]</pre><p>3. Replace [CLUSTER-NAME] and [ZONE] with your cluster name and zone.</p><h3>Step 4: Deploy Your Model to GKE</h3><ol><li><strong>Create a Deployment File:</strong> Define a Kubernetes deployment YAML file, which describes the deployment configuration for your model. Save it as deployment.yaml.</li></ol><pre>apiVersion: apps/v1  # Specifies the API version for creating a deployment.<br>kind: Deployment  # Declares this YAML file as a Deployment.<br>metadata:<br>  name: ml-model-deployment  # The unique name of your deployment.<br>spec:<br>  replicas: 3  # Sets the number of pod replicas to run.<br>  selector:<br>    matchLabels:<br>      app: ml-model  # Ensures only pods with this label will be managed by this deployment.<br>  template:<br>    metadata:<br>      labels:<br>        app: ml-model  # Labels to identify pods in this deployment.<br>    spec:<br>      containers:<br>      - name: ml-model  # The container&#39;s name.<br>        image: gcr.io/[PROJECT-ID]/gke-ml-model:latest  # The image from GCR for your model.<br>        ports:<br>        - containerPort: 80  # Exposes container&#39;s port 80 to the outside.</pre><h4>Explanation</h4><ul><li><strong>apiVersion</strong>: Defines which Kubernetes API version is used to create this deployment.</li><li><strong>kind</strong>: Specifies the resource type. Here, it’s a Deployment to manage the pods for the application.</li><li><strong>metadata</strong>: Contains metadata, including the name of the deployment.</li><li><strong>spec</strong>: Configures the desired state of the deployment.</li><li><strong>replicas</strong>: Specifies the number of identical pod replicas to run.</li><li><strong>selector</strong> and <strong>template</strong>: Ensure that only pods with a specific label (app: ml-model) are managed by this deployment.</li><li><strong>containers</strong>: Defines the container within the pod, including the Docker image and port configuration.</li></ul><p><strong>2. Apply the Deployment:</strong> Use kubectl to apply the configuration and deploy the model.</p><pre>kubectl apply -f deployment.yaml</pre><p><strong>3. Expose the Deployment:</strong> Make the deployment accessible by exposing it as a service. Here’s how you can set up a LoadBalancer service:</p><pre>apiVersion: v1  # Specifies the API version for creating a service.<br>kind: Service  # Declares this YAML file as a Service resource.<br>metadata:<br>  name: ml-model-service  # The unique name for the service.<br>spec:<br>  type: LoadBalancer  # Defines the service type for external access.<br>  selector:<br>    app: ml-model  # Matches the service with pods labeled as app: ml-model.<br>  ports:<br>    - protocol: TCP  # Specifies the communication protocol.<br>      port: 80  # Exposes port 80 on the service.<br>      targetPort: 80  # Connects to port 80 in the pod&#39;s container.</pre><h4>Explanation</h4><ul><li><strong>apiVersion</strong>: Defines which Kubernetes API version is used for this service.</li><li><strong>kind</strong>: Specifies the resource type, here Service, which provides access to the pods.</li><li><strong>metadata</strong>: Contains metadata, including the service’s unique name.</li><li><strong>spec</strong>: Configures the service’s behavior.</li><li><strong>type</strong>: Specifies the service type; LoadBalancer makes the service accessible outside the cluster.</li><li><strong>selector</strong>: Matches pods with the label app: ml-model to link the service to the correct pods.</li><li><strong>ports</strong>: Specifies the communication details, mapping the service’s external port (80) to the target container port (80) inside the pods.</li></ul><p>4. Apply the service file:</p><pre>kubectl apply -f service.yaml</pre><p>After a few minutes, you’ll be able to access the model at the external IP address of the load balancer.</p><h3>Step 5: Scale and Monitor Your Deployment</h3><h3>Scaling</h3><p>One of Kubernetes’ biggest advantages is its built-in support for scaling. You can easily scale your deployment by adjusting the replicas value in your deployment.yaml file or using the following command: code</p><pre>kubectl scale deployment ml-model-deployment --replicas=5</pre><p>This command scales the deployment to 5 replicas, distributing the workload and improving reliability.</p><h3>Monitoring</h3><p>To monitor your deployment, you can use Google Cloud’s Stackdriver for Kubernetes. Stackdriver provides insights into CPU and memory usage, error rates, and other critical metrics. This is particularly useful for observing model performance in real time and diagnosing issues.</p><h3>Final Thoughts</h3><p>Deploying machine learning models on GKE may seem complex at first, but with a structured approach, you can effectively bring your models into production. Google Kubernetes Engine offers a robust, scalable solution for managing containerized applications, making it ideal for ML deployments that need high availability and scalability.</p><h3>Key Kubernetes Terms</h3><ol><li><strong>Cluster</strong>: A Kubernetes environment made up of multiple <strong>nodes</strong> that collectively run applications. It represents the entire environment managed by Kubernetes, containing both worker nodes (where applications run) and the control plane (which manages the cluster).</li><li><strong>Nodes</strong>: The machines, either virtual or physical, that make up a Kubernetes cluster. Each node runs the necessary services to host <strong>pods</strong> and manage networking. A cluster can have multiple nodes for higher availability and scalability.</li><li><strong>Pods</strong>: The smallest deployable unit in Kubernetes, typically containing one or more tightly coupled containers that share storage and network resources. Pods are ephemeral and created, used, and deleted according to the workload needs.</li><li><strong>Container</strong>: A lightweight, standalone executable that includes everything needed to run an application, such as code, libraries, and dependencies. Containers are the foundation of Kubernetes workloads and are packaged into pods.</li><li><strong>Kubelet</strong>: A node agent that ensures containers are running as defined in the pod specs. The kubelet monitors each node, starting, stopping, and reporting the status of containers to the Kubernetes control plane.</li><li><strong>Control Plane</strong>: The set of components that manages and controls the entire Kubernetes cluster, including the <strong>API Server</strong>, <strong>Controller Manager</strong>, <strong>Scheduler</strong>, and <strong>etcd</strong>. It’s responsible for maintaining the desired state of the cluster and coordinating activities across nodes.</li><li><strong>API Server</strong>: The main management point of the Kubernetes control plane that processes requests (via REST API) and interacts with other control plane components. It serves as the interface to Kubernetes, allowing administrators and applications to communicate with the cluster.</li><li><strong>Scheduler</strong>: A component of the control plane that determines on which nodes pods should run based on resource requirements and availability. It assigns pods to nodes for optimal resource utilization and efficiency.</li><li><strong>Controller Manager</strong>: A component that runs various controllers (like replication controller, endpoint controller, etc.) to ensure the desired state of the cluster is maintained. Each controller watches the state of the cluster and makes necessary changes to meet the desired state.</li><li><strong>etcd</strong>: A consistent and highly available key-value store that holds all the data for the cluster’s state, including configurations and secrets. etcd is crucial for cluster health and consistency.</li><li><strong>ReplicaSet</strong>: A resource that ensures a specified number of pod replicas are running at any time. If a pod fails or is deleted, the ReplicaSet automatically replaces it, helping maintain application availability.</li><li><strong>Deployment</strong>: A higher-level abstraction that manages ReplicaSets and provides declarative updates to pods and ReplicaSets. A deployment allows you to define the number of pod replicas, container images, and other configurations, automating scaling and updates.</li><li><strong>Service</strong>: A Kubernetes resource that allows stable networking and communication between pods and other parts of the cluster. It provides a fixed IP and DNS name, making it easy to expose applications externally and internally within the cluster.</li></ol><figure><img alt="" src="https://cdn-images-1.medium.com/max/1000/1*QqctFDVmmAmkiJRmzxm0KA.png" /></figure><ol><li><strong>Ingress</strong>: A resource that manages external access to services within a cluster, typically HTTP or HTTPS. It acts as a routing layer, allowing multiple services to be accessible under a single IP address, with routing rules for different paths or hostnames.</li><li><strong>ConfigMap</strong>: A key-value store that allows you to store configuration data separately from the application’s code. This makes it easy to change configurations without modifying or redeploying the application itself.</li><li><strong>Secrets</strong>: A resource for storing sensitive data, like passwords, tokens, or keys. Secrets are similar to ConfigMaps but are specifically designed to hold confidential information and are stored in an encrypted format.</li><li><strong>PersistentVolume (PV)</strong>: A resource that provides storage in a Kubernetes cluster. It’s a piece of storage provisioned independently of pods and remains available even if pods are deleted, enabling long-term data persistence.</li><li><strong>PersistentVolumeClaim (PVC)</strong>: A request for storage that’s used to connect pods to PersistentVolumes. A PVC allows pods to access storage as needed, enabling applications to read from or write to a consistent storage layer.</li><li><strong>Namespace</strong>: A virtual cluster within a Kubernetes cluster. Namespaces provide a way to divide cluster resources among multiple users or applications, enabling isolation and resource management within the same physical cluster.</li><li><strong>DaemonSet</strong>: A type of resource that ensures a copy of a specific pod runs on all or selected nodes. DaemonSets are typically used for logging, monitoring, or networking tasks that need to be deployed consistently across all nodes.</li><li><strong>StatefulSet</strong>: A resource for managing stateful applications, ensuring that pods are uniquely identified and maintain data persistence across restarts. It’s useful for databases and applications where pod identity and storage stability are essential.</li><li><strong>Job</strong>: A resource that creates pods to perform a specific task, then terminates them upon completion. Jobs are useful for batch processing or tasks that need to be run to completion.</li><li><strong>CronJob</strong>: A type of Job that runs on a scheduled basis, similar to a cron job in Linux. It’s useful for periodic tasks like backups, data synchronization, or maintenance jobs.</li><li><strong>YAML Files</strong>: Kubernetes configurations are written in YAML files, defining the desired state of resources like deployments, services, and volumes. These YAML files are applied to the cluster to create or modify resources in a standardized, declarative way.</li></ol><p>#Kubernetes #YAML #GKE #Deployment #Pods</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=411a616b3890" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Understanding RESTful APIs: Structure, Types, and Why They Matter]]></title>
            <link>https://medium.com/@_sabagul_/understanding-restful-apis-structure-types-and-why-they-matter-dcfd1a0e4988?source=rss-72aab5678257------2</link>
            <guid isPermaLink="false">https://medium.com/p/dcfd1a0e4988</guid>
            <category><![CDATA[api-development]]></category>
            <category><![CDATA[restful-api-development]]></category>
            <category><![CDATA[flask-framework]]></category>
            <category><![CDATA[fastapi]]></category>
            <dc:creator><![CDATA[Saba Gul]]></dc:creator>
            <pubDate>Tue, 01 Oct 2024 16:04:35 GMT</pubDate>
            <atom:updated>2024-10-07T16:56:54.558Z</atom:updated>
            <content:encoded><![CDATA[<p>The modern world runs on <strong>data</strong> and <strong>communication</strong> between software systems, and RESTful APIs are at the core of that communication. Whether it’s accessing data from a cloud service, interacting with a machine learning model, or performing real-time operations across multiple devices, RESTful APIs provide a powerful and standardized way for applications to talk to each other. In this article, we’ll dive into what a RESTful API is, its structure, different types, status codes, and why it remains a critical component in modern web and software development.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/736/1*LKPn7zBS_J6VKeojE5fP6w.png" /></figure><h3><strong>What is a RESTful API?</strong></h3><p>A <strong>RESTful API</strong> (Representational State Transfer) is an architectural style for designing networked applications. It relies on HTTP protocols (the backbone of the web) and focuses on a few core principles, such as statelessness and resource manipulation via standard HTTP methods. Essentially, it allows two software systems to communicate over the web, often to exchange data, perform operations, or retrieve information.</p><p>APIs (Application Programming Interfaces) act as intermediaries that allow different software components to communicate with each other. RESTful APIs, specifically, do this in a way that is stateless, scalable, and standardized, which is why they are so widely used.</p><h3>Basic Structure of a RESTful API Request</h3><p>A typical RESTful API request structure includes several key components:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/906/1*w4_UnEli8YP0qlh86Y1kOw.png" /></figure><h3>HTTP Methods: Mapping Actions to State Changes</h3><p>In RESTful APIs, specific HTTP methods correspond to actions that manipulate the state of resources on the server. Here’s a table summarizing the common HTTP methods and their corresponding operations:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/907/1*zX20aDvn9pFoWNqpecZ42Q.png" /></figure><p>These HTTP methods follow a predictable structure, making them intuitive to use and integrate into systems across various platforms.</p><h3>HTTP Status Codes: Explained with Real-World Scenarios</h3><p>When you interact with a RESTful API, the server responds with a <strong>status code</strong> to indicate the result of the operation. These codes are crucial for understanding what happened with your request. Below is a detailed list of common HTTP status codes with real-world analogies to make them easier to grasp.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/815/1*hBc_RaRkZwkkfWZkg1Pv2A.png" /></figure><h3>Types of RESTful API Operations</h3><h4>1. GET: Read Operation</h4><p><strong>Purpose</strong>: Fetches data from the server.<br><strong>Example</strong>: A client retrieves a list of users from the system using:</p><pre>GET /users</pre><h4>2. POST: Create Operation</h4><p><strong>Purpose</strong>: Submits new data to the server and creates a new resource.<br><strong>Example</strong>: A client adds a new user:</p><pre>POST /users</pre><h4>3. PUT: Update Operation</h4><p><strong>Purpose</strong>: Replaces the data of an existing resource.<br><strong>Example</strong>: A client updates a user’s data:</p><pre>PUT /users/123</pre><h4>4. PATCH: Partial Update Operation</h4><p><strong>Purpose</strong>: Partially modifies an existing resource.<br><strong>Example</strong>: A client updates only the email address of a user:</p><pre>PATCH /users/123</pre><h4>5. DELETE: Remove Operation</h4><p><strong>Purpose</strong>: Deletes a resource from the server.<br><strong>Example</strong>: A client deletes a user from the system:</p><pre>DELETE /users/123</pre><h3>Building an API Request: A Practical Example</h3><p>Let’s break down how to construct an API request by walking through a real-world example. Suppose you’re interacting with an API that manages book records, and the endpoint is:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/642/1*8d-oIAXR4xFk9HbAV5irFA.png" /></figure><h3>Endpoint Overview:</h3><p>The base URL for this API is:</p><pre>http://localhost:1234/booksrecord/v1/titles/{book_id}</pre><p>The {book_id} part is a placeholder for a specific book’s ID, which would be replaced with an actual value. For instance, if you wanted details for a book with ID 123, the URL would look like this:</p><pre>http://localhost:1234/booksrecord/v1/titles/123</pre><h3>Adding Query Parameters:</h3><p>Now, let’s say you want to filter the books by author, publication year, and sort the results. Query parameters allow us to do just that by appending key-value pairs to the URL. In this case, we’ll add:</p><ul><li><strong>author</strong>: The author’s name (e.g., “John”).</li><li><strong>year</strong>: The publication year (e.g., 2023).</li><li><strong>sort</strong>: Whether the results should be sorted in ascending or descending order (e.g., “asc”).</li></ul><p>When we add these query parameters, the complete URL would look like:</p><pre>http://localhost:1234/booksrecord/v1/titles/123?author=John&amp;year=2023&amp;sort=asc</pre><p>This URL now fetches the details of book 123, written by &quot;John&quot;, published in 2023, and the results are sorted in ascending order.</p><h3>HTTP Method:</h3><p>The <strong>HTTP method</strong> indicates what action you’re performing. In this example, we’ll assume it’s a <strong>GET</strong> request, which is used to retrieve information. So, our final request would be:</p><pre>GET http://localhost:1234/booksrecord/v1/titles/123?author=John&amp;year=2023&amp;sort=asc</pre><h3>Sending a Body (For POST/PUT Requests):</h3><p>In case you need to create or update a book’s details, you would use a <strong>POST</strong> or <strong>PUT</strong> request. These methods often require sending a <strong>body</strong>, which contains the data to be saved. For example, here’s what the body might look like for a <strong>POST</strong> request to add a new book:</p><pre>{<br>  &quot;title&quot;: &quot;Introduction to APIs&quot;,<br>  &quot;author&quot;: &quot;John Doe&quot;,<br>  &quot;year&quot;: 2023,<br>  &quot;genre&quot;: &quot;Technology&quot;<br>}</pre><h3>Headers:</h3><p>Headers are additional pieces of information sent along with your API request, often used for authentication or specifying the format of the data. Here are some common headers you might include:</p><pre>Authorization: Bearer your_auth_token<br>Content-Type: application/json<br>Accept: application/json</pre><ul><li><strong>Authorization</strong>: For secure APIs, you’ll need an access token.</li><li><strong>Content-Type</strong>: Indicates that the request body (if any) is in JSON format.</li><li><strong>Accept</strong>: Tells the API you expect a JSON response.</li></ul><h3>Crafting RESTful APIs: Naming Conventions and Best Practices</h3><p>Creating intuitive and user-friendly RESTful APIs requires attention to naming conventions and design patterns. Here are some best practices to consider:</p><ul><li><strong>Use Descriptive Resource Names</strong>: Opt for clear, descriptive nouns that convey the purpose of each resource. For example, instead of using generic names, specify your resources as /users, /products, or /orders to enhance clarity.</li><li><strong>Employ Plural Nouns</strong>: Consistency is key. Use plural nouns for resource names to maintain a predictable API structure. For instance, /items is preferable to /item.</li><li><strong>Avoid Including Actions in Resource Names</strong>: Actions should be defined by the HTTP methods rather than embedded in the resource name. For example, use PUT /users/{userId} instead of updateUser/{userId}.</li><li><strong>Incorporate Query Parameters for Flexibility</strong>: Allow for filtering, sorting, and pagination through query parameters. For instance, /items?category=electronics&amp;sort=price.</li><li><strong>Opt for Hyphens Over Underscores</strong>: When constructing URLs, use hyphens to separate words. For example, https://api.example.com/v1/users/123/first-name is clearer and more readable than using underscores or camel case.</li></ul><h3>FastAPI vs. Flask: Industry Standards for Building RESTful APIs</h3><p>When building RESTful APIs, two popular Python web frameworks are <strong>Flask</strong> and <strong>FastAPI</strong>. Both are widely used but differ in terms of speed, ease of use, and features. Here’s a comparison of these frameworks:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/892/1*tMvOdnJPv6Ok4Nl4XsebdQ.png" /></figure><h4>1. Flask</h4><p><strong>Flask</strong> is one of the most popular Python web frameworks, known for its simplicity and flexibility. It is lightweight, making it a good choice for small to medium-sized applications, especially when you need to get something up and running quickly. Flask is designed to be easily extendable, meaning developers can pick and choose which libraries or features to add to their API.</p><p>However, Flask does not come with built-in features for things like input validation, security, or performance optimization, so developers often need to add these manually.</p><h4>2. FastAPI</h4><p><strong>FastAPI</strong> is a newer framework that’s quickly becoming popular for building fast and scalable APIs. It is built on the <strong>ASGI</strong> (Asynchronous Server Gateway Interface) standard, making it natively support asynchronous programming, which is perfect for high-performance use cases. FastAPI also uses <strong>Pydantic</strong> for automatic input validation, meaning your API can handle user inputs more safely and efficiently out-of-the-box.</p><p>Another standout feature is the <strong>automatic generation of documentation</strong> — FastAPI generates Swagger and ReDoc documentation automatically from your API endpoints, making it easier for developers to understand and test the API.</p><h3>Conclusion</h3><p>RESTful APIs have become the de facto standard for web communication due to their simplicity, scalability, and stateless nature. Understanding the structure of RESTful APIs, HTTP methods, and status codes is critical for anyone looking to work with web services or data integration across platforms. When choosing a framework for building APIs, consider your application’s performance needs and the features provided by frameworks like Flask and FastAPI.</p><p>With the increasing demand for scalable and efficient web services, mastering RESTful APIs is a valuable skill that will serve you well in many software development and data-driven fields.</p><p>#RESTfulAPI #Flask #FastAPI #PythonWebFrameworks #PythonDevelopment #FlaskVsFastAPI #FastAPITutorial #Microservices #WebServices #DataValidation #AsyncProgramming #APIManagement #SoftwareArchitecture #Developers #DataScientists #TechCommunity #TechBlog</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=dcfd1a0e4988" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Effective Ways to Remember SQL Queries: A Guide for Aspiring Data Analysts]]></title>
            <link>https://medium.com/@_sabagul_/effective-ways-to-remember-sql-queries-a-guide-for-aspiring-data-analysts-434b10ebd1c1?source=rss-72aab5678257------2</link>
            <guid isPermaLink="false">https://medium.com/p/434b10ebd1c1</guid>
            <category><![CDATA[data-analysis]]></category>
            <category><![CDATA[data-analyst]]></category>
            <category><![CDATA[memory-management]]></category>
            <category><![CDATA[querying]]></category>
            <category><![CDATA[sql]]></category>
            <dc:creator><![CDATA[Saba Gul]]></dc:creator>
            <pubDate>Sat, 10 Aug 2024 01:47:33 GMT</pubDate>
            <atom:updated>2024-08-10T01:52:07.015Z</atom:updated>
            <content:encoded><![CDATA[<p>Whether you’re just starting your journey into data analysis or looking to sharpen your SQL skills, memorizing the myriad of SQL commands — like DML, DDL, DCL, and TCL — can be daunting. However, with the right techniques, you can effectively internalize these commands and feel confident during interviews or while working on real-world projects.</p><p>In this article, we’ll explore some practical methods to help you remember SQL queries, making your learning process smoother and more enjoyable.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*i8GFeCyHyn4M9Onb-FBEGw.jpeg" /></figure><h3>Understanding the Categories: The Foundation</h3><p>Before diving into memorization techniques, it’s crucial to understand the categories of SQL commands. SQL commands are grouped into several categories based on their functionality:</p><ul><li><strong>DML (Data Manipulation Language):</strong> Used to manipulate data within tables.</li><li><strong>DDL (Data Definition Language):</strong> Used to define and modify database structures.</li><li><strong>DCL (Data Control Language):</strong> Used to control access to data.</li><li><strong>TCL (Transaction Control Language):</strong> Used to manage transactions in a database.</li></ul><p>Having a clear understanding of what each category represents will make it easier to associate commands with their functions.</p><h3>SQL Command Categories Overview</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/941/1*0Fu-kYEtidchYzlfIRqTiw.png" /></figure><h3>Association with Real-Life Scenarios</h3><p>One of the most effective memory techniques is association — linking SQL commands to real-life scenarios. Here’s how you can do it:</p><ul><li><strong>DDL (Data Definition Language):</strong> Think of DDL commands like setting up the blueprint of a building. <strong>CREATE</strong> is like laying the foundation, <strong>ALTER</strong> is like renovating, <strong>DROP</strong> is demolishing, and <strong>TRUNCATE</strong> is clearing out the building.</li><li><strong>DML (Data Manipulation Language):</strong> Imagine DML commands as activities inside the building. <strong>SELECT</strong> is like reading a book (retrieving information), <strong>INSERT</strong> is like adding a new piece of furniture (inserting new data), <strong>UPDATE</strong> is redecorating (modifying existing data), and <strong>DELETE</strong> is removing old items (deleting data).</li><li><strong>DCL (Data Control Language):</strong> Think of DCL as the security system of the building. <strong>GRANT</strong> is giving someone access, and <strong>REVOKE</strong> is taking that access away.</li><li><strong>TCL (Transaction Control Language):</strong> Consider TCL as the project manager overseeing renovations. <strong>COMMIT</strong> is finalizing the renovation, <strong>ROLLBACK</strong> is undoing a mistake, and <strong>SAVEPOINT</strong> is marking a stage of completion.</li></ul><h3>Visual Mnemonics and Mind Maps</h3><p>Creating visual mnemonics or mind maps can be a powerful way to remember SQL commands. Draw a mind map with the main categories (DDL, DML, etc.) at the center, and branch out with specific commands under each category. You can also use icons or symbols to represent each command — like a hammer for <strong>ALTER</strong> or a key for <strong>GRANT</strong>.</p><h3>Practice with Real-World Examples</h3><p>The more you practice, the better you’ll remember. Instead of rote memorization, apply each SQL command in a real-world context. Use a sample database (like an employee or retail database) and perform operations like creating tables, inserting data, updating records, and running queries.</p><p>For example:</p><ul><li><strong>CREATE</strong> a table called employees with columns for id, name, and age.</li><li><strong>INSERT</strong> a few employee records.</li><li><strong>SELECT</strong> data to view all employees older than 30.</li><li><strong>UPDATE</strong> an employee’s age, and then <strong>DELETE</strong> an employee from the table.</li></ul><p>By actively using SQL commands in practice, you’ll reinforce your memory through repetition and context.</p><h3>Flashcards and Spaced Repetition</h3><p>Flashcards are a tried-and-true method for memorization. Create a set of flashcards with SQL commands on one side and their functions or syntax on the other. Use spaced repetition — a technique where you review the flashcards at increasing intervals — to cement the knowledge in your long-term memory.</p><h3>Mnemonics for SQL Command Syntax</h3><p>To remember the syntax of SQL commands, create mnemonics or short, catchy phrases. For instance:</p><ul><li><strong>SELECT columns FROM table WHERE condition;</strong><br>Mnemonic: “<strong>S</strong>elect <strong>C</strong>olumns <strong>F</strong>rom <strong>T</strong>he <strong>W</strong>arehouse.”</li><li><strong>INSERT INTO table (columns) VALUES (values);</strong><br>Mnemonic: “<strong>I</strong>nsert <strong>T</strong>hings <strong>I</strong>nto <strong>T</strong>he <strong>V</strong>ault.”</li></ul><p>These mnemonics can act as quick mental triggers when you’re trying to recall the correct syntax.</p><h3>Teach What You Learn</h3><p>One of the most effective ways to solidify your understanding is to teach others. Explain SQL commands and concepts to a friend, classmate, or even yourself in front of a mirror. By articulating what you’ve learned, you’ll reinforce your knowledge and identify any gaps in your understanding.</p><h3>Join a Study Group or Online Community</h3><p>Engaging with others who are learning SQL can be highly beneficial. Join a study group or participate in an online community, such as a forum or a Slack group, where you can ask questions, share knowledge, and quiz each other on SQL commands.</p><h3>Real-World Projects and Challenges</h3><p>Apply your SQL skills to real-world projects or coding challenges on platforms like LeetCode, HackerRank, or Kaggle. Working through these challenges will help you remember SQL commands in the context of solving real problems.</p><h3>Conclusion</h3><p>Remembering SQL commands doesn’t have to be overwhelming. By associating commands with real-life scenarios, practicing regularly, using visual aids, and engaging with the community, you can internalize SQL commands and feel confident in your data analysis tasks.</p><p>With consistent effort and the right strategies, you’ll find that recalling SQL commands becomes second nature. So, pick up your favorite method, start practicing, and watch as your SQL skills soar!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=434b10ebd1c1" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Cooking with AI: Generating Recipes from Food Images Using LangChain and OpenAI]]></title>
            <link>https://medium.com/@_sabagul_/cooking-with-ai-generating-recipes-from-food-images-using-langchain-and-openai-3d41981a74a0?source=rss-72aab5678257------2</link>
            <guid isPermaLink="false">https://medium.com/p/3d41981a74a0</guid>
            <category><![CDATA[api-integration]]></category>
            <category><![CDATA[gen-ai-for-business]]></category>
            <category><![CDATA[langchain]]></category>
            <category><![CDATA[llm-applications]]></category>
            <category><![CDATA[openai]]></category>
            <dc:creator><![CDATA[Saba Gul]]></dc:creator>
            <pubDate>Wed, 31 Jul 2024 04:55:39 GMT</pubDate>
            <atom:updated>2024-08-16T05:34:33.749Z</atom:updated>
            <content:encoded><![CDATA[<p>In an era where artificial intelligence (AI) is transforming industries, the culinary world isn’t far behind. Imagine snapping a picture of a dish and getting a complete recipe in return! In this article, we explore how to create such an experience using cutting-edge AI tools like Hugging Face, LangChain, and OpenAI, with an added twist: a text-to-speech (TTS) feature for auditory guidance.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*lbczThKSS60nkRRhmn9nxw.jpeg" /></figure><h3>Setting the Stage: Installation and Setup</h3><p>To start, we need a few libraries:</p><ul><li><strong>Hugging Face Transformers</strong>: For image-to-text conversion.</li><li><strong>LangChain</strong>: To facilitate interaction with OpenAI models.</li><li><strong>gtts</strong>: A simple library to convert text to speech.</li></ul><p>Here’s the installation setup:</p><pre>!pip install datasets huggingface_hub -q<br>!pip install -q -U transformers<br>!pip install -q bitsandbytes==0.41.3 accelerate==0.25.0<br>!pip install langchain -q<br>!pip install openai langchain_openai -q<br>!pip install typing_extensions<br>!pip install gtts</pre><p>After installing these packages, we need to set up our API keys. For this tutorial, we’ll use OpenAI’s GPT-3.5 model, which requires an <a href="https://platform.openai.com/">API key</a> for access.</p><pre>from google.colab import userdata<br>OPENAI_API_KEY = userdata.get(&#39;OPENAI_API_KEY&#39;)</pre><h3>Logging into Huggingface</h3><p>Huggingface provides a plethora of AI models. We’ll use their platform to generate captions for our food images.</p><pre>from huggingface_hub import login<br>login()</pre><p>This step requires a Huggingface account. If you don’t have one, you can sign up <a href="https://huggingface.co/">here</a>.</p><h3>Capturing the Dish with an Image</h3><p>Let’s start by fetching an image of the dish we want to recreate. In this example, we’ll use a random image URL which is an image of buger with fries. However, you can replace this with any image URL of your choice.</p><pre>import requests<br>from PIL import Image</pre><pre>image_url = &quot;https://encrypted-tbn0.gstatic.com/images?q=tbn:ANd9GcR3ZKlfd82ogR-0YWf882ZQMQDp9dxDb9KszkCpA2WRFw&amp;s&quot;<br>image = Image.open(requests.get(image_url, stream=True).raw)<br>image</pre><p>Next, we use Hugging Face’s <a href="https://huggingface.co/Salesforce/blip-image-captioning-base">blip-image-captioning-base</a> model to describe the image and generate a caption:</p><pre>from transformers import pipeline</pre><pre>captioner = pipeline(&quot;image-to-text&quot;, model=&quot;Salesforce/blip-image-captioning-base&quot;)<br>results = captioner(image_url)<br>print(results[0][&#39;generated_text&#39;])</pre><h3>Turning Captions into Recipes: LangChain and OpenAI</h3><p>With the image caption in hand, we can now use LangChain to interface with OpenAI’s language model, generating a full recipe.</p><pre>from langchain_openai import OpenAI</pre><p>Here, we’re using the gpt-3.5-turbo model, known for its ability to handle detailed prompts effectively.</p><pre>llm = OpenAI(model_name=&quot;gpt-3.5-turbo-1106&quot;, temperature=0, max_tokens=512, openai_api_key=&#39;OPENAI_API_KEY&#39;)</pre><p>Next, we create a prompt template to guide the language model in generating the recipe.</p><pre>from langchain.prompts import PromptTemplate<br>from langchain.chains import LLMChain</pre><pre>template = &quot;&quot;&quot;Question: {question}<br>Answer: Let&#39;s think step by step,&quot;&quot;&quot;<br>prompt = PromptTemplate(template=template, input_variables=[&quot;question&quot;])<br>llm_chain = LLMChain(prompt=prompt, llm=llm)</pre><p>Finally, we invoke the model with our question, which includes the caption generated from the image.</p><pre>question = f&quot;Give me the list of ingredients and a step-by-step recipe for {results[0][&#39;generated_text&#39;]}&quot;<br>openai_results = llm_chain.invoke(question)</pre><pre>print(openai_results[&#39;text&#39;])<br>recipe_text=openai_results[&#39;text&#39;]</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*fAQgcachhpaBClMK2cbfQA.png" /></figure><h3>Text-to-Speech Conversion with gtts</h3><p>To make the cooking process even smoother, we convert the recipe text into audio. This feature is particularly useful when you’re busy with the cooking process and prefer listening to instructions.</p><pre>from gtts import gTTS</pre><pre>def text_to_speech(text, filename=&#39;recipe_audio.mp3&#39;):<br>    tts = gTTS(text=text, lang=&#39;en&#39;)<br>    tts.save(filename)<br>    print(f&quot;Audio saved as {filename}&quot;)<br>text_to_speech(recipe_text)</pre><p>The text_to_speech function saves the audio to recipe_audio.mp3, which you can listen to while cooking. This TTS feature is a game-changer for multitasking in the kitchen.</p><h3>Unleashing Culinary Creativity</h3><p>In just a few lines of code, we have created an AI-powered system that can take an image of food and turn it into a detailed recipe. This is just the beginning of what’s possible with LangChain and OpenAI. Imagine integrating this with smart kitchen devices, creating personalized meal plans, or even generating recipes based on dietary restrictions.</p><p>Imagine integrating this technology into a cooking app where users can upload images and receive recipes instantly, or using it to create unique dishes by drawing inspiration from images found online. The potential applications are endless!</p><h3>Conclusion</h3><p>By combining image recognition, natural language processing, and text-to-speech technologies, we’ve created a seamless cooking assistant that goes beyond traditional methods. This setup not only generates recipes from images but also provides audio instructions, making it accessible and convenient for everyone. Whether you’re an AI enthusiast or a cooking aficionado, this project offers a glimpse into the future of interactive and intelligent cooking aids.</p><p>For more details: <a href="https://github.com/Saba-Gul/Generating-Recipes-from-Food-Images-Using-LangChain-and-OpenAI/blob/main/Cooking_With_AI.ipynb">Colab Notebook</a></p><p>Try it out: <a href="https://sabagul-cooking-with-ai-recipebot.hf.space/">https://sabagul-cooking-with-ai-recipebot.hf.space</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=3d41981a74a0" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Mastering Machine Learning Deployment with Google Cloud: A Beginner’s Guide (Part I)]]></title>
            <link>https://medium.com/@_sabagul_/mastering-machine-learning-deployment-with-google-cloud-a-beginners-guide-part-i-3899cb9d7d73?source=rss-72aab5678257------2</link>
            <guid isPermaLink="false">https://medium.com/p/3899cb9d7d73</guid>
            <category><![CDATA[vertex-ai]]></category>
            <category><![CDATA[deployment-automation]]></category>
            <category><![CDATA[google-cloud-platform]]></category>
            <category><![CDATA[machine-learning]]></category>
            <category><![CDATA[mlops-platform]]></category>
            <dc:creator><![CDATA[Saba Gul]]></dc:creator>
            <pubDate>Tue, 16 Jul 2024 16:19:19 GMT</pubDate>
            <atom:updated>2024-07-16T16:19:19.422Z</atom:updated>
            <content:encoded><![CDATA[<p>Machine Learning (ML) model deployment is a crucial step towards making your models accessible and operational for real-world applications. Google Cloud Platform (GCP) offers robust tools like AI Platform and Vertex AI, supported by the gcloud command-line interface (CLI), to streamline the deployment process. In this guide, we’ll walk through the essential gcloud commands for serving and deploying ML models on GCP.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*hsyJRgqYqR3qxJPRpL1Yjw.jpeg" /></figure><h3><strong>Getting Started</strong></h3><ol><li><strong>Install and Set Up gcloud CLI</strong>:</li></ol><pre>Copy codecurl https://sdk.cloud.google.com | bash<br>exec -l $SHELL<br>gcloud init</pre><p><strong>Purpose</strong>: Sets up the gcloud command-line interface (CLI) on your computer to manage Google Cloud services.</p><p><strong>Explanation</strong>:</p><ul><li>Use curl to download and install the Google Cloud SDK.</li><li>exec -l $SHELL ensures the command-line interface recognizes the newly installed SDK.</li><li>gcloud init starts the setup process, helping you log in, set preferences, and link to your GCP project.</li></ul><p><strong>2. Authenticate and Configure Your Project</strong>:</p><pre>gcloud auth login gcloud config set project PROJECT_ID</pre><p><strong>Purpose</strong>: Logs you into Google Cloud and links your local environment to your GCP project.</p><p><strong>Explanation</strong>:</p><ul><li>gcloud auth login opens a browser for you to sign in with your Google account.</li><li>gcloud config set project PROJECT_ID sets the default project for future gcloud commands.</li></ul><h3>Using Google Cloud Storage (GCS)</h3><p><strong>Store and Manage Model Artifacts</strong>:</p><pre>gsutil mb gs://your-bucket-name<br>gsutil cp model.joblib gs://your-bucket-name/models/</pre><ul><li><strong>Purpose</strong>: Manages storage buckets in Google Cloud Storage (GCS) for storing your model files securely.</li><li><strong>Explanation</strong>:</li><li>gsutil mb gs://your-bucket-name creates a new bucket for storing data and models.</li><li>gsutil cp model.joblib gs://your-bucket-name/models/ copies your model file (model.joblib) to the bucket for easy access and deployment.</li></ul><h3>AI Platform (AI Platform Classic)</h3><ol><li><strong>Deploy Your Model</strong>:</li></ol><pre>gcloud ai-platform models create MODEL_NAME<br>gcloud ai-platform versions create VERSION_NAME \<br>    --model=MODEL_NAME \<br>    --origin=gs://your-bucket-name/models/ \<br>    --runtime-version=2.1 \<br>    --framework=SCIKIT_LEARN \<br>    --python-version=3.7</pre><p><strong>Purpose</strong>: Deploys your machine learning model on Google AI Platform with specific configurations.</p><p><strong>Explanation</strong>:</p><ul><li>gcloud ai-platform models create MODEL_NAME creates a new model container on AI Platform.</li><li>gcloud ai-platform versions create VERSION_NAME \ ... sets up a new version of your model with details like where it&#39;s stored (--origin), which framework it uses (--framework), and its runtime environment (--runtime-version).</li></ul><p><strong>2. Manage Your Deployments</strong>:</p><pre>gcloud ai-platform models list<br>gcloud ai-platform versions list --model=MODEL_NAME<br>gcloud ai-platform versions delete VERSION_NAME --model=MODEL_NAME</pre><p><strong>Purpose</strong>: Lists, views, and deletes models and their versions on AI Platform.</p><p><strong>Explanation</strong>:</p><ul><li>gcloud ai-platform models list shows all models deployed on AI Platform.</li><li>gcloud ai-platform versions list --model=MODEL_NAME lists versions of a specific model.</li><li>gcloud ai-platform versions delete VERSION_NAME --model=MODEL_NAME removes a version of a model, helpful for managing updates and maintenance.</li></ul><h3>Vertex AI (AI Platform Unified)</h3><ol><li><strong>Simplify Deployment with Vertex AI</strong>:</li></ol><pre>gcloud ai models upload \<br>    --region=REGION \<br>    --display-name=MODEL_DISPLAY_NAME \<br>    --artifact-uri=gs://your-bucket-name/models/</pre><p><strong>Purpose</strong>: Streamlines deploying machine learning models on Vertex AI, providing a unified and scalable platform.</p><p><strong>Explanation</strong>:</p><ul><li>gcloud ai models upload \ ... uploads your model to Vertex AI, specifying its display name (--display-name) and location in GCS (--artifact-uri).</li></ul><p><strong>2. Create Endpoints and Deploy Models</strong>:</p><pre>gcloud ai endpoints create --region=REGION --display-name=ENDPOINT_DISPLAY_NAME<br><br>gcloud ai endpoints deploy-model ENDPOINT_ID \<br>    --model=MODEL_ID \<br>    --region=REGION \<br>    --display-name=DEPLOYED_MODEL_DISPLAY_NAME \<br>    --machine-type=n1-standard-4</pre><p><strong>Purpose</strong>: Sets up endpoints and deploys models on Vertex AI for making predictions in real-time.</p><p><strong>Explanation</strong>:</p><ul><li>gcloud ai endpoints create --region=REGION --display-name=ENDPOINT_DISPLAY_NAME creates an endpoint for hosting models in the specified region.</li><li>gcloud ai endpoints deploy-model ENDPOINT_ID \ ... deploys a model (MODEL_ID) to an endpoint (ENDPOINT_ID), setting its display name (--display-name) and specifying the machine type for handling predictions (--machine-type).</li></ul><h3>Predictions and Monitoring</h3><ol><li><strong>Make Predictions Effortlessly</strong>:</li></ol><pre>gcloud ai-platform predict \<br>    --model=MODEL_NAME \<br>    --version=VERSION_NAME \<br>    --json-instances=request.json<br><br>gcloud ai-platform jobs submit prediction JOB_NAME \<br>    --model=MODEL_NAME \<br>    --version=VERSION_NAME \<br>    --input-paths=gs://your-bucket-name/input.json \<br>    --output-path=gs://your-bucket-name/output/ \<br>    --region=REGION \<br>    --data-format=JSON</pre><p><strong>Purpose</strong>: Performs online and batch predictions on AI Platform.</p><p><strong>Explanation</strong>:</p><ul><li>gcloud ai-platform predict \ ... sends a prediction request (request.json) to a specific version (VERSION_NAME) of a model (MODEL_NAME).</li><li>gcloud ai-platform jobs submit prediction JOB_NAME \ ... submits a batch prediction job (JOB_NAME) to process input data (input.json) and store results in GCS (gs://your-bucket-name/output/) using JSON format.</li></ul><p><strong>2. Monitor and Optimize Performance</strong>:</p><pre>gcloud logging read &quot;resource.type=gce_instance AND logName=projects/PROJECT_ID/logs/LOG_ID&quot; --limit=10</pre><p><strong>Purpose</strong>: Monitors model performance and troubleshoots issues using logs.</p><p><strong>Explanation</strong>: gcloud logging read \ ... retrieves logs (LOG_ID) from specific Google Compute Engine instances (resource.type=gce_instance) associated with your project (PROJECT_ID), limiting results to the last 10 logs (--limit=10).</p><h3>Conclusion: Unleashing the Power of AI with GCP</h3><p>Deploying ML models on Google Cloud using gcloud commands streamlines the process, enabling scalable and reliable solutions for various applications. Whether using AI Platform Classic or Vertex AI, these commands provide essential tools for managing and scaling machine learning deployments in a cloud environment.</p><p>For further exploration and advanced features, refer to the <a href="https://cloud.google.com/sdk/docs">Google Cloud documentation</a>. Start deploying your models today and unlock the potential of machine learning in the cloud!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=3899cb9d7d73" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Understanding YAML for Machine Learning: A Beginner’s Guide]]></title>
            <link>https://medium.com/@_sabagul_/understanding-yaml-for-machine-learning-a-beginners-guide-9362a20b8c67?source=rss-72aab5678257------2</link>
            <guid isPermaLink="false">https://medium.com/p/9362a20b8c67</guid>
            <category><![CDATA[machine-learning]]></category>
            <category><![CDATA[ml-for-beginners]]></category>
            <category><![CDATA[mlops]]></category>
            <category><![CDATA[yamlforml]]></category>
            <category><![CDATA[yaml]]></category>
            <dc:creator><![CDATA[Saba Gul]]></dc:creator>
            <pubDate>Fri, 05 Jul 2024 15:57:04 GMT</pubDate>
            <atom:updated>2024-08-14T04:18:38.115Z</atom:updated>
            <content:encoded><![CDATA[<p>YAML, which stands for “YAML Ain’t Markup Language,” is a human-readable data serialization standard that is widely used for configuration files and data exchange between programming languages. If you’re venturing into the world of machine learning, understanding YAML can significantly streamline your workflow. This guide will walk you through the essentials of YAML, with a focus on applications in machine learning.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*gmBWenwaTHHvWjguRI8ldg.jpeg" /></figure><h3>Why YAML?</h3><p>YAML’s simplicity and readability make it a popular choice for configuration files and data serialization in machine learning projects. Unlike other data formats like JSON or XML, YAML is designed to be easy to read and write, making it ideal for settings and parameter files.</p><h3>Basic Syntax of YAML</h3><p>Understanding the basic syntax of YAML is the first step in mastering it. Here’s a quick overview:</p><h3>Key-Value Pairs</h3><p>At its core, YAML is composed of key-value pairs. A key is followed by a colon and a space, and then the value.</p><pre>key: value</pre><h3>Nested Key-Value Pairs</h3><p>YAML uses indentation to represent nested structures. Each level of indentation corresponds to a level of nesting.</p><pre>parent_key:<br>  child_key: value</pre><h3>Lists</h3><p>Lists are represented with a dash followed by a space before each item.</p><pre>list:<br>  - item1<br>  - item2<br>  - item3</pre><h3>Common Use Cases in Machine Learning</h3><p>YAML is incredibly useful in various aspects of machine learning projects. Here are some common use cases:</p><h3>1. Configuration Files</h3><p>Configuration files in YAML are used to set up environments, define hyperparameters, and specify dataset paths.</p><pre>model:<br>  type: RandomForest<br>  parameters:<br>    n_estimators: 100<br>    max_depth: 10<br>dataset:<br>  path: /data/dataset.csv<br>  split:<br>    train: 0.8<br>    validation: 0.1<br>    test: 0.1</pre><h3>2. Defining Pipelines</h3><p>Machine learning workflows often involve multiple steps, such as data loading, preprocessing, and model training. YAML can be used to define these steps in a clear and organized manner.</p><pre>pipeline:<br>  steps:<br>    - name: load_data<br>      parameters:<br>        path: /data/dataset.csv<br>    - name: preprocess<br>      parameters:<br>        method: standardize<br>    - name: train_model<br>      parameters:<br>        model_type: RandomForest<br>        hyperparameters:<br>          n_estimators: 100<br>          max_depth: 10</pre><h3>3. Environment Configuration</h3><p>Setting up consistent environments is crucial for reproducibility. YAML can specify Python versions and dependencies.</p><pre>environment:<br>  python_version: 3.8<br>  dependencies:<br>    - numpy<br>    - pandas<br>    - scikit-learn<br>    - tensorflow</pre><h3>Tips for Writing YAML</h3><ol><li><strong>Use Consistent Indentation</strong>: YAML uses spaces (not tabs) for indentation. Typically, two spaces per level of indentation are recommended.</li><li><strong>Quotes for Strings</strong>: Use quotes for strings that contain special characters or spaces.</li></ol><pre>string: &quot;Hello, World!&quot;</pre><p><strong>3. Multi-Line Strings</strong>: Use | or &gt; for multi-line text.</p><pre>description: |<br>  This is a multi-line<br>  string in YAML.</pre><h3>Advanced Features</h3><h3>Anchors and Aliases</h3><p>YAML allows you to reuse and reference data within the file using anchors (&amp;) and aliases (*).</p><pre><br>default: &amp;default<br>  type: RandomForest<br>  parameters:<br>    n_estimators: 100<br>    max_depth: 10<br><br>model1:<br>  &lt;&lt;: *default<br>  parameters:<br>    max_depth: 20</pre><h3>Merge Key</h3><p>The merge key &lt;&lt; allows combining multiple mappings.</p><pre>default_settings: &amp;default<br>  learning_rate: 0.01<br>  batch_size: 32<br><br>model_config:<br>  &lt;&lt;: *default<br>  epochs: 50</pre><h3>Validation Tools</h3><p>To ensure your YAML files are correctly formatted, use tools like <strong>YAML Lint</strong> or integrated IDE support (e.g., VSCode extensions).</p><h3>How to Use YAML Lint</h3><h4>Online Tools</h4><p>Several online tools, such as <a href="http://www.yamllint.com/">yamllint.com</a>, allow you to paste your YAML code into a web interface for instant validation.</p><ol><li><strong>Paste your YAML code</strong> into the provided text box.</li><li><strong>Click the “Lint” button</strong> to check for errors.</li><li><strong>Review the results</strong> to see any syntax errors or formatting issues highlighted.</li></ol><h4>Command Line Tools</h4><p>You can also use command line tools like yamllint for local validation.</p><ol><li><strong>Install <em>yamllint</em>:</strong></li></ol><pre>pip install yamllint</pre><p><strong>2. Run <em>yamllint</em> on a YAML file</strong>:</p><pre>yamllint yourfile.yaml</pre><p><strong>3. Review the output</strong> to identify and fix any errors.</p><h3>Benefits of Using YAML Lint</h3><ul><li><strong>Error Prevention</strong>: Helps catch syntax errors before they cause issues in your projects.</li><li><strong>Consistency</strong>: Ensures your YAML files are consistently formatted, making them easier to read and maintain.</li><li><strong>Efficiency</strong>: Saves time by quickly identifying and highlighting problems in your YAML code.</li></ul><p>By integrating YAML Lint into your workflow, you can improve the reliability and maintainability of your YAML configurations, ultimately leading to smoother project execution.</p><h3>Example in an ML Project</h3><p>Let’s put it all together with an example YAML configuration for a machine learning project:</p><pre># Project information<br>project:<br>  name: MyMLProject<br>  author: Saba Gul<br><br># Environment configuration<br>environment:<br>  python_version: 3.8<br>  dependencies:<br>    - numpy<br>    - pandas<br>    - scikit-learn<br>    - tensorflow<br><br># Dataset configuration<br>dataset:<br>  path: /data/dataset.csv<br>  split:<br>    train: 0.7    # 70% for training<br>    validation: 0.2    # 20% for validation<br>    test: 0.1    # 10% for testing<br><br># Model configuration<br>model:<br>  type: RandomForest<br>  parameters:<br>    n_estimators: 100<br>    max_depth: 10<br>  training:<br>    epochs: 50<br>    batch_size: 32<br><br># Logging configuration (Optional)<br>logging:<br># Specifies the file path where logs will be stored (/logs/ml_logs.log in this example).<br>  file_path: /logs/ml_logs.log<br># Sets the logging level to INFO, which determines the severity of messages to log.<br>  level: INFO<br># Defines the format of log messages, including timestamp, log level, and message content.<br>  format: &#39;%(asctime)s - %(levelname)s - %(message)s&#39;</pre><h3>Conclusion</h3><p>YAML’s simplicity and readability make it an excellent choice for managing configurations and data in machine learning projects. Whether you are defining hyperparameters, setting up your environment, or structuring your data processing pipeline, YAML can help keep your project organized and easy to understand.</p><p>By mastering the basics of YAML and exploring its advanced features, you can enhance your productivity and ensure the reproducibility of your machine learning projects.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=9362a20b8c67" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Building an Image Recognition App in 10 Minutes]]></title>
            <link>https://medium.com/@_sabagul_/building-an-image-recognition-app-in-10-minutes-9c0828bd4b6b?source=rss-72aab5678257------2</link>
            <guid isPermaLink="false">https://medium.com/p/9c0828bd4b6b</guid>
            <category><![CDATA[no-code-development]]></category>
            <category><![CDATA[chatgpt]]></category>
            <category><![CDATA[vision-api]]></category>
            <category><![CDATA[chatgpt4o-powered-app]]></category>
            <category><![CDATA[bubble-io]]></category>
            <dc:creator><![CDATA[Saba Gul]]></dc:creator>
            <pubDate>Fri, 14 Jun 2024 16:03:42 GMT</pubDate>
            <atom:updated>2024-08-03T16:05:44.993Z</atom:updated>
            <content:encoded><![CDATA[<h4>Bubble.io x OpenAI</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*ouge1DF_jjtNfibB_74rqQ.jpeg" /></figure><h4>Prerequisites:</h4><ol><li><strong>Bubble.io Account</strong>: Sign up at <a href="https://bubble.io/">Bubble.io</a> if you haven’t already.</li><li><strong>OpenAI API Key</strong>: Obtain an API key for GPT-4o through OpenAI.</li><li><strong>Basis App Extension</strong>: Install the <a href="https://www.basislab.io/">Basis app extension </a>in Bubble.io for easy integration.</li></ol><h4>Step 1: Setting Up Your Bubble.io Project</h4><p><strong>Create a New Bubble Application</strong>:</p><ul><li>Log in to your Bubble.io account.</li><li>Click on “Create an App” to start a new project.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Q739r_BGv-8d6A2xkLHbhQ.png" /></figure><h4>Step 2: Installing the Basis App Extension</h4><p><strong>Install Basis App Extension</strong>:</p><ul><li>Install the Basis Lab extension which helps Bubble.io developers build professional looking web applications with it’s pre-built UI components and template pages.</li><li>Search for “Basis Lab” on chrome webstore and click “Install”.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*vgHVW4Vsp8Swx-5eFYs52Q.png" /></figure><h4>Step 3: Setting Up OpenAI Integration</h4><ol><li><strong>Obtain OpenAI API Key</strong>:</li></ol><ul><li>Visit OpenAI’s website to obtain an API key for the GPT-4 vision API.</li></ul><p><strong>2. Configure API Connector in Bubble.io</strong>:</p><ul><li>In your Bubble.io editor, go to “Plugins” -&gt; “API Connector” and install it.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*gr-4wJ1M6syeX7Lkfqyowg.png" /></figure><ul><li>Click on “Add another API” and enter details for the OpenAI API:</li><li><strong>API name</strong>: OpenAI Vision API</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*LUrUFXXnyhgdmfu7PwrbxQ.png" /></figure><p><strong>3. Configure Connection With OpenAI Vision API</strong></p><ul><li>For integrtating the app with the ChatGPT 4o, Click on import another call from cURL and copy the <a href="https://platform.openai.com/docs/guides/vision?lang=curl">cURL command</a> and paste it in Import From cURL dialog box.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*HL3NwN-VFbbdTNe6nejrcw.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/497/1*h-HQl0x1x99MahlasZcFlw.png" /></figure><ul><li>We modify the cURL call from Use as “Data” to “Action”.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*vDRd55C9GmMmIdRkEHljEg.png" /></figure><ul><li>Now modify the body of the JSON so that users can enter their own prompt and upload images to the app. Copy the url from the image_url given in the cURL command and place it in the key value of input_image. Simmilarly, replace the value for user_prompt and uncheck the private placeholder infront of both keys.</li><li>Click on the Initailize call dialog box and after a successful API call, press the save button and now our API call is initialized.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*81ZavsEhzszOyIltAUW3Qw.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*mH4mlN4Z3zPZR7I2bl5-Jw.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*u7xUG_aImrAdvLlD545Erw.png" /></figure><h4>Step 4: Designing the User Interface (UI)</h4><p><strong>Create Input and Output Elements</strong>:</p><ul><li>After creating the app in bubble, the design tab will open by defualt. Click on the Basis lab extension.</li><li>Use Basis lab extension for intuitive UI elements that connect seamlessly with your backend.</li><li>In the Basis Lab, go to <em>Blocks</em>, copy the <em>input/output shell</em> and paste it in the design tab of bubble app.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*8EzqPVJch_bAOfzyMT9kFA.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*B3tsFsjLNDsfxJU6b3_Ifg.png" /></figure><h4>Step 5: Configuring Workflow Actions</h4><p><strong>Define Workflow for Image Processing</strong>:</p><ul><li>Now click on the Run button in the UI, then click on the add workflow.</li><li>Use Bubble.io workflows to trigger API calls to OpenAI’s GPT-4 vision API through the API Connector. To do this, while in the workflow tab, right click, you get a drop down menu, from which you should select: plugins and add the API you initialized earlier.</li><li>Now set up the dynamic values in the API call’s workflow which matches the design inputs as shown in the dialogbox on the right. Remeber to add <em>https:</em> before the dynamic value in the <em>user-image</em> dialog box.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*1rzvlHT0loeSFI2aoFpEow.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/710/1*DYUKjHKn3kTDu2E-3FreSA.png" /></figure><ul><li>Now click on <em>click here to add action </em>-&gt;<em> Element Actions</em> -&gt; <em>set state</em> and set state to the name of the page which is <em>input-ouput-1</em> in the <em>element</em> dialog box. In the <em>custom state</em>, select <em>create a new custom state</em> and name it and set the<em> state type</em> as <em>text</em>.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*PxtdyZcLcamohWeLA8xpZQ.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/550/1*tVTwQzyKVq41aNokmmeplw.png" /></figure><ul><li>So when we click the Run button, it calls the API and its going to set a state. Modify the Value to <em>Result of Step 1(Name of API) </em>-&gt; <em>choices </em>-&gt; :first item-&gt; <em>message-content.</em></li><li>Now, we have saved the reponse from to the API call to have it displayed on the same page.</li><li>For the ouput reponse, we go to the design tab of our app, click on the <em>model ouput placeholder</em>-&gt; <em>insert data dynamically</em> and set it to the name of the page which in our case is <em>input-output-1-&gt;cutom state name (model-response).</em></li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*el-VIA0YJFZvf8du5JZy1w.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*XhCXq5yTj03z5jEaClCxWQ.png" /></figure><h4>Step 6: Testing and Deployment</h4><ol><li><strong>Test Your Application</strong>:</li></ol><ul><li>Use Bubble.io’s built-in preview mode to test your app.</li><li>Upload various images to see how accurately the GPT-4 vision API recognizes objects.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*u786RPauuqBvw46H000kqg.png" /></figure><p><strong>2. Deploy Your Application</strong>:</p><ul><li>Once satisfied with testing, deploy your Bubble.io application.</li><li>Consider optimization and user experience improvements based on feedback.</li></ul><h4>Step 7: Continuous Improvement</h4><p><strong>Iterate Based on Feedback</strong>:</p><ul><li>Gather user feedback and analytics to refine your app.</li><li>Improve UI/UX, add features, or optimize backend processes as needed.</li></ul><h3>Conclusion</h3><p>By following these steps, you can create a sophisticated image recognition app using Bubble.io, OpenAI’s GPT-4 vision API, and the Basis app extension for intuitive UI design. This no-code approach allows you to focus on functionality and user experience without delving into complex coding tasks.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=9c0828bd4b6b" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Democratizing Machine Learning with PyCaret: A Low-Code Approach]]></title>
            <link>https://medium.com/@_sabagul_/democratizing-machine-learning-with-pycaret-a-low-code-approach-95e9efc496f9?source=rss-72aab5678257------2</link>
            <guid isPermaLink="false">https://medium.com/p/95e9efc496f9</guid>
            <category><![CDATA[deploying-model]]></category>
            <category><![CDATA[feature-importance]]></category>
            <category><![CDATA[pycaret]]></category>
            <category><![CDATA[machine-learning]]></category>
            <category><![CDATA[low-code-machine-learning]]></category>
            <dc:creator><![CDATA[Saba Gul]]></dc:creator>
            <pubDate>Mon, 27 May 2024 20:47:12 GMT</pubDate>
            <atom:updated>2024-08-03T15:59:00.413Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*bR0POCzBZXoKK8s9SWXX3w.jpeg" /></figure><p>In the ever-evolving world of data science, machine learning (ML) has become an indispensable tool for extracting insights and making informed decisions. However, the complexity of ML workflows can often deter individuals without extensive coding experience. This is where low-code libraries like PyCaret come to the rescue.</p><p>PyCaret is an open-source, low-code machine learning library in Python that streamlines the entire ML lifecycle, from data preparation to model deployment. It empowers users of all skill levels to build and experiment with various ML models efficiently, even without extensive coding knowledge.</p><h3><strong>Key Features of PyCaret:</strong></h3><ul><li><strong>Modular Design:</strong> PyCaret is organized into well-defined modules that encapsulate specific ML tasks, making it easy to navigate and use.</li><li><strong>Intuitive Functions:</strong> Each module provides a set of functions that perform specific actions within the workflow, ensuring consistency and clarity.</li><li><strong>Streamlined Data Preprocessing:</strong> PyCaret offers a wide range of data preprocessing functions, including handling missing values, scaling features, and feature engineering.</li><li><strong>Comprehensive Model Training:</strong> The library supports a diverse set of ML algorithms, allowing you to experiment with different models and find the best fit for your problem.</li><li><strong>Model Explainability:</strong> PyCaret provides tools to understand the behavior and decision-making processes of your models, fostering trust and transparency.</li><li><strong>MLOps Integration:</strong> PyCaret facilitates model deployment and monitoring, enabling you to put your models into production and track their performance.</li></ul><h3><strong>Benefits of Using PyCaret:</strong></h3><ul><li><strong>Reduced Development Time:</strong> By automating many ML tasks, PyCaret significantly reduces the time it takes to build and deploy models.</li><li><strong>Improved Efficiency:</strong> Users can focus on the core aspects of the ML process, such as data analysis and model interpretation, rather than spending time on low-level coding.</li><li><strong>Accessibility:</strong> PyCaret makes ML more accessible to a wider audience, including those with limited coding experience.</li></ul><h3><strong>Getting Started with PyCaret:</strong></h3><h4>Step 1: Installing PyCaret</h4><p>Before we begin, we need to install PyCaret. You can do this using pip:</p><pre># Install PyCaret with all dependencies<br>!pip install pycaret[full]</pre><h4>Step 2: Importing Necessary Libraries</h4><p>After installing PyCaret, import the necessary modules. We’ll use PyCaret’s classification module since the Iris dataset is a classification problem.</p><pre>from pycaret.classification import *<br>from pycaret.datasets import get_data</pre><h4>Step 3: Loading the Iris Dataset</h4><p>PyCaret makes it easy to load datasets with its get_data function. Here, we load the Iris dataset, which is included with PyCaret.</p><pre># Load the Iris dataset<br>data = get_data(&#39;iris&#39;)</pre><h4>Step 4: Initializing the Setup</h4><p>The setup function initializes the environment in PyCaret. It performs data preprocessing, handles missing values, and prepares the data for modeling. We specify the dataset and the target variable (&#39;species&#39;).</p><pre># Initialize the setup<br>clf_setup = setup(data=data, target=&#39;species&#39;, session_id=123)</pre><h4>Step 5: Comparing Models</h4><p>PyCaret allows you to compare multiple models with ease. The compare_models function trains and evaluates several models, returning the best one based on a default metric (accuracy for classification).</p><pre># Compare models and select the best model<br>best_model = compare_models()</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/860/1*FxKnZN07YaNj3sZ5htbteA.png" /><figcaption>Comparison report of different classification models is generated with the best models highlighted</figcaption></figure><h4>Step 6: Creating and Evaluating a Specific Model</h4><p>Once the best model is identified, you can create a specific model using the create_model function. Although, Logistic regression shows the best performance, Here we choose a Random Forest model (&#39;rf&#39;).</p><pre># Create a Random Forest model<br>rf_model = create_model(&#39;rf&#39;)</pre><pre># Evaluate the model<br>evaluate_model(rf_model)</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/542/1*I47B9v2egPHi0EknaYe_HQ.png" /><figcaption>Evaluation results of Random Forest on Iris dataset</figcaption></figure><p>An interseting feature of Pycaret is how you get to visualize the metrics for evaluating the model by running a single line of code.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*AONg2JMJXGbAt5k_bdtP-g.png" /><figcaption>AUC plot of the trained model</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*_vsgb5aEyadChyQaYCQouw.png" /><figcaption>Decision boundries of the trained model</figcaption></figure><h4>Step 7: Model Interpretation and Visualization</h4><p>Interpreting and visualizing the model is crucial for understanding its performance. PyCaret provides easy-to-use functions for this purpose.</p><p>The interpret_model() function in PyCaret provides visualizations to help understand the predictions made by the Random Forest model, such as feature importance and SHAP (SHapley Additive exPlanations) plots.</p><pre># Model Interpretation<br>interpret_model(rf_model)</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/871/1*C7uVJApM-3rNqWsD93miaA.png" /></figure><pre># Plot confusion matrix and feature importance<br>plot_model(rf_model, plot=&#39;confusion_matrix&#39;)<br>plot_model(rf_model, plot=&#39;feature&#39;)</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/638/1*Zsn_FGVhLBy7BSkVebaO_w.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/607/1*i4Y2SGZJ6-jRw47urNzL1Q.png" /></figure><h4>Step 8: Finalizing and Saving the Model</h4><p>Before deploying the model, finalize it using the finalize_model function. This locks the model, preventing further changes. The model can then be saved with the save_model function.</p><pre># Finalize the model<br>final_model = finalize_model(rf_model)</pre><pre># Save the model<br>save_model(final_model, &#39;iris_classifier&#39;)</pre><h4>Step 9: Deployment</h4><p>PyCaret supports deploying models to various platforms.</p><pre># Deploy the model<br>deploy_model(final_model, model_name=&#39;iris_classifier&#39;, platform=&#39;aws&#39;, authentication=&#39;aws_credent</pre><h4>Full Code for Reference</h4><p>Here is the complete code for the workflow:</p><pre># Install PyCaret with all dependencies<br>!pip install pycaret[full]<br><br># Import necessary libraries<br>from pycaret.classification import *<br>from pycaret.datasets import get_data<br><br># Load the Iris dataset<br>data = get_data(&#39;iris&#39;)<br><br># Initialize the setup<br>clf_setup = setup(data=data, target=&#39;species&#39;, session_id=123)<br><br># Compare models and select the best model<br>best_model = compare_models()<br><br># Create a specific model (e.g., Random Forest)<br>rf_model = create_model(&#39;rf&#39;)<br><br># Evaluate the model<br>evaluate_model(rf_model)<br><br># Model Interpretation<br>interpret_model(rf_model)<br><br># Plot confusion matrix and feature importance<br>plot_model(rf_model, plot=&#39;confusion_matrix&#39;)<br>plot_model(rf_model, plot=&#39;feature&#39;)<br><br># Finalize the model<br>final_model = finalize_model(rf_model)<br><br># Save the model<br>save_model(final_model, &#39;iris_classifier_rf&#39;)<br><br># Deploy the model<br>deploy_model(final_model, model_name=&#39;iris_classifier_rf&#39;, platform=&#39;aws&#39;, authentication=&#39;aws_credentials.json&#39;)</pre><h3><strong>Conclusion:</strong></h3><p>PyCaret is a powerful low-code solution that democratizes ML by making it accessible to a wider audience. With its intuitive interface and comprehensive features, it simplifies the ML process and empowers users to build and deploy models efficiently.</p><p><strong>Additional Considerations:</strong></p><ul><li><strong>Advanced Customization:</strong> While PyCaret offers extensive functionality, it’s important to remember that it’s a low-code framework. For highly customized or complex ML projects, you may need to delve deeper into Python coding.</li><li><strong>Model Selection:</strong> PyCaret provides a good starting point for model selection, but it’s crucial to understand the strengths and limitations of different algorithms and choose the best fit for your specific problem.</li><li><strong>Data Quality:</strong> As with any ML project, data quality is paramount. Ensure your data is clean, well-structured, and representative of the problem you’re trying to solve.</li></ul><p>By leveraging PyCaret’s capabilities and addressing these considerations, you can effectively build and deploy ML models, even with limited coding experience.</p><p>#PyCaret #MachineLearning #ModelEvaluation</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=95e9efc496f9" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>