<?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 Stavros Theocharis on Medium]]></title>
        <description><![CDATA[Stories by Stavros Theocharis on Medium]]></description>
        <link>https://medium.com/@stavrostheocharis?source=rss-216e390c9a41------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*atlV5Yk8mtyG1YQrGg5vuQ.png</url>
            <title>Stories by Stavros Theocharis on Medium</title>
            <link>https://medium.com/@stavrostheocharis?source=rss-216e390c9a41------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Wed, 18 Nov 2026 05:30:35 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@stavrostheocharis/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[Auto-Streamlit Studio]]></title>
            <link>https://pub.towardsai.net/auto-streamlit-studio-baa50121fe53?source=rss-216e390c9a41------2</link>
            <guid isPermaLink="false">https://medium.com/p/baa50121fe53</guid>
            <category><![CDATA[genai]]></category>
            <category><![CDATA[openai]]></category>
            <category><![CDATA[llm]]></category>
            <category><![CDATA[streamlit]]></category>
            <category><![CDATA[python]]></category>
            <dc:creator><![CDATA[Stavros Theocharis]]></dc:creator>
            <pubDate>Sun, 30 Jun 2024 18:02:40 GMT</pubDate>
            <atom:updated>2024-06-30T18:02:40.207Z</atom:updated>
            <content:encoded><![CDATA[<h4>The next generation of Streamlit automation with the support of GenAI</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/600/1*CEIyUtz_uXjF3b8yFJnopQ.gif" /></figure><h3>Introduction</h3><p>In the rapidly evolving landscape of web application development and artificial intelligence, having the right tools at your disposal can significantly streamline your workflow and boost productivity. Enter <strong>AutoStreamlit Studio</strong>, an intelligent assistant designed to simplify the creation of Streamlit applications. Whether you’re a seasoned developer or just starting, <strong>AutoStreamlit Studio</strong> automates the process of generating, customizing, and running Streamlit apps based on your specific requirements with <strong>GenAI</strong> technology.</p><blockquote>You can create everything you have in your mind in a fully automated manner. The limit is only your imagination!</blockquote><p>This article will provide an in-depth overview of <strong>AutoStreamlit Studio</strong>, its features, usage guide, and potential impact on your development process.</p><p>You can access both the <a href="https://github.com/stavrostheocharis/auto-streamlit-studio">github repository</a> and the <a href="https://auto-stream-studio.streamlit.app/">app deployed on Streamlit cloud</a>.</p><p>Check out also my <a href="https://www.youtube.com/watch?v=YYHxokV76aw">Youtube video tutorial of the app</a>:</p><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fwww.youtube.com%2Fembed%2FYYHxokV76aw%3Ffeature%3Doembed&amp;display_name=YouTube&amp;url=https%3A%2F%2Fwww.youtube.com%2Fwatch%3Fv%3DYYHxokV76aw&amp;image=https%3A%2F%2Fi.ytimg.com%2Fvi%2FYYHxokV76aw%2Fhqdefault.jpg&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;schema=youtube" width="640" height="480" frameborder="0" scrolling="no"><a href="https://medium.com/media/20753c3abe17017fd0218ec2afb587f9/href">https://medium.com/media/20753c3abe17017fd0218ec2afb587f9/href</a></iframe><h3>The Evolution of Streamlit Applications</h3><p><strong>Streamlit</strong> has become a popular choice for developers due to its simplicity and power in creating web applications for data visualization, machine learning, and interactive dashboards. However, despite its capabilities, building complex Streamlit apps can still be time-consuming and challenging, especially for those new to the framework. This is where <strong>AutoStreamlit Studio</strong> comes into play, offering an innovative solution to these challenges by automating much of the development process.</p><h3>What is AutoStreamlit Studio?</h3><p><strong>AutoStreamlit Studio </strong>is a cutting-edge tool that leverages the power of AI to assist in the creation and management of Streamlit applications. By inputting your requirements through a chat prompt, <strong>AutoStreamlit Studio</strong> takes care of generating, customizing, and running a Streamlit app tailored to your needs. This tool is designed to save time and enhance productivity, making it a valuable asset for both developers and non-developers.</p><h3>Key Features</h3><p><strong>AutoStreamlit Studio</strong> comes packed with a range of features designed to make app development as seamless as possible:</p><h4>Automatic App Generation</h4><p><strong>AutoStreamlit Studio </strong>simplifies the initial development phase by automatically generating a complete Streamlit app based on the requirements you provide. This feature eliminates the need for manual coding from scratch, allowing you to focus on refining and customizing the app.</p><h4>Customizable Templates</h4><p>To kickstart your development process, <strong>AutoStreamlit Studio</strong> offers a variety of predefined templates. These templates serve as a foundation upon which you can build and customize your applications, ensuring that you have a solid starting point for any project.</p><h4>Interactive Widgets</h4><p>Adding interactive elements such as charts, tables, and forms is made effortless with <strong>AutoStreamlit Studio</strong>. These widgets enhance the functionality of your app, making it more engaging and user-friendly.</p><h4>Voice Commands</h4><p>For users leveraging the <strong>OpenAI</strong> provider, <strong>AutoStreamlit Studio</strong> supports voice commands, allowing for hands-free interaction with the tool. This feature is particularly useful for quickly generating and modifying apps without typing.</p><h4>Code Editor</h4><p><strong>AutoStreamlit Studio</strong> includes a built-in code editor, enabling you to make direct modifications to the generated code. This allows for greater flexibility and customization, ensuring that the final product meets your specific needs.</p><h4>Version Control</h4><p>Managing different versions of your app is crucial for tracking changes and improvements. <strong>AutoStreamlit Studio’s</strong> version control feature allows you to save, load, and reset versions of your app, providing a comprehensive history of your development process.</p><h4>File Operations</h4><p>With <strong>AutoStreamlit Studio</strong>, handling file operations such as downloading, uploading, and running Streamlit app files is straightforward. This functionality streamlines the process of managing and deploying your applications.</p><h4>API Token Management</h4><p>Security is a top priority, and <strong>AutoStreamlit Studio</strong> ensures that your API tokens are managed securely. The tool supports API token management for OpenAI and Replicate providers, safeguarding your credentials.</p><h4>Error Handling and Resolution</h4><p>Coding errors are inevitable, but <strong>AutoStreamlit Studio</strong> is equipped to identify and resolve them automatically. This feature saves you time and effort, ensuring that your app runs smoothly.</p><h4>Session Management</h4><p>Maintaining session state and chat history is essential for continuity. <strong>AutoStreamlit Studio</strong> handles session expiration and preserves chat history and code state, allowing you to pick up where you left off.</p><h3>How to Use AutoStreamlit Studio</h3><p>Getting started with <strong>AutoStreamlit Studio</strong> is straightforward. Here’s a step-by-step guide to help you navigate the tool:</p><ol><li><strong>Select Provider and Enter API Key</strong>: Begin by choosing your provider (<em>OpenAI</em> or <em>Replicate</em>) and entering the API key to unlock the app’s full functionality.</li><li><strong>Enter Your Requirements</strong>: Use the chat input box to specify your app requirements. The more detailed your input, the better <strong>AutoStreamlit Studio</strong> can tailor the app to your needs.</li><li><strong>Generate the Script</strong>: <strong>AutoStreamlit Studio</strong> will generate a Streamlit script based on your input. This script serves as the backbone of your application.</li><li><strong>View Past Conversations</strong>: The chat history feature allows you to review previous interactions and modifications, providing context and continuity.</li><li><strong>Use Predefined Templates</strong>: Kickstart your development with predefined templates, which can be customized to suit your specific needs.</li><li><strong>Edit and Run</strong>: Make any necessary modifications to the generated script through the built-in code editor, then run the script to see your app in action.</li><li><strong>Save, Load, or Reset Versions</strong>: Utilize the version control feature to manage different versions of your app, ensuring you can track changes and revert to previous states if needed.</li><li><strong>Clear Chat History</strong>: If you need a fresh start, use the ‘Clear chat history’ button to delete previous interactions.</li><li><strong>Download the Script</strong>: Save the generated script as a .py file for further use or sharing.</li><li><strong>Handle Errors</strong>: The app will identify any errors in the generated code and provide resolution options, ensuring your app runs without issues.</li></ol><h3>Sidebar UI</h3><p>The sidebar of AutoStreamlit Studio is designed to provide easy access to various functionalities, enhancing your workflow:</p><ul><li><strong>About AutoStreamlit Studio</strong>: Learn more about the tool, its capabilities, and its development.</li><li><strong>How to Use</strong>: Detailed instructions on how to interact with AutoStreamlit Studio, ensuring you make the most of its features.</li><li><strong>API Token Management</strong>: Manage your API tokens securely for OpenAI and Replicate providers.</li><li><strong>Chat History</strong>: View the history of your interactions with the assistant, providing a reference for your development process.</li><li><strong>Template Selection</strong>: Choose from a variety of predefined templates to start your app development.</li><li><strong>Version Control</strong>: Manage different versions of your app to keep track of changes and improvements.</li><li><strong>Code Editor</strong>: Edit the generated code directly within the app for further customization.</li></ul><h3>Practical Examples</h3><h4>Example 1: Simple Data Visualization App</h4><p>Imagine you need a simple data visualization app to display sales data. By providing your requirements through <strong>AutoStreamlit Studio</strong>, you can quickly generate an app that includes charts, tables, and interactive elements to visualize your data effectively.</p><h4>Example 2: Interactive Dashboard for Machine Learning</h4><p>Suppose you want to create an interactive dashboard to showcase machine learning models. <strong>AutoStreamlit Studio</strong> can help you build an app that integrates various models, displays their performance metrics, and allows users to interact with the models through a user-friendly interface.</p><h3>Impact on Development Workflow</h3><p><strong>AutoStreamlit Studio</strong> significantly enhances the development workflow by automating repetitive tasks and reducing the time required to create functional Streamlit apps. This automation allows developers to focus on higher-level tasks, such as refining the user experience and adding advanced features. For non-developers, <strong>AutoStreamlit Studio</strong> makes it possible to create sophisticated web applications without deep coding knowledge.</p><h3>Conclusion</h3><p><strong>AutoStreamlit Studio</strong> is poised to revolutionize the way we develop <strong>Streamlit</strong> applications. By automating the creation and management of apps, it empowers users to quickly turn their ideas into reality. Whether you’re developing data visualizations, interactive dashboards, or other custom applications, <strong>AutoStreamlit Studio</strong> provides the tools you need to succeed. Embrace this innovative tool and experience the future of app development today. For more information, check out the <a href="https://github.com/stavrostheocharis/auto-streamlit-studio/blob/main/README.md">REAME.md file inside the repo</a>.</p><h3>✨ Call to Action</h3><p>I invite you to try <a href="https://auto-stream-studio.streamlit.app/"><strong>AutoStreamlit Studio</strong></a> and see how it can transform your development process. Your feedback and contributions are invaluable as we continue to improve and expand the tool. Join the community, share your experiences, and help shape the future of automated app development.</p><p>⚡ <a href="https://medium.com/@stavrostheocharis">Follow me on Medium</a>, <a href="https://github.com/stavrostheocharis">Github</a>, <a href="http://www.linkedin.com/in/stavros-theocharis-ai">LinkedIn</a> and <a href="https://www.youtube.com/channel/UCDmXZxBke7Io-OwbBdi5aGQ">Youtube</a> for more updates and tutorials. Happy coding!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=baa50121fe53" width="1" height="1" alt=""><hr><p><a href="https://pub.towardsai.net/auto-streamlit-studio-baa50121fe53">Auto-Streamlit Studio</a> was originally published in <a href="https://pub.towardsai.net/">Towards AI</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[easy-explain: Explainable AI with GradCam]]></title>
            <link>https://pub.towardsai.net/easy-explain-explainable-ai-with-gradcam-e187f85a697c?source=rss-216e390c9a41------2</link>
            <guid isPermaLink="false">https://medium.com/p/e187f85a697c</guid>
            <category><![CDATA[ai]]></category>
            <category><![CDATA[explainable-ai]]></category>
            <category><![CDATA[xai]]></category>
            <category><![CDATA[computer-vision]]></category>
            <category><![CDATA[grad-cam]]></category>
            <dc:creator><![CDATA[Stavros Theocharis]]></dc:creator>
            <pubDate>Tue, 13 Feb 2024 18:01:53 GMT</pubDate>
            <atom:updated>2024-02-13T18:01:53.792Z</atom:updated>
            <content:encoded><![CDATA[<h4>A quick and easy-to-use package for fast explainability results on common image models like VGG19 &amp; Resnet50</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*voIWB85-b_ydJXxZ7Q4Fww.png" /></figure><h3>Introduction</h3><p>It’s been a while since I created this <a href="https://github.com/stavrostheocharis/easy_explain">package <strong>‘easy-explain</strong>’ </a>and published it on <a href="https://pypi.org/project/easy-explain/">Pypi</a>. I have already written several articles on Medium about the functionality on <a href="https://pub.towardsai.net/easy-explain-explainable-ai-for-images-285777a004e3">image models using Occlusion</a> &amp; <a href="https://pub.towardsai.net/easy-explain-explainable-ai-for-yolov8-bbbf66ff8690">YoloV8 models using LRP</a>.</p><p><strong>GradCam</strong> is a widely used <strong>Explainable AI </strong>method that has been extensively discussed in both forums and literature. Therefore, I thought, why not include this common method in my package, but in an abstract way, so that, as my motto says, someone can use it <strong>easily</strong>!</p><p>The package has already been transformed since my previous release to make it easier for me to add a new method each time without breaking the entire structure. The logic is that each of my methods has its own class and can be called directly from the package. The plotting functionality is also included, so you only need to run a few lines of code.</p><p>So, let&#39;s read some of the theory…</p><h3>What is GradCam</h3><p>Grad-CAM, or Gradient-weighted Class Activation Mapping, introduced in this <a href="https://arxiv.org/pdf/1610.02391.pdf">paper</a>, is a prominent algorithm in Explainable AI (XAI). It was specifically developed for evaluation with pretrained networks like Resnet50 and VGG19. Grad-CAM can be used in image classification problems and enables us to identify the parts of an image that influenced the model’s labeling decision.</p><p>It has been widely used, for instance, in analysis where the model may have misclassified an image. The Grad-CAM technique is known for its simplicity and ease of implementation. The architecture of Grad-CAM is depicted in the image below.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*XfkLwGnXVj3nlD8obnCTDQ.png" /><figcaption>Grad-CAM architecture [1]</figcaption></figure><p>In this package, we offer two different options based on the user’s needs: <strong>SmoothGradCAMpp</strong> and <strong>LayerCAM</strong>.</p><h4>SmoothGradCAMpp</h4><p>SmoothGradCAMpp is an extension of Grad-CAM++ (Gradient-weighted Class Activation Mapping) and integrates ideas from SmoothGrad. Grad-CAM++ itself is an improvement over Grad-CAM, designed to provide finer-grained visual explanations of CNN decisions.</p><p>The core idea of Grad-CAM++ (and by extension, SmoothGradCAMpp) is to use the gradients flowing into the final convolutional layer of the CNN to produce a heatmap that highlights the important regions in the input image for predicting the concept. SmoothGradCAMpp enhances this by averaging the maps obtained from multiple noisy versions of the input image, aiming to reduce noise and highlight salient features more effectively.</p><p>SmoothGradCAMpp is particularly useful for getting more detailed and less noisy heatmaps that indicate why a particular decision was made by the model. It’s beneficial for understanding model behavior in a specific instance.</p><h4>LayerCAM</h4><p>LayerCAM is a relatively newer technique that also aims to provide visual explanations for model decisions. Unlike Grad-CAM and its variants, LayerCAM can generate more detailed heatmaps by integrating features from multiple layers of CNN.</p><p>LayerCAM modifies the way of aggregating feature maps from different layers. It emphasizes the importance of each pixel by considering its influence across multiple layers, not just the final convolutional layer. This approach allows LayerCAM to highlight finer details and more relevant areas in the input image for the model’s decision.</p><p>LayerCAM is particularly useful when you want to capture the model’s attention at multiple levels of abstraction, from lower-level features to higher-level semantics. It can provide a more comprehensive view of how different layers contribute to the final decision, making it valuable for in-depth analysis of model behavior.</p><h4>Key differences</h4><ul><li><strong>Layer Focus</strong>: SmoothGradCAMpp focuses on the final convolutional layer and uses noise reduction techniques to enhance clarity. LayerCAM aggregates information across multiple layers for a more detailed heatmap.</li><li><strong>Detail and Scope</strong>: LayerCAM can potentially provide more detailed insights by leveraging multiple layers, while SmoothGradCAMpp seeks to refine the clarity of heatmaps derived from a single layer.</li><li><strong>Noise Reduction</strong>: The integration of SmoothGrad into GradCAMpp (forming SmoothGradCAMpp) specifically aims to reduce noise in the generated heatmaps, a feature not explicitly designed into LayerCAM.</li><li><strong>Implementation Complexity</strong>: SmoothGradCAMpp’s methodology of adding noise and averaging might be more straightforward to implement as an extension of existing Grad-CAM++ techniques, while LayerCAM requires a more complex aggregation of features across layers.</li></ul><p>Both methods offer valuable insights into model decisions, and the choice between them depends on the specific requirements of the explanation task, such as the need for detail, clarity, or understanding multi-layer contributions.</p><h3>How to use it (Code part)</h3><p>In this example, I am going to showcase the same one with the <a href="https://github.com/stavrostheocharis/easy_explain/tree/main/examples/gradcam">example notebooks provided inside the repo</a>.</p><p>I will also load two different models from torchvision to demonstrate the possible uses of the package. So, let’s import the libraries. We also assume that the package has been installed via “<strong><em>pip install easy-explain”</em></strong>.</p><pre>from torchvision.models import resnet50, vgg19<br>from torchvision.io.image import read_image<br>from easy_explain import CAMExplain</pre><p>Now let&#39;s initialize the models to be used:</p><pre>resnet50_model = resnet50(weights=&quot;ResNet50_Weights.DEFAULT&quot;).eval()<br>vgg19_model = vgg19(weights=&quot;VGG19_Weights.DEFAULT&quot;).eval()</pre><p>We also need to apply specific transformations (resizing and normalization) to the image before passing it through the models:</p><pre>trans_params = {&quot;ImageNet_transformation&quot;:<br>  {&quot;Resize&quot;: {&quot;h&quot;: 224,&quot;w&quot;: 224},<br>  &quot;Normalize&quot;: {&quot;mean&quot;: [0.485, 0.456, 0.406], &quot;std&quot;: [0.229, 0.224, 0.225]}}}</pre><p>And now let&#39;s get an image from Unsplash.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*XEY73iLiZwpvOOsxpiPLDQ.jpeg" /><figcaption>Image by <a href="https://unsplash.com/@mikesetchell?utm_content=creditCopyText&amp;utm_medium=referral&amp;utm_source=unsplash">Mike Setchell</a> (Unsplash)</figcaption></figure><p>You can save this image to your path. My path will be as follows, inside a data folder. So, I will load it from there:</p><pre>img = read_image(&quot;../data/mike-setchell-pf97TYdQlWM-unsplash.jpg&quot;)</pre><p>And now… we have our new explainer!</p><pre>explainer = CAMExplain(model = resnet50_model) </pre><p>You can easily initialize it! In addition, let’s convert the image to a tensor in order to pass it through the model (also applying the transformation mentioned above). The explainer has built-in functionality for such image transformation.</p><pre>input_tensor = explainer.transform_image(img, trans_params[&quot;ImageNet_transformation&quot;])</pre><p>Let’s also take a look at the ResNet50 model architecture to understand the layers and identify what we would like to see through the XAI application.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*uei4wAkBKvj4gwXeRZAg2A.png" /><figcaption>Image by the author</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*udtcoRJd_cyoSFJisjYCFg.png" /><figcaption>Image by the author</figcaption></figure><p>This needs to be done since each model has a different number of layers, names, etc. To determine the specific layers to analyze using Class Activation Mapping (CAM), we must inspect the model’s architecture and select the relevant layers based on our objective, such as identifying which features influence the model’s predictions at different levels.</p><p>Each model possesses unique layers, necessitating an overview of its structure to make an informed selection. By default, if no target layer is specified, the algorithm applies to the final layer of the model. For a more comprehensive visualization, multiple layer names can be included in a list.</p><h4>Application of the XAI</h4><p>Let’s visualise for this model some of our preference layers. We will select layers 2, 3 &amp; 4.</p><pre>explainer.generate_explanation(img, input_tensor, multiple_layers=[&quot;layer2&quot;, &quot;layer3&quot;, &quot;layer4&quot;])</pre><p>and this results to:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/940/1*rO873f61Qwewiuy2Rk52IQ.png" /><figcaption>Image by the author</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/632/1*_TQ4lfla8dU9xNuiW-5veg.png" /><figcaption>Image by the author (raw image by <a href="https://unsplash.com/@mikesetchell?utm_content=creditCopyText&amp;utm_medium=referral&amp;utm_source=unsplash">Mike Setchell</a>)</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Uya5fIBxwMakSrPps9vccg.png" /><figcaption>Image by the author</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*hAm_08u_yDo23ukxfX9D7Q.png" /><figcaption>Image by the author</figcaption></figure><p>The impact of each layer on the outcome is distinct, as observed from the different layers. Every layer contributes uniquely to the final decision. Ultimately, we can view an aggregated visualization that combines the effects of all the chosen layers.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/930/1*BQDAiUMhdVnL9zbAommP0Q.png" /><figcaption>Image by the author</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/634/1*5ukv79NFReCeNYuyiDxN3A.png" /><figcaption>Image by the author (raw image by <a href="https://unsplash.com/@mikesetchell?utm_content=creditCopyText&amp;utm_medium=referral&amp;utm_source=unsplash">Mike Setchell</a>)</figcaption></figure><p>We can see that we have various visualizations of the layers. This can be very helpful in understanding how each one contributes to the final classification. These visualizations can be really useful in custom training models. In such models, the AI developer will want to see if the model behaves well and on what parts it focuses more.</p><p>Now let’s use another model (vgg model). As mentioned, each model features a unique architecture, comprising distinct layers and naming conventions for those layers.</p><p>For the ResNet50 model, GradCam was applied to its final layer by default (since None is specified), as well as an aggregated GradCam analysis for layers “layer2”, “layer3”, and “layer4”.</p><p>For the VGG19 model, GradCam is executed individually for each layer within the features section to also demonstrate the possible use of this XAI package.</p><p>again… a new explainer:</p><pre>explainer = CAMExplain(model = vgg19_model)</pre><p>Let’s have a look at the architecture again…</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*o1LukvdgtIYFV9TrgnB3RA.png" /><figcaption>Image by the author</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*STNII1G75k7p6Y5onekgeg.png" /><figcaption>Image by the author</figcaption></figure><p>It is of course different than the previous model…</p><p>Let’s visualize for this model all the layers with features. Through these visualizations, we will be able to understand how each one of the features that the model extracts from the image behaves in order to contribute to the final result.</p><pre># Keep the features layers until the last CNN layer<br>features = []<br>features = [vgg19_model.features[x] for x in range(35)]<br><br>explainer.generate_explanation(img, input_tensor, target_layer=features)</pre><p>The script mentioned above will create visualizations for all of the features identified in the model’s architecture. Below, I provide only a sample of the plots that are generated.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/536/1*lrVzW8WwhmMvl3XSIqP7nw.png" /><figcaption>Image by the author</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/538/1*kYpQiQJRJwO-eYQ517v12g.png" /><figcaption>Image by the author</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/536/1*SL9rnwjVJNeeMdbe-2ZlsA.png" /><figcaption>Image by the author</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/366/1*jnvd7jNu8bFJZNd57wu53g.png" /><figcaption>Image by the author (raw image by <a href="https://unsplash.com/@mikesetchell?utm_content=creditCopyText&amp;utm_medium=referral&amp;utm_source=unsplash">Mike Setchell</a>)</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/370/1*4vAqiayrGhmdAXMX8SNb6w.png" /><figcaption>Image by the author (raw image by <a href="https://unsplash.com/@mikesetchell?utm_content=creditCopyText&amp;utm_medium=referral&amp;utm_source=unsplash">Mike Setchell</a>)</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/362/1*yzubG0-X5s8OyVq49Mhgsg.png" /><figcaption>Image by the author (raw image by <a href="https://unsplash.com/@mikesetchell?utm_content=creditCopyText&amp;utm_medium=referral&amp;utm_source=unsplash">Mike Setchell</a>)</figcaption></figure><h3>Conclusion</h3><p>Generally, the field of explainable artificial intelligence (XAI) plays a crucial role in ensuring that artificial intelligence systems are interpretable, transparent, and reliable. By employing XAI techniques in the creation of image classification models, we can achieve a deeper comprehension of their functionality and make informed decisions regarding their application.</p><p>In this article, I showcased the new functionality of my easy-explain package. Through it, someone can easily and quickly explain and check the predictions of many known image classification models like Resnet50 or VGG19.</p><p>I encourage you to experiment with this new feature of my easy-explain package for explaining easily image models.</p><p>Possible feedback is more than welcome! If you want to contribute to the project, please read the <a href="https://github.com/stavrostheocharis/easy_explain/blob/main/CONTRIBUTING.md">contribution guide</a>.</p><p>🌟 If you enjoyed this article, <a href="https://medium.com/@stavrostheocharis">follow me on Medium to read more</a>!</p><p>🌟 you can also <a href="http://www.linkedin.com/in/stavros-theocharis-ai">follow me on Linkedin</a> &amp; <a href="https://github.com/stavrostheocharis">Github</a>!</p><h3>References</h3><p>[1] Lin, Cheng-Jian &amp; Jhang, Jyun-Yu. (2021). Bearing Fault Diagnosis Using a Grad-CAM-Based Convolutional Neuro-Fuzzy Network. Mathematics. 9. 1502. 10.3390/math9131502.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=e187f85a697c" width="1" height="1" alt=""><hr><p><a href="https://pub.towardsai.net/easy-explain-explainable-ai-with-gradcam-e187f85a697c">easy-explain: Explainable AI with GradCam</a> was originally published in <a href="https://pub.towardsai.net/">Towards AI</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[easy-explain: Explainable AI for YoloV8]]></title>
            <link>https://pub.towardsai.net/easy-explain-explainable-ai-for-yolov8-bbbf66ff8690?source=rss-216e390c9a41------2</link>
            <guid isPermaLink="false">https://medium.com/p/bbbf66ff8690</guid>
            <category><![CDATA[yolo]]></category>
            <category><![CDATA[explainable-ai]]></category>
            <category><![CDATA[xai]]></category>
            <category><![CDATA[ai]]></category>
            <category><![CDATA[computer-vision]]></category>
            <dc:creator><![CDATA[Stavros Theocharis]]></dc:creator>
            <pubDate>Sat, 03 Feb 2024 18:01:40 GMT</pubDate>
            <atom:updated>2024-02-14T10:56:56.720Z</atom:updated>
            <content:encoded><![CDATA[<h4>A quick and easy-to-use package for fast explainability results on Yolo models</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*QkPZLHK1Pf8gK8fVfjovvw.png" /><figcaption>(Left) Photo by <a href="https://unsplash.com/@pawel_czerwinski">Pawel Czerwinski</a> on <a href="https://unsplash.com/photos/black-and-white-signal-light--Y0qPpeO5Us">Unsplash</a> | (Right) <a href="https://unsplash.com/photos/black-and-white-signal-light--Y0qPpeO5Us">Unsplash</a> Image adjusted by the showcased algorithm</figcaption></figure><h3>Introduction</h3><p>It’s been a while since I created this <a href="https://github.com/stavrostheocharis/easy_explain">package ‘easy-explain’ </a>and published on <a href="https://pypi.org/project/easy-explain/">Pypi</a>. I also wrote a <a href="https://pub.towardsai.net/easy-explain-explainable-ai-for-images-285777a004e3">Medium article about this package</a> in the past to illustrate its use with image classification models. A few weeks ago, I needed an explainability algorithm for a YoloV8 model.</p><blockquote>You can also have a read of my new article: easy-explain: <a href="https://pub.towardsai.net/easy-explain-explainable-ai-with-gradcam-e187f85a697c">Explainable AI with GradCam</a></blockquote><p>The truth is, I couldn’t find anything. After further digging, I found a <a href="https://github.com/akarasman/yolo-heatmaps">repo</a>. which included an LRP method for generating explanations for such models. I needed it to be slightly different, so I made some adjustments and decided to include it in my <a href="https://github.com/stavrostheocharis/easy_explain">‘easy-explain’ package</a>, as there was no other available package offering the same functionality. Since this package was not originally intended for various use cases when I created it, I had to refactor many things, leading to some breaking changes in the new release.</p><p>A quick reference for what is a YOLO model. <strong>You Only Look Once (YOLO) is one of the most popular model architectures and object detection algorithms</strong>. It uses one of the best neural network architectures to produce high accuracy and overall processing speed, which is the main reason for its popularity.</p><h3>Loading &amp; Pre-processing of an image</h3><p>Here, I use an image sourced from Unsplash, which I retrieve directly through a request. Afterwards, it needs to be opened with the Image class from the PIL library.</p><pre>from PIL import Image<br>from io import BytesIO<br>import requests<br><br>response = requests.get(&quot;https://images.unsplash.com/photo-1530652101053-8c0db4fbb5de?q=80&amp;w=2787&amp;auto=format&amp;fit=crop&amp;ixlib=rb-4.0.3&amp;ixid=M3wxMjA3fDB8MHxwaG90by1wYWdlfHx8fGVufDB8fHx8fA%3D%3D&quot;)<br>image = Image.open(BytesIO(response.content))</pre><p>In addition, the loaded image will undergo a basic transformation with the help of the torchvision library to be compatible with the model.</p><pre>import torchvision<br><br>desired_size = (512, 640)<br>transform = torchvision.transforms.Compose([<br>    torchvision.transforms.Resize(desired_size),<br>    torchvision.transforms.ToTensor(),<br>])<br>image = transform(image)</pre><h3>Loading YoloV8 model</h3><p>You are free to use any YoloV8 model you prefer. Here, I am using a model from <a href="https://github.com/ultralytics">Ultralytics</a>. I have also tested other models from Hugging Face, and the easy-explain package is working correctly!</p><pre>from ultralytics import YOLO<br><br>model = YOLO(&#39;ultralyticsplus/yolov8s&#39;)</pre><p>I will not delve into the details of how to make predictions using this model in this article. We are ready to utilize the easy-explain package…</p><h3>Simple use of easy-explain package for a YoloV8 model</h3><p>Here, we simply need to import the package and instantiate the corresponding class. The good news is that this explainer can be used with both CPU and GPU, so I will use the CPU. We also need to specify the class for which we seek to understand the prediction. Feel free to experiment with the arguments and check the results.</p><pre>from easy_explain import YOLOv8LRP<br><br>lrp = YOLOv8LRP(model, power=2, eps=1, device=&#39;cpu&#39;)<br>explanation_lrp = lrp.explain(image, cls=&#39;traffic light&#39;, contrastive=False).cpu()</pre><p>Now that we have our explanations, let’s use the appropriate function to visualize them in various ways. We’ll utilize the visualization functionality provided by the package:</p><pre>lrp.plot_explanation(frame=image, explanation = explanation_lrp, contrastive=False, cmap=&#39;seismic&#39;, title=&#39;Explanation for Class &quot;traffic light&quot;&#39;)</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*QuGd9tow6w5myhpTrkgXPw.png" /><figcaption>(Left) Photo by <a href="https://unsplash.com/@pawel_czerwinski">Pawel Czerwinski</a> on <a href="https://unsplash.com/photos/black-and-white-signal-light--Y0qPpeO5Us">Unsplash</a> | (Right) <a href="https://unsplash.com/photos/black-and-white-signal-light--Y0qPpeO5Us">Unsplash</a> Image adjusted by the showcased algorithm</figcaption></figure><p>Here, I used contrastive=False to create a different visualization from the first image (which was produced with contrastive=True).</p><p>Let’s try it with another image and a different class (zebra). We’ll assume that we follow the same process as before for the <a href="https://unsplash.com/photos/zebra-standing-on-wheat-field-ZqYPM8i60F8">new image</a>. Then we have:</p><pre>explanation_lrp = lrp.explain(image, cls=&#39;zebra&#39;, contrastive=False).cpu()<br>lrp.plot_explanation(frame=image, explanation = explanation_lrp, contrastive=False, cmap=&#39;Reds&#39;, title=&#39;Explanation for Class &quot;zebra&quot;&#39;)</pre><p>and we get:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*qDBPiMb4IKFOXpxdV7VpFA.png" /><figcaption>(Left) Photo by <a href="https://unsplash.com/@grifjef">Jeff Griffith</a> on <a href="https://unsplash.com/photos/zebra-standing-on-wheat-field-ZqYPM8i60F8">Unsplash</a> | (Right) <a href="https://unsplash.com/photos/zebra-standing-on-wheat-field-ZqYPM8i60F8">Unsplash</a> Image adjusted by the showcased algorithm</figcaption></figure><p>For more information and ideas you can also check the example notebooks inside the <a href="https://github.com/stavrostheocharis/easy_explain/tree/main/examples">github repositoty.</a></p><h3>How does Layer-Wise Relevance Propagation (LRP) work?</h3><p>Layer-wise Relevance Propagation (LRP) is a method used for explaining decisions made by models structured as neural networks, where inputs might include images, videos, or text. LRP works by backward propagating the prediction f(x) through the neural network, utilizing specifically tailored local propagation rules. The propagation process applied by LRP adheres to a conservation principle, ensuring that what a neuron has received is equally redistributed to the preceding layer.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*5Ogsye85kjvB8VRfqd-H-Q.png" /><figcaption>The LRP procedure [2]</figcaption></figure><h3>Conclusion</h3><p>Generally, the field of explainable artificial intelligence (XAI) plays a crucial role in ensuring that artificial intelligence systems are interpretable, transparent, and reliable. By employing XAI techniques in the creation of image classification models, we can achieve a deeper comprehension of their functionality and make informed decisions regarding their application.</p><p>In this article, I showcased the new functionality of my easy-explain package. Through it, someone can easily and quickly explain and check the predictions of the YoloV8 trained models.</p><p>I encourage you to experiment with this new feature of my easy-explain package for explaining easily YoloV8 models.</p><p>Possible feedback is more than welcome! If you want to contribute to the project, please read the <a href="https://github.com/stavrostheocharis/easy_explain/blob/main/CONTRIBUTING.md">contribution guide</a>.</p><p>🌟 If you enjoyed this article, <a href="https://medium.com/@stavrostheocharis">follow me on Medium to read more</a>!</p><p>🌟 you can also <a href="http://www.linkedin.com/in/stavros-theocharis-ai">follow me on Linkedin!</a></p><h3>References</h3><p>[1] Bach, S., Binder, A., Montavon, G., Klauschen, F., Müller, K.R., Samek, W.: On pixel-wise explanations for non-linear classifier decisions by layer-wise relevance propagation. PLoS ONE 10(7), e0130140 (2015)</p><p>[2] Montavon, G., Binder, A., Lapuschkin, S., Samek, W., Müller, KR. (2019). Layer-Wise Relevance Propagation: An Overview. In: Samek, W., Montavon, G., Vedaldi, A., Hansen, L., Müller, KR. (eds) Explainable AI: Interpreting, Explaining and Visualizing Deep Learning. Lecture Notes in Computer Science(), vol 11700. Springer, Cham. <a href="https://doi.org/10.1007/978-3-030-28954-6_10">https://doi.org/10.1007/978-3-030-28954-6_10</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=bbbf66ff8690" width="1" height="1" alt=""><hr><p><a href="https://pub.towardsai.net/easy-explain-explainable-ai-for-yolov8-bbbf66ff8690">easy-explain: Explainable AI for YoloV8</a> was originally published in <a href="https://pub.towardsai.net/">Towards AI</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[AI Balances: How the EU AI Act is Redefining Tech Norms]]></title>
            <link>https://medium.datadriveninvestor.com/ai-balances-how-the-eu-ai-act-is-redefining-tech-norms-7bf5604fbb0c?source=rss-216e390c9a41------2</link>
            <guid isPermaLink="false">https://medium.com/p/7bf5604fbb0c</guid>
            <category><![CDATA[ai-regulation]]></category>
            <category><![CDATA[eu-ai-act]]></category>
            <category><![CDATA[ai-act-compliance]]></category>
            <category><![CDATA[ai]]></category>
            <category><![CDATA[ai-future]]></category>
            <dc:creator><![CDATA[Stavros Theocharis]]></dc:creator>
            <pubDate>Mon, 22 Jan 2024 05:03:18 GMT</pubDate>
            <atom:updated>2024-02-05T16:03:43.895Z</atom:updated>
            <content:encoded><![CDATA[<h4>The Balance of Innovation and Regulation in Europe</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*QhM599marVMVM_TbkMishw.png" /></figure><h3>Introduction</h3><p>The AI Act is a crafted set of rules governing the use of Artificial Intelligence (AI) across all EU countries. Personally, I do not believe that it is something coming out of nowhere, as some people may believe. The reason is that we are talking about the EU. The commission almost always comes with specific regulations, especially in the tech sector.</p><p>The AI Act is enforceable across the EU area, unlike directives, which need to be fine-tuned and integrated into each country’s laws. It’s worth mentioning that directives outline required outcomes but leave Member States free to decide how to transpose them into national laws. This new pioneering law, similar to the earlier GDPR, sets a standard for AI regulation, focusing on a risk-based approach. This means that AI systems are categorized according to their potential harm, with stricter rules for higher-risk systems.</p><p>The regulation aims not to hinder innovation but to ensure its safe and ethical implementation. It conveys a clear message that not all innovations are beneficial without proper oversight.</p><h3><strong>Basic terminology</strong></h3><p>Let’s clarify some basic terms. The term ‘artificial intelligence system’ (AI system) refers to software created with specific functionalities that can perform tasks such as content generation, decision-making, etc. Additionally, the term ‘provider’ denotes anyone involved in either creating AI systems or supplying them for use, whether they are selling them or offering them for free.</p><p>The European Commission has also reconsidered how SMEs are defined under <a href="https://eur-lex.europa.eu/LexUriServ/LexUriServ.do?uri=OJ:L:2003:124:0036:0041:en:PDF"><strong>Recommendation 2003/361/EC</strong></a><strong>. </strong>Micro, small and medium-sized enterprises include those that have less than 250 employees and annual turnover of less than €50 million and/or annual balance sheet of less than €43 million. Furthermore an enterprise is considered to be any legal entity engaged in economic activities.</p><h3>Goals of the New AI Regulations</h3><p>In the face of current political developments, the European Commission has outlined a set of goals for its new AI regulations:</p><ol><li>To strengthen the enforcement of laws protecting fundamental rights and safety in various aspects, including the ethical dimension, where AI is concerned.</li><li>To provide businesses with a legal framework that will guide AI investments, development, innovation, etc.</li><li>To help the creation of a unified market for AI applications that are legal, safe, and reliable.</li></ol><h3>Key Aspects of the AI Act</h3><p>I’d like to unpack this like we’re talking about some new, hyper-responsible kind of approach to handling AI. In some of the bullets below I will also include my personal view which will be highlighted to keep it separate from the objective view emanating from the AI Act itself:</p><ul><li><strong>AI Act as a Milestone: </strong>The<strong> </strong>AI Act is a crucial step toward ethical and safe AI innovation in Europe.</li></ul><blockquote>Of course there are both pros and cons. What do you sacrifice for the ethical and safe innovation? In such decisions there is always a trade-off.</blockquote><ul><li><strong>Responsible AI in Law Enforcement: </strong>The responsible use of AI is highly emphasised. There exist specific law enforcement parts, with clear guidelines to be followed.</li><li><strong>Regulatory Sandboxes: </strong>Future AI systems will need to be validated in specific environments.<strong> </strong>“Regulatory sandboxes” are introduced for testing the AI under real conditions, ensuring safety and ethical standards.</li></ul><blockquote>I think that something like that is needed but I am concerned that it&#39;s application may burden the easy progress of innovation.</blockquote><ul><li><strong>Exclusion of Military AI: </strong>The<strong> </strong>AI systems used solely for military purposes are excluded from the regulation.</li></ul><blockquote>From my perspective this raises some concerns about AI’s impact on warfare and national defense. Personally, I fully understand the reasons, but again …. possible dangers arise.</blockquote><ul><li><strong>Rules for General-Purpose AI: </strong>Specific guidelines for general-purpose AI models.</li><li><strong>No Interference with Other Laws or National Security</strong>: The regulation doesn’t affect EU laws unrelated to AI, nor does it affect member states’ national security responsibilities.</li><li><strong>Easier Rules for Low-Risk AI: </strong>There will be some low-expected requirements for AI systems that pose limited risk, like disclosing AI-generated content.</li><li><strong>Big No-Nos in AI: </strong>Prohibitions on practices like manipulating human behaviour, indiscriminate facial image collection, emotion recognition at work or schools, social grading, and some proactive policing methods.</li></ul><blockquote>Personally, I appreciate this aspect, because it adopts a more human-centric approach, trying to prohibit AI elements that could lead to social issues and bias.</blockquote><ul><li><strong>Fines for Rule Breakers: </strong>There exist specific fine categories based on the type of the AI system<strong>. </strong>Fines for breaking the rules are a percentage of a company’s global turnover or a fixed amount, whichever is higher. These fines vary: up to EUR 35 million or 7% for prohibited AI uses, EUR 15 million or 3% for other obligations, and EUR 7.5 million or 1.5% for false information. However, there are lower fine limits for SMEs and startups in certain cases.</li><li><strong>Exemptions for free and open-source components</strong>: The Act provides an exemption for free and open-source AI components providing they are not put into service as a component of a high-risk system.</li></ul><blockquote>Once again, this shows that the open source is at the forefront of transparency. Open-source parts can be more easily validated and tested by communities leading to quicker feedback.</blockquote><h3>Measures to Foster Innovation and Compliance</h3><p>The approach suggested by the EU Act is measured and has a focus on the minimum that is needed to tackle AI-related risks without unnecessarily holding back technological progress or making AI products prohibitively expensive.</p><p>To foster innovation, the framework includes:</p><ul><li>“AI regulatory sandboxes” for safe AI experimentation. Participation in these sandboxes is voluntary, but it is encouraged. There is a free priority access for SMEs and start-ups in case they are eligible. This is important because those companies that participate in the sandboxes, (especially SMEs and start-ups), will also benefit from specific guidance on the implementation of the Act.</li><li>The AI act strengthens anti-discrimination laws by ensuring AI is designed and developed with high-quality data and with selected testing configurations to prevent possible biased outcomes. This also includes the maintenance of documentation and human oversight over the AI’s lifecycle without affecting competition laws within the EU.</li><li>Support for small and medium-sized businesses and startups to help them navigate the rules without too much cost. SMEs have an exemption of the consultation requirement regarding the impact assessments.</li></ul><p>In the document there’s referenced a specific option (Option 3+) that:</p><ul><li>Follows a balanced, risk-based approach.</li><li>Suggests voluntary codes of conduct for AI systems not considered high-risk. This code could also include commitments to environmental sustainability, accessibility, inclusive design, and diverse development teams.</li></ul><p>The target of this option is to keep the compliance costs low, encouraging more companies to adopt AI without financial strain. In addition support for small and medium-sized enterprises (SMEs) is considered, such as reduced fees and the opportunity to use regulatory sandboxes.</p><h3>Bans on Harmful AI Practices</h3><p>There are strict bans on AI practices that could be harmful:</p><ol><li>No AI can be made or used that manipulates people subliminally to cause physical or mental harm.</li><li>AI cannot exploit possible vulnerabilities of certain groups (age, gender, disability, etc.) to harm them.</li><li>Public authorities are prohibited to use AI to create a ‘social score’ based on people’s behaviour or personality traits over time.</li></ol><h3>AI systems basic requirements</h3><ol><li>AI systems that interact with humans are required to inform users they’re engaging with AI, with certain exceptions for law enforcement. It is needed to become clear to the users when they’re interacting with AI or when AI is used to analyse emotions or biometric data.</li><li>Systems that recognise emotions or categorise biometrics must disclose their operation to the people affected.</li><li>Disclosure is required when AI creates or alters content significantly, with certain exceptions for legal and expressive purposes.</li></ol><h3>Risk categories</h3><p>I will reference the 4 different risk categories. It will not be a detailed section since many other articles have already covered them.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*QsyPi71seqGuqKRj3GFeKA.png" /><figcaption>Image by the author</figcaption></figure><p><strong>Unacceptable:</strong> AI systems that operate subliminally, exploitative ones, real-time remote biometric identification ones (with some specifications), or those that assign social score to individuals. All of these are prohibited.</p><p><strong>High Risk: </strong>AI systems related to toys, aviation, cars, medical devices and lifts. In addition other AI systems that fall under this category are these used in management and operation of critical infrastructure, education and vocational training, employment, worker management and access to self-employment, access to and enjoyment of essential private services and public services and benefits, law enforcement, migration, asylum and border control management, assistance in legal interpretation and application of the law. Deployers of high-risk AI systems are required to carry out fundamental rights impact assessments prior to their use (detailed plan) and mitigate possible risks of fundamental rights. They are also obliged to inform who is going to be affected by these systems.</p><p><strong>Limited Risk:</strong> These refer to AI systems that fall under the umbrella of generative AI with specific requirements like disclosure that the content was generated by AI, designs of the models to prevent them from generating illegal content, publishing summaries of copyrighted data used for training. Limited risk AI systems should comply with minimal transparency requirements</p><p><strong>Minimal Risk:</strong> There exist already widely deployed AI systems in this category. Such systems include spam filters, inventory-management systems, etc.</p><h3>Member States’ Responsibilities</h3><p>As stated above member States must provide a controlled environment, known as AI regulatory sandboxes, for testing the AI systems. These sandboxes are under strict supervision to ensure they meet regulatory standards.</p><p>Member States should provide and setup a set of processes and access. They should:</p><ol><li>give small providers and startups priority access to AI regulatory sandboxes.</li><li>conduct activities to raise awareness about the new regulations among small-scale providers and users.</li><li>create communication channels to guide and answer queries.</li></ol><p>It is important to mention once again that regulations are legally binding across all Member States from a specified date.</p><h3>Conclusion</h3><p>Navigating the complex trade-off between innovation and regulation, the EU’s AI framework can be seen as a well-intentioned attempt, with its own challenges and potential obstacles.</p><p>On one hand, all these regulations are like a detailed drawn map, guiding the AI landscape on ethical dilemmas and safety concerns. They provide guidance, with the guaranty that AI will be applied under a logical and ethical context and won&#39;t be misused with having in mind as the only target the exploitation. In this context, the AI regulatory sandboxes appear to be particularly promising. They can act as some controlled playgrounds where the seeds of possible future technologies can be planted in a safe way, watched over by the eyes of the state.</p><p>However, there’s a flip side to consider. The very threads intended to strengthen the tapestry of AI development could, if pulled too tightly, constrain the creative freedom necessary for groundbreaking innovation.</p><p>Many may believe that the AI Act will have both positive and negative consequences and I also agree with that. One big question is how the EU will compete for example US in innovation? The AI act could possibly slow down processes and innovation due to the possible bureaucracy it may bring with it. Strict guidelines, while necessary for safety and ethical assurance, might inadvertently act as a straitjacket, stifling the spontaneity and risk-taking that often fuel technological breakthroughs.</p><p>An example is that let’s say that you have a nice idea and begin working on your new AI product. Until you get a review and validation for it from EU, another company in the US can come up with a similar idea and get it into the market much faster than you.</p><p>For small-scale innovators and startups, these regulations are a double-edged sword. While they offer guidance and safe testing grounds, there’s an underlying concern: Could the administrative burden and the need to navigate complex regulatory landscapes dampen the fiery spirit of entrepreneurship? The challenge lies in striking a delicate balance between the freedom to innovate and the necessity to regulate.</p><p>While these regulations aim to act as a lighthouse, guiding the AI ship away from potential dangers, there’s an underlying worry that they might also dim the lights of innovation. The hope and my personal view, however, remains that with careful implementation and a willingness to adapt, these regulations will not only safeguard against the risks of AI but also foster an environment where innovation can thrive within well-defined boundaries. The happy case scenario will be the one where caution and creativity coexist in a harmonious equilibrium.</p><blockquote>In my perspective all the human-centric approaches are more than welcome. We try to make a better world for us and the future humans, not to get trapped by our own inventions.</blockquote><p>🌟 If you enjoyed this article, <a href="https://medium.com/@stavrostheocharis">follow me on Medium to read more</a>!</p><p>🌟 you can also <a href="http://www.linkedin.com/in/stavros-theocharis-ai">follow me on Linkedin!</a></p><h3>References</h3><p><a href="https://eur-lex.europa.eu/legal-content/EN/TXT/?uri=celex%3A52021PC0206">EU commission, 2023. EU AI Act. Proposal for a REGULATION OF THE EUROPEAN PARLIAMENT AND OF THE COUNCIL LAYING DOWN HARMONISED RULES ON ARTIFICIAL INTELLIGENCE (ARTIFICIAL INTELLIGENCE ACT) AND AMENDING CERTAIN UNION LEGISLATIVE ACTS.</a></p><p><a href="https://eur-lex.europa.eu/LexUriServ/LexUriServ.do?uri=OJ:L:2003:124:0036:0041:en:PDF">EU commission, 2023. Commision recommendation. Concerning the definition of micro, small and medium-sized enterprises.</a></p><p>Visit us at <a href="https://www.datadriveninvestor.com/"><em>DataDrivenInvestor.com</em></a></p><p>Subscribe to DDIntel <a href="https://www.ddintel.com/"><em>here</em></a>.</p><p>Have a unique story to share? Submit to DDIntel <a href="https://datadriveninvestor.com/ddintelsubmission"><em>here</em></a>.</p><p>Join our creator ecosystem <a href="https://join.datadriveninvestor.com/"><em>here</em></a>.</p><p><a href="https://ddintel.datadriveninvestor.com/"><em>DDIntel</em> </a>captures the more notable pieces from our <a href="https://www.datadriveninvestor.com/"><em>main site</em></a> and our popular <a href="https://medium.datadriveninvestor.com/"><em>DDI Medium publication</em></a>. Check us out for more insightful work from our community.</p><p>DDI Official Telegram Channel: <a href="https://t.me/+tafUp6ecEys4YjQ1">https://t.me/+tafUp6ecEys4YjQ1</a></p><p>Follow us on <a href="https://www.linkedin.com/company/data-driven-investor"><em>LinkedIn</em></a>, <a href="https://twitter.com/@DDInvestorHQ"><em>Twitter</em></a>, <a href="https://www.youtube.com/c/datadriveninvestor"><em>YouTube</em></a>, and <a href="https://www.facebook.com/datadriveninvestor"><em>Facebook</em></a>.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=7bf5604fbb0c" width="1" height="1" alt=""><hr><p><a href="https://medium.datadriveninvestor.com/ai-balances-how-the-eu-ai-act-is-redefining-tech-norms-7bf5604fbb0c">AI Balances: How the EU AI Act is Redefining Tech Norms</a> was originally published in <a href="https://medium.datadriveninvestor.com/">DataDrivenInvestor</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Brand New Streamlit Component: Token Key Mastery]]></title>
            <link>https://pub.towardsai.net/brand-new-streamlit-component-token-key-mastery-a7c7d7351f39?source=rss-216e390c9a41------2</link>
            <guid isPermaLink="false">https://medium.com/p/a7c7d7351f39</guid>
            <category><![CDATA[streamlit-app-deployment]]></category>
            <category><![CDATA[components]]></category>
            <category><![CDATA[tutorial]]></category>
            <category><![CDATA[streamlit]]></category>
            <category><![CDATA[python]]></category>
            <dc:creator><![CDATA[Stavros Theocharis]]></dc:creator>
            <pubDate>Fri, 29 Dec 2023 14:01:41 GMT</pubDate>
            <atom:updated>2024-02-05T16:04:07.790Z</atom:updated>
            <content:encoded><![CDATA[<h4>Elevate Your App with Advanced Management and Display of Token Keys</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*-w3hTBAlqpOV--XYxpbCHg.png" /><figcaption>Image created by <a href="https://openai.com/dall-e-2">DALL·E 2</a></figcaption></figure><h4>Introduction</h4><p>In the dynamic parts of web application development and AI, the Streamlit Python library stands out as an important resource, known for its promptness and effectiveness in the application, especially in software prototype development. One of the most important aspects of Streamlit is its ability to craft specialized components that elevate its functionality. Through this, the community is able to develop and contribute custom components that can broaden the possible use cases for which Streamlit can be used.</p><p>My new contribution is the ‘<strong>streamlit-token-craft</strong>’ component, a brand new custom component I made. It is intended to <strong>manage</strong> and <strong>display</strong> token keys within the user interface. This component represents a key segment of token key management solutions integral to enhancing the Streamlit experience.</p><p>Such a component (custom or not) was missing from the Streamlit library, and I had to enhance an existing Streamlit app to manage the user’s keys. So, after a bit of research, I saw that I had to build something from scratch. I hope that this component will help developers in the future to build such apps and that some of them will want to contribute to it and step in further.</p><h4>What is the Streamlit Token Key Management Component?</h4><p>This specific component is tailored for incorporation into Streamlit applications. It mainly focuses on the <strong>administration</strong> and <strong>visualization</strong> of existing token keys within Streamlit applications. If you have used services across the Internet to create your keys, you may remember tables displaying your created keys and the ability to create a new key, rename existing keys, or delete one. With these keys, you are actually able to get access to APIs and various other protected resources. This feature is often a standard one in numerous products that distribute API access tokens to their users.</p><p>For example, given the current hype of Large Language Models and their popular quick prototype apps within the Streamlit Community, the “<strong>streamlit-craft-token”</strong> component is going to be a valuable enhancement in such apps (for their user management dashboards).</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/800/1*2yyKlzFuaA535Ln37WxW8w.gif" /><figcaption>Image created by the author</figcaption></figure><p>For more information, you can access the <a href="https://github.com/stavrostheocharis/streamlit-token-craft/blob/main/demo_col_selection_app.py">GitHub</a><a href="https://github.com/stavrostheocharis/streamlit-token-craft"> repo</a>.</p><p>A demo app showcasing the functionality of the component is also deployed in <a href="https://app-token-craft-example.streamlit.app/">Streamlit community cloud</a>!</p><h4>Features 🎉</h4><p>This part comes directly from the documentation of the component.</p><ul><li>Inline Editing: Edit tokens directly in the table like a ninja! 🥷</li><li>Dynamic Column Visibility: Play hide and seek with your columns! 🙈</li><li>Action Handling: Manage token deletion with style. It’s like having a mini-command center. 🎮</li><li>Responsive Design: Looks great on screens of all sizes, even on your grandma’s old monitor! 👵💻</li></ul><h4>Use Cases</h4><p>This component finds its application in a specific use case, from small-scale projects to larger ones. Whether it’s for accessing third-party APIs, cloud services, or internal authentication systems, it offers a robust solution for managing access credentials.</p><h3>Getting Started 🚀</h3><p>In order to get started you only need to install the &quot;streamlit-token-craft&quot; library into your project! This library is alraedy uploaded in <a href="https://pypi.org/project/streamlit-token-craft/">pypi</a>!</p><pre>pip install streamlit-token-craft</pre><h4>Usage Guide</h4><p>Here’s a very simple example of how to unleash the power of the Token Craft in your app:</p><pre>import streamlit as st<br>from token_craft import st_token_table<br><br>mock_tokens = [<br>    {<br>        &quot;id&quot;: &quot;token98a1c077&quot;,<br>        &quot;key&quot;: &quot;token98-e316-49d9&quot;,<br>        &quot;display_key&quot;: &quot;token98a...e5437d75&quot;,<br>        &quot;name&quot;: &quot;Token 1&quot;,<br>        &quot;dateCreated&quot;: &quot;2023-12-20&quot;,<br>        &quot;lastUsed&quot;: &quot;Never&quot;,<br>        &quot;is_active&quot;: True,<br>    },<br>]<br><br>rendered_tokens = st_token_table(<br>    tokens=mock_tokens,<br>    key=&quot;token_table&quot;,<br>)</pre><p>Through this basic code, you will be able to visualize the Tokens table in your app. Of course, more complex functionality is needed to use the component in combination with your own token key creation and handling service.</p><h3>Hands-On Examples</h3><h4>Example 1: Usage Scenario with token generation simulator</h4><p>In this example, I am going to showcase how the component can be used in combination with a <strong>token-handling service</strong>. Additional functionality, such as visualizing success after creating a new key, displaying warning messages, and adding interactive buttons, will demonstrate an almost ‘real’ use case.</p><p>The token handling service, simulated through a set of functions, allows for creating, deleting, and renaming tokens within a database (represented as a list of dictionaries in this case). This simulated service can easily be substituted with real API calls for an actual token-handling service.</p><p>So first, let’s create our token handling service:</p><pre>import uuid<br>from datetime import date<br><br># Simulated database (in-memory for this example)<br>_token_db = []</pre><p>uuid will be used to generate random unique &quot;token keys&quot;. The temporary db will actually be the _token_db list.</p><p>We need to define the essential functions of our service, including <strong>retrieving</strong>, <strong>adding</strong>, <strong>removing</strong>, and <strong>renaming</strong> tokens in the database. Additionally, a function will be used to <strong>format</strong> the token keys. This function will modify the display of a token after its initial viewing. For instance, a token is initially shown as ‘dc22ac88-aab4–4109-bf03-d27fbaaed7a8’ will subsequently be displayed in a shortened form like ‘dc22xxxxxxxd7a8’ for enhanced security.</p><pre>def get_tokens():<br>    &quot;&quot;&quot;Retrieve all active tokens from the mock database, replacing &#39;key&#39; with &#39;display_key&#39;.&quot;&quot;&quot;<br>    return [<br>        {**token, &quot;key&quot;: token[&quot;display_key&quot;]}  # Replace &#39;key&#39; with &#39;display_key&#39;<br>        for token in _token_db<br>        if token[&quot;is_active&quot;]<br>    ]<br><br>def format_text(text):<br>    if len(text) &lt;= 8:<br>        return &quot;xxxx&quot; + text[-4:]<br>    return text[:4] + &quot;xxxxxxx&quot; + text[-4:]<br><br>def add_token(name=&quot;New Token&quot;):<br>    &quot;&quot;&quot;Add a new token to the mock database.&quot;&quot;&quot;<br>    full_key = str(uuid.uuid4())<br>    # Create a simple hash of the key to display in the table, for example, take the first 8 characters.<br>    formated_key = format_text(full_key)<br>    new_token = {<br>        &quot;id&quot;: &quot;token&quot; + str(uuid.uuid4()),<br>        &quot;key&quot;: full_key,  # Store the full key<br>        &quot;display_key&quot;: formated_key,  # Store the formated version for display<br>        &quot;name&quot;: name,<br>        &quot;dateCreated&quot;: str(date.today()),<br>        &quot;lastUsed&quot;: &quot;Never&quot;,<br>        &quot;is_active&quot;: True,<br>    }<br>    _token_db.append(new_token)<br>    return new_token  # Return the full new_token to show the full key once<br><br>def remove_token(token_key):<br>    &quot;&quot;&quot;Deactivate a token in the mock database by its key.&quot;&quot;&quot;<br>    token = next((token for token in _token_db if token[&quot;key&quot;] == token_key), None)<br>    if token:<br>        token[&quot;is_active&quot;] = False<br><br>def update_token_name(token_key, new_name):<br>    &quot;&quot;&quot;Update the name of a specific token in the mock database.&quot;&quot;&quot;<br>    token = next((token for token in _token_db if token[&quot;key&quot;] == token_key), None)<br>    if token:<br>        token[&quot;name&quot;] = new_name</pre><p>Now, our token management service is ready to be used within our Streamlit app! (I suppose that we save it in a .py file named demo_mock_token_service.py)</p><p>Let’s initialize our Streamlit app now. To manage and integrate various components across different reruns of the app, we will utilize Streamlit’s session state class.</p><p>If you are not familiar with using <strong>streamlit’s session state class,</strong> I recommend checking out my two detailed articles: <a href="https://pub.towardsai.net/unlocking-the-power-of-session-state-in-streamlit-1-2-c7acda8dda6c">Unlocking the Power of Session State in Streamlit (1/2)</a> and <a href="https://pub.towardsai.net/unlocking-the-power-of-session-state-in-streamlit-2-2-832a3a136cc0">Unlocking the Power of Session State in Streamlit (2/2)</a>.</p><p>Import the needed libraries:</p><pre>import streamlit as st<br>import demo_mock_token_service as mts<br>from token_craft import st_token_table</pre><p>Initialization of the session state variables and a custom function that handles the changes in session state and reruns the app (it will be needed in several parts within the app code).</p><pre># Initialize session state keys if they don&#39;t exist<br>for key in [<br>    &quot;show_basic_key&quot;,<br>    &quot;show_add_key_form&quot;,<br>    &quot;show_success_message&quot;,<br>    &quot;success_message&quot;,<br>    &quot;show_table&quot;,<br>]:<br>    if key not in st.session_state:<br>        st.session_state[key] = (<br>            True if key in [&quot;show_basic_key&quot;, &quot;show_table&quot;] else False<br>        )<br><br><br># Function to reset the success message and related state variables<br>def reset_state(<br>    show_basic_key=True,<br>    show_add_key_form=False,<br>    show_success_message=False,<br>    show_table=True,<br>):<br>    st.session_state.update(<br>        {<br>            &quot;show_basic_key&quot;: show_basic_key,<br>            &quot;show_add_key_form&quot;: show_add_key_form,<br>            &quot;show_table&quot;: show_table,<br>            &quot;show_success_message&quot;: show_success_message,<br>        }<br>    )<br>    st.rerun()</pre><p>Now, the part for the main button for creating a new token key:</p><pre>if st.session_state[&quot;show_basic_key&quot;]:<br>    # Button to show the form for adding a new key<br>    if st.button(&quot;Create new secret key&quot;):<br>        reset_state(show_basic_key=False, show_add_key_form=True, show_table=False)</pre><p>When the <strong>button</strong> is pressed, a <strong>form</strong> should open to allow the user to input their preferred name. Upon the form’s opening, the initial button and the token table should be <strong>hidden</strong>.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*skhKcQJU4WJgAm2djPLIJQ.png" /><figcaption>Image created by the author</figcaption></figure><p>Then, the form part and the key creation <strong>verification</strong> should take place. The form requires the user to input at least one character for the name, failing which a warning is displayed. Additionally, the name is limited to 18 characters. If the key creation is successful, a confirmation message is saved in the session state for subsequent display. For users opting not to create a key, a cancel button resets the app to its initial state.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*-dMu1SptzXyvTGWGssNpYA.png" /><figcaption>Image created by the author</figcaption></figure><blockquote>It’s important to note how various parts of the token service are integrated within the code.</blockquote><pre># The form for adding a new key<br>if st.session_state[&quot;show_add_key_form&quot;]:<br>    with st.form(key=&quot;add_key_form&quot;):<br>        new_key_name = st.text_input(<br>            &quot;Name&quot;,<br>            placeholder=&quot;Enter the key name&quot;,<br>            disabled=st.session_state[&quot;show_success_message&quot;],<br>            max_chars=18,<br>        )<br><br>        col1, col2 = st.columns([3, 10])<br>        with col1:<br>            submit_button = st.form_submit_button(<br>                label=&quot;Create secret key&quot;,<br>            )<br>        with col2:<br>            cancel_button = st.form_submit_button(label=&quot;Cancel&quot;, type=&quot;primary&quot;)<br><br>        if submit_button:<br>            if new_key_name:  # Check if the name is not empty<br>                new_token = mts.add_token(new_key_name)  # Call function to add token<br>                # Set the success message and flag<br>                st.session_state[<br>                    &quot;success_message&quot;<br>                ] = f&quot;New secret key created successfully! Key: {new_token[&#39;key&#39;]}&quot;<br>                # st.session_state[&quot;show_success_message&quot;] = True<br>                reset_state(<br>                    show_basic_key=False,<br>                    show_success_message=True,<br>                    show_table=False,<br>                )<br>            else:<br>                st.warning(&quot;Please enter a name for the key.&quot;)<br>        elif cancel_button:<br>            reset_state()</pre><p>After successfully creating the token, we display it to the user as an ‘<strong>one-time view</strong>’ key:</p><pre># Show a success message if a new key was added<br>if st.session_state[&quot;show_success_message&quot;]:<br>    container = st.container(border=True)<br>    container.write(<br>        &quot;Stash this secret key in a super safe yet reachable hidey-hole! It&#39;s like a one-off magic ticket – once gone from here, it&#39;s gone for good. Lose it, and you&#39;re off to the wizarding world of making a new one! 🗝️✨🧙‍♂️&quot;<br>    )<br>    container.success(st.session_state[&quot;success_message&quot;])<br>    # &#39;OK&#39; button to reset the success state<br>    if container.button(&quot;OK&quot;):<br>        reset_state(show_success_message=False)</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*FU9N4maaLNgm2iAj4GCw0Q.png" /><figcaption>Image created by the author</figcaption></figure><p>Now, let’s delve into the code for the <strong>token table</strong>, which is the most important aspect of this tutorial:</p><pre>if st.session_state[&quot;show_table&quot;]:<br>    # Display the keys in the table with the hashed version<br>    rendered_tokens = st_token_table(<br>        tokens=mts.get_tokens(),<br>        key=&quot;token_table&quot;,<br>    )<br><br>    # Check for updates from the React component<br>    if rendered_tokens is not None:<br>        needs_rerun = False<br><br>        for rendered_token in rendered_tokens:<br>            current_token = next(<br>                (t for t in mts._token_db if t[&quot;display_key&quot;] == rendered_token[&quot;key&quot;]),<br>                None,<br>            )<br><br>            if current_token:<br>                # If the token should be deactivated<br>                if not rendered_token[&quot;is_active&quot;] and current_token[&quot;is_active&quot;]:<br>                    mts.remove_token(current_token[&quot;key&quot;])  # Use the full key here<br>                    needs_rerun = True<br>                # If the token&#39;s name should be changed<br>                elif rendered_token[&quot;name&quot;] != current_token[&quot;name&quot;]:<br>                    mts.update_token_name(<br>                        current_token[&quot;key&quot;], rendered_token[&quot;name&quot;]<br>                    )  # Use the full key here<br>                    needs_rerun = True<br><br>        if needs_rerun:<br>            st.rerun()</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*8V2SKWstSz6ei0k0F4eXAQ.png" /><figcaption>Image created by the author</figcaption></figure><p>It’s important to remember that Streamlit components typically operate in the background on React or another JavaScript framework. Consequently, we need a way to render and communicate possible changes between the Streamlit Interface and the React component. Fortunately, most of these processes occur automatically.</p><p>In the above blocks, we actually compare the token values based as they are changed by the user, between the component&#39;s state and the db.</p><p>If a token is <strong>active</strong> in the service but marked as <strong>inactive</strong> in our app, it should be converted to inactive (removed for the user&#39;s view). With the same logic, if a name is different between the app and the db, the db should be updated accordingly.</p><p>The function <strong><em>st.rerun()</em></strong> is used to directly update the <strong>token table </strong>with the possible changes made. In some apps, you might have noticed that changes made by the user are only reflected after a subsequent action triggers a <strong>rerun</strong>. The app actually shows the change when another action happens in a second phase (when something changes, we have a rerun in the app). In order to avoid this delayed update, we directly trigger the rerun, ensuring that the changes are visible in the app in “real-time”.</p><p>For the detailed code, check out the <a href="https://github.com/stavrostheocharis/streamlit-token-craft/blob/main/demo_full_app.py">example app in </a><a href="https://github.com/stavrostheocharis/streamlit-token-craft/blob/main/demo_col_selection_app.py">GitHub</a>.</p><h4>Example 2: Advanced Implementation with Custom Settings for Columns Choice</h4><p>Through this component, you also have the ability to hide specific columns on demand.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/800/1*QX_5l9kWhQF9lqbwLe8_wQ.gif" /><figcaption>Image created by the author</figcaption></figure><p>To accomplish this, we first need to create a sidebar with checkboxes for each column:</p><pre>column_visibility_settings = {<br>    &quot;name&quot;: st.sidebar.checkbox(&quot;Show Name&quot;, True),<br>    &quot;key&quot;: st.sidebar.checkbox(&quot;Show Key&quot;, True),<br>    &quot;dateCreated&quot;: st.sidebar.checkbox(&quot;Show Date Created&quot;, True),<br>    &quot;lastUsed&quot;: st.sidebar.checkbox(&quot;Show Last Used&quot;, True),<br>    &quot;actions&quot;: st.sidebar.checkbox(&quot;Show Actions&quot;, True),<br>}</pre><p>And the <strong>token table</strong> needs to get the <strong><em>column_visibility</em></strong> argument:</p><pre>rendered_tokens = st_token_table(<br>    tokens=mts.get_tokens(),<br>    key=&quot;token_table&quot;,<br>    column_visibility=column_visibility_settings,<br>)</pre><p>For the detailed code, check out the <a href="https://github.com/stavrostheocharis/streamlit-token-craft/blob/main/demo_col_selection_app.py">example app on </a><a href="https://github.com/stavrostheocharis/streamlit-token-craft/blob/main/demo_col_selection_app.py">GitHub</a>.</p><h3>Conclusion</h3><p>In conclusion, the <strong>&quot;streamlit-token-craft&quot;</strong> stands as an important component in streamlit web applications that target the user key management parts. This component introduces a simplified approach to managing and displaying token keys in the app, filling a gap not addressed by previous components.</p><p>By providing hands-on examples, the practicality and ease of use are being demonstrated. I encourage you to experiment with this new component for managing and displaying keys in your apps.</p><p>Possible feedback is more than welcome! If you want to contribute to the project, please read the <a href="https://github.com/stavrostheocharis/streamlit-token-craft/blob/main/CONTRIBUTING.md">contribution guide</a>.</p><p>🌟 If you enjoyed this article, <a href="https://medium.com/@stavrostheocharis">follow me on Medium to read more</a>!</p><p>🌟 you can also <a href="http://www.linkedin.com/in/stavros-theocharis-ai">follow me on Linkedin!</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=a7c7d7351f39" width="1" height="1" alt=""><hr><p><a href="https://pub.towardsai.net/brand-new-streamlit-component-token-key-mastery-a7c7d7351f39">Brand New Streamlit Component: Token Key Mastery</a> was originally published in <a href="https://pub.towardsai.net/">Towards AI</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Unlocking the Power of Session State in Streamlit (2/2)]]></title>
            <link>https://pub.towardsai.net/unlocking-the-power-of-session-state-in-streamlit-2-2-832a3a136cc0?source=rss-216e390c9a41------2</link>
            <guid isPermaLink="false">https://medium.com/p/832a3a136cc0</guid>
            <category><![CDATA[similarity-search]]></category>
            <category><![CDATA[streamlit-app-deployment]]></category>
            <category><![CDATA[hands-on-tutorials]]></category>
            <category><![CDATA[software-engineering]]></category>
            <category><![CDATA[streamlit]]></category>
            <dc:creator><![CDATA[Stavros Theocharis]]></dc:creator>
            <pubDate>Thu, 28 Sep 2023 16:01:35 GMT</pubDate>
            <atom:updated>2024-02-05T16:04:43.527Z</atom:updated>
            <content:encoded><![CDATA[<h4>Matching Rows Between Two Dataframes</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*js9CY9ynlPJLd1s5V2u3Mw.png" /><figcaption>Image by the author</figcaption></figure><h3>Introduction</h3><p>In my previous <a href="https://medium.com/towards-artificial-intelligence/unlocking-the-power-of-session-state-in-streamlit-1-2-c7acda8dda6c">related article</a>, we saw what Streamlit’s session state is and how it can be used in practice with a simple example. Streamlit can be really used for nice apps, and someone can easily develop such apps with only a few lines of code. I think that in the beginning it was considered to be more for creating prototypes, but as time passes, I believe that it can be used for more production apps in general. When it comes to proprietary tools made by organizations for their in-house work, design isn’t as important. Instead, the usefulness and overall value they provide are more important. That’s why I believe Streamlit will be one of the packages for building internal tools in organizations in the near future.</p><h3>Creating a Dynamic Row Matching App for Two Dataframes</h3><p>So, as I promised, let’s see a nice example. In my opinion, this is a real-world example, as many of us sometimes want to match rows from one dataframe with rows from another dataframe. Of course there are specific requirements, and the statement “matching” is a bit blurry. In this example, we do not care about the matching functionality, but mainly we care about the UI functionality with Streamlit.</p><p>Let’s make this example more concrete!</p><h4>Mock data creation</h4><p>We have a dataset with Car owner information and a dataset with Cars information. In the Cars dataset, we have only the name of the owner. So, we need an app that, based on the name of the Cars dataset, will propose Car owners, and then the user will be able to validate whether this matches or not and make the appropriate adjustments.</p><p>Let’s create these two datasets using pandas dataframes:</p><pre>import pandas as pd<br><br># Sample data for Car Owners<br>owners_data = {<br>    &#39;OwnerID&#39;: [1, 2, 3, 4, 5],<br>    &#39;OwnerName&#39;: [&#39;Alice&#39;, &#39;Bob&#39;, &#39;Charlie&#39;, &#39;David&#39;, &#39;Eve&#39;],<br>    &#39;OwnerSurname&#39;: [&#39;Smith&#39;, &#39;Johnson&#39;, &#39;Brown&#39;, &#39;Davis&#39;, &#39;Wilson&#39;],<br>    &#39;OwnerEmail&#39;: [&#39;alice@example.com&#39;, &#39;bob@example.com&#39;, &#39;charlie@example.com&#39;, &#39;david@example.com&#39;, &#39;eve@example.com&#39;]<br>}<br><br># Sample data for Cars<br>cars_data = {<br>    &#39;CarID&#39;: [101, 102, 103, 104, 105],<br>    &#39;CarName&#39;: [&#39;Honda Civic&#39;, &#39;Toyota Camry&#39;, &#39;Ford Mustang&#39;, &#39;Chevrolet Malibu&#39;, &#39;Nissan Altima&#39;],<br>    &#39;OwnerName&#39;: [&#39;Alice&#39;, &#39;Charlie&#39;, &#39;Eve&#39;, &#39;Bob&#39;, &#39;Eve&#39;],  <br>    &#39;OwnerSurname&#39;: [&#39;Smith&#39;, &#39;Brown&#39;, &#39;Wilson&#39;, &#39;Johnson&#39;, &#39;Wilson&#39;] # OwnerSurname based on the Car&#39;s owner<br>}</pre><p>So, the created dataframes can be shown below:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*HpWRMadg_p1aueuu-sZ0aQ.png" /><figcaption>Car owners dataframe [Image by the author]</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/696/1*5nkICNQHF6IiqrYIfD6TRQ.png" /><figcaption>Cars dataframe [Image by the author]</figcaption></figure><p>As we can see, there are some typos in the Cars dataframe, or uppercase and lowercase characters. This is a common situation with real-world data when information is gathered manually. I can say that the data in these two dataframes is good (in reality, more problems exist!).</p><h4>Matching algorithm</h4><p>So the logic is simple: If we have a match based on a score applied to the ‘OwnerSurname’ column, we need to match them through the IDs. After that, we need to display these matches in our app and let the user choose based on the proposals made by the algorithm (this is often called “human in the loop”).</p><p>Let’s create a simple matching function. We will use the <a href="https://pypi.org/project/rapidfuzz/">rapidfuzz library</a>, which is <em>a fast string matching library for Python and C++, which is using the string similarity calculations from </em><a href="https://github.com/seatgeek/fuzzywuzzy"><em>FuzzyWuzzy</em></a><em>.</em></p><p>Through the below function, we get a score on the similarity between two strings.</p><pre>from rapidfuzz import fuzz<br><br>def calculate_distance_ratio(text_1, text_2):<br>    try:<br>        text_1 = text_1.upper()<br>        text_2 = text_2.upper()<br>        return round(fuzz.QRatio(text_1, text_2) / 100, 2)<br>    except:<br>        return 0</pre><p>Ok, now the compare part between the rows of the dataframes. I know this is not efficient when applied to many rows, but it is just an example:</p><pre>final_df = pd.DataFrame()<br>for idx1, row1 in car_owners_df.iterrows():<br>    for idx2, row2 in cars_df.iterrows():<br>        score = calculate_distance_ratio(row1[&quot;OwnerSurname&quot;], row2[&quot;OwnerSurname&quot;])<br>        temp_row = pd.DataFrame(row1).T<br>        temp_row[&quot;score&quot;] = score<br>        temp_row[&quot;CarID&quot;] = row2[&quot;CarID&quot;]<br>        final_df = pd.concat([final_df, temp_row], axis=0) <br>        final_df = final_df.reset_index(drop=True)</pre><p>This results in something like below:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*VKFeybtMc0hHXLjuZX2utg.png" /><figcaption>Part of the constructed dataframe with scores [Image by the author]</figcaption></figure><h4>Streamlit app</h4><p>Ok, now let’s create the Streamlit app and the corresponding functionality. Keep your focus on this part because it may take some time to understand it in depth.</p><pre>dif_pages = list(car_owners_df[&quot;OwnerID&quot;].unique())</pre><p>“dif_pages” is based on the different IDs of the Car Owners. Based on this variable, we will change pages in the app.</p><p>Let’s write some callback functions:</p><pre>def change_position():<br>    st.session_state.data[&quot;position&quot;] = st.session_state.data[&quot;position&quot;] + 1<br><br>def click_begin_button():<br>    st.session_state.begin_button = True</pre><p>So, the “change_position” function will change the “position” in the session state each time. Keep in mind that each time a button or something is triggered, everything is running again. So, we need a session state to keep variable values over reruns.</p><p>“click_begin_button”, as can be identified by the name, will be used in the beginning as a callback to the “begin” button in order to initialize the functionality of the app.</p><p>Let’s write some streamlit code:</p><pre>import streamlit as st<br>import numpy as np<br><br>st.title(&quot;Dynamic Row Matching App&quot;)<br><br>if &quot;begin_button&quot; not in st.session_state:<br>    st.session_state.begin_button = False<br><br>if st.session_state.begin_button == False:<br>    with st.expander(&quot;What is this app?&quot;, expanded=True):<br>        st.write(<br>            &quot;This is an example app for showcasing session state in a real-world example&quot;<br>        )<br>        st.write(&quot;&quot;)</pre><p>Now we want to build the logic of the dataframes that will be visualized after the “begin” button is pressed. We will create two tabs. The first one will be the “Matching” tab, where the user can interact with elements and select the preferred combinations. Then, by pressing the “match” button, two actions will take place. The first one is that the Car Owner will change in the “Matching” tab. Secondly, the validated combination will be appended to a combination dataframe in the “Display” tab.</p><p>As can be seen below, we keep both the current position in the session state and the final combination dataframe.</p><pre>position = 0<br><br>if st.session_state.begin_button:<br>    final_combination_df = pd.DataFrame()<br><br>    if &quot;data&quot; not in st.session_state:<br>        st.session_state.data = {<br>            &quot;position&quot;: position,<br>            &quot;final_combination&quot;: final_combination_df,<br>        }<br><br>begin_button = st.sidebar.button(<br>    &quot;Begin&quot;, key=&quot;begin_but&quot;, type=&quot;primary&quot;, on_click=click_begin_button<br>)</pre><p>We can see the below interface:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*e964U158NZkSNNP5QSp8Cw.png" /><figcaption>Image by the author</figcaption></figure><p>Let’s create some helping functions:</p><pre>def identify_id(df, id):<br>    &quot;&quot;&quot;<br>    Locates the specific IDs in a dataframe and returns the corresponding dataframe<br>    &quot;&quot;&quot;<br>    return df.loc[df[&quot;OwnerID&quot;] == id].reset_index(drop=True)<br><br>def create_cars_table(<br>    final, car_owner_id, cars, threshold_to_keep=0.26, threshold_to_select=0.33<br>):<br>    try:<br>        # Find for the specific merchant the transactions<br>        car_owner_df = final.loc[final[&quot;OwnerID&quot;] == car_owner_id]<br>        print(car_owner_df)<br>        # Keep only those above the threshold<br>        car_owner_df = car_owner_df.loc[car_owner_df[&quot;score&quot;] &gt;= threshold_to_keep]<br><br>        id_list = car_owner_df[&quot;CarID&quot;].to_list()  # which are the cars&#39;id to bring<br>        identified_cars_df = cars.loc[cars[&quot;CarID&quot;].isin(id_list)]<br>        # Get also the scores from merging<br>        identified_cars_df = (<br>            identified_cars_df.merge(<br>                car_owner_df[[&quot;CarID&quot;, &quot;score&quot;]],<br>                left_on=&quot;CarID&quot;,<br>                right_on=&quot;CarID&quot;,<br>                how=&quot;left&quot;,<br>            )<br>            .sort_values(by=&quot;score&quot;, ascending=False)<br>            .reset_index(drop=True)<br>        )<br><br>        if len(identified_cars_df) &gt; 0:<br>            identified_cars_df.insert(0, &quot;selection&quot;, False)  # new column in front<br>            # If some transactions are above the threshold, select them<br>            identified_cars_df[&quot;selection&quot;] = np.where(<br>                identified_cars_df[&quot;score&quot;] &gt;= threshold_to_select, True, False<br>            )<br>    except Exception:<br>        identified_cars_df = pd.DataFrame()<br>    return identified_cars_df</pre><p>“create_cars_table” is actually a function that builds the combined dataframe of selected cars and owners. We also use as arguments two thresholds. “threshold_to_keep” is the threshold that will indicate which car rows will be shown in the app (above that threshold). “threshold_to_select” is the threshold that will indicate which car rows will be selected by default in the app.</p><p>Now, let’s create one more callback for the match button:</p><pre>def change_position_on_ok():<br>    # Find and loc the selected cars<br>    temp_selection_df = edited_car_df.loc[<br>        edited_car_df[&quot;selection&quot;] == True<br>    ].reset_index(drop=True)<br>    # Add the current id<br>    temp_selection_df[&quot;Owner_ID&quot;] = current_id<br>    final_combination_df = pd.concat(<br>        [st.session_state.data[&quot;final_combination&quot;], temp_selection_df],<br>        ignore_index=True,<br>        sort=True,<br>    )<br>    st.session_state.data[&quot;final_combination&quot;] = final_combination_df.drop(<br>        [&quot;selection&quot;], axis=1<br>    )<br>    change_position()</pre><p>And…. the final parts with the tabs:</p><pre>if st.session_state.begin_button == True:<br>    matching, dis_matched = st.tabs([&quot;Matching&quot;, &quot;Display matched&quot;])<br><br>    with matching:<br>        if st.session_state.data[&quot;position&quot;] &lt; len(dif_pages):<br>            current_id = dif_pages[st.session_state.data[&quot;position&quot;]]<br>            identified_owner = identify_id(car_owners_df, current_id)<br>            identified_cars_df = create_cars_table(<br>                final=final_df,<br>                car_owner_id=current_id,<br>                cars=cars_df,<br>            )<br><br>            if not identified_cars_df.empty:<br>                st.header(&quot;Car Owner&quot;)<br>                edited_owner_df = st.data_editor(identified_owner)<br>                st.header(&quot;Cars&quot;)<br>                edited_car_df = st.data_editor(identified_cars_df)<br><br>                ok_button = st.button(<br>                    &quot;Match&quot;,<br>                    key=&quot;ok_button&quot;,<br>                    type=&quot;primary&quot;,<br>                    on_click=change_position_on_ok,<br>                )<br><br>    with dis_matched:<br>        st.header(&quot;Matched Table&quot;)<br>        final_edited_combination_df = st.data_editor(<br>            st.session_state.data[&quot;final_combination&quot;]<br>        )<br>        st.session_state.data[&quot;final_combination&quot;] = final_edited_combination_df</pre><p>We use “st.data_editor” to give the user the ability to edit the showcased information if needed.</p><p>The final app can be seen below:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/600/1*g_U9FrhkeUfuUIO7Q5iWVw.gif" /><figcaption>Image by the author</figcaption></figure><h3>Conclusion</h3><p>During the exploration of Streamlit’s functionalities, we have examined the pragmatic uses of session state and observed how this apparently straightforward technology may enable developers to construct exceptional applications with minimal lines of code. Streamlit was once perceived as a tool primarily used for rapid prototyping. However, its adaptability and user-friendly nature have facilitated its integration into the domain of production-grade applications.</p><p>In this hands-on example, we can identify the infinite parts and use cases that Streamlit can cover. In the near future, I am thinking of building a package that will encapsulate all the above parts and make it easier for the user to adapt based on their needs. If you have any ideas, please reach out!</p><p>The first part of the “session state” series can be found <a href="https://medium.com/towards-artificial-intelligence/unlocking-the-power-of-session-state-in-streamlit-1-2-c7acda8dda6c">here</a>.</p><p>You can also check out my previous articles, which cover various parts of data science, AI, and software. Some of my streamlit articles are:</p><ul><li><a href="https://pub.towardsai.net/empowering-your-app-with-streamlits-new-connections-feature-and-interactive-plotly-maps-8029cf0787e8">Empowering Your App with Streamlit’s New Connections Feature and Interactive Plotly Maps</a></li><li><a href="https://pub.towardsai.net/how-to-create-an-end-2-end-text-paraphrase-app-db83a4e05918">How To Create an End-2-End Text Paraphrase App</a></li></ul><p>🌟 If you enjoyed this article, <a href="https://medium.com/@stavrostheocharis">follow me on Medium to read more</a>!</p><p>🌟 you can also <a href="http://www.linkedin.com/in/stavros-theocharis-ai">follow me on Linkedin!</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=832a3a136cc0" width="1" height="1" alt=""><hr><p><a href="https://pub.towardsai.net/unlocking-the-power-of-session-state-in-streamlit-2-2-832a3a136cc0">Unlocking the Power of Session State in Streamlit (2/2)</a> was originally published in <a href="https://pub.towardsai.net/">Towards AI</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Unlocking the Power of Session State in Streamlit (1/2)]]></title>
            <link>https://pub.towardsai.net/unlocking-the-power-of-session-state-in-streamlit-1-2-c7acda8dda6c?source=rss-216e390c9a41------2</link>
            <guid isPermaLink="false">https://medium.com/p/c7acda8dda6c</guid>
            <category><![CDATA[data]]></category>
            <category><![CDATA[streamlit-app-deployment]]></category>
            <category><![CDATA[visualization]]></category>
            <category><![CDATA[session-state]]></category>
            <category><![CDATA[streamlit]]></category>
            <dc:creator><![CDATA[Stavros Theocharis]]></dc:creator>
            <pubDate>Wed, 27 Sep 2023 20:01:33 GMT</pubDate>
            <atom:updated>2024-02-05T16:05:02.974Z</atom:updated>
            <content:encoded><![CDATA[<h4>A Practical Example</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/960/1*noMYhEHseS1eTG6kT5oyQw.gif" /><figcaption>Image by <a href="https://github.com/streamlit/streamlit">streamlit</a></figcaption></figure><h3>Introduction</h3><p>Streamlit has had a quick surge in popularity due to its efficacy in facilitating the development of web applications with minimal exertion. Although Streamlit simplifies the process of creating interactive applications, certain projects may necessitate more intricate features. This blog article aims to examine the notion of “session state” in Streamlit and illustrate its potential for developing applications that rival others in terms of functionality and user experience. There is also a second part available for you to read: <a href="https://pub.towardsai.net/unlocking-the-power-of-session-state-in-streamlit-2-2-832a3a136cc0">Unlocking the Power of Session State in Streamlit (2/2) — Matching Rows Between Two Dataframes</a> which includes a more practical guide.</p><h3>What is a Session State?</h3><p>Prior to delving into the pragmatic elements, it is imperative to establish a comprehensive understanding of the concept of session state within the Streamlit package.</p><p>As stated in the official <a href="https://docs.streamlit.io/library/api-reference/session-state">docs</a>:</p><blockquote>Session State is a way to share variables between reruns, for each user session. In addition to the ability to store and persist state, Streamlit also exposes the ability to manipulate state using Callbacks. Session state also persists across apps inside a <a href="https://docs.streamlit.io/library/get-started/multipage-apps">multipage app</a>.</blockquote><p>Why does it reference “reruns”?</p><p>To be as generic as I can, the answer is that each time the user interacts with something (i.e., a button), the whole code reruns. When rerunning the code, the variables included may change. In some apps, it is important to be able to keep the values of some variables between reruns and alternate them on demand. That’s why the session state is important. It is our storage that keeps “information” between the different reruns.</p><h3>How to use Session State?</h3><p>So, let’s directly see some code importing the necessary libraries:</p><pre>import streamlit as st</pre><p>Session state can be accessed easily in order to update it, or create a new variable inside:</p><pre>st.session_state.data[&quot;test_var&quot;] = True</pre><p>In the above example, a new key was added, “data”, including as value “test_var” with the value True. You can use this new variable very easily in your code, as you could with any other variable:</p><pre>st.text_input(&quot;Enter your info:&quot;, session_state.data.test_var)</pre><h4>Leveraging Session State for Complex Functionality</h4><p>The utilization of the session state is advantageous in the management of user sessions, processing form submissions, and monitoring the application’s state across several components. The user possesses the capability to generate conditional logic by utilizing session state variables, hence enabling the dynamic modification of the content within their application.</p><p>In this example, <strong>callbacks</strong> are being used. Let’s create a simple app that can calculate the square of a number using a callback function. Here’s a snippet of how this can be achieved:</p><pre>if &quot;user_number&quot; not in st.session_state:<br>    st.session_state[&quot;user_number&quot;] = 0<br><br>if &quot;square_result&quot; not in st.session_state:<br>    st.session_state[&quot;square_result&quot;] = 0<br><br># Create a callback function<br>def calculate_square():<br>    st.session_state[&quot;square_result&quot;] = st.session_state.user_number**2<br><br># Create a user input field<br>st.session_state.user_number = st.number_input(<br>    &quot;Enter a number:&quot;, value=st.session_state.user_number<br>)<br><br># Add a button to trigger the calculation<br>button = st.button(&quot;Calculate Square&quot;, on_click=calculate_square)<br><br>st.write(<br>    f&quot;The square of {st.session_state.user_number} is {st.session_state.square_result}&quot;<br>)</pre><p>Instead of using the “on_click” argument, you can use something like the below (depending on your coding preference):</p><pre># Add a button to trigger the calculation<br>if st.button(&quot;Calculate Square&quot;)<br>    calculate_square()  </pre><p>The above example app can be seen below:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/600/1*sxAOU-Kiy8QMHUFzjEwEYA.gif" /><figcaption>Image by the author</figcaption></figure><h3>Conclusion</h3><p>By utilizing Streamlit’s session state feature, developers may augment the functionality and user experience of their applications to compete with more complex frameworks. By leveraging the capabilities of the session state, one can enhance the performance and functionality of Streamlit projects to a higher level. Gain firsthand experience in harnessing the potential of developing dynamic and interactive applications that have a profound influence. Embrace the opportunity and commence a venture focused on constructing outstanding applications that captivate interest and establish an enduring impact.</p><p>The second part of the “session state” series can be found <a href="https://pub.towardsai.net/unlocking-the-power-of-session-state-in-streamlit-2-2-832a3a136cc0">here</a>.</p><p>You can also check out my previous articles, which cover various parts of data science, AI, and software. Some of my streamlit articles are:</p><ul><li><a href="https://pub.towardsai.net/empowering-your-app-with-streamlits-new-connections-feature-and-interactive-plotly-maps-8029cf0787e8">Empowering Your App with Streamlit’s New Connections Feature and Interactive Plotly Maps</a></li><li><a href="https://pub.towardsai.net/how-to-create-an-end-2-end-text-paraphrase-app-db83a4e05918">How To Create an End-2-End Text Paraphrase App</a></li></ul><p>🌟 If you enjoyed this article, <a href="https://medium.com/@stavrostheocharis">follow me on Medium to read more</a>!</p><p>🌟 you can also <a href="http://www.linkedin.com/in/stavros-theocharis-ai">follow me on Linkedin!</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=c7acda8dda6c" width="1" height="1" alt=""><hr><p><a href="https://pub.towardsai.net/unlocking-the-power-of-session-state-in-streamlit-1-2-c7acda8dda6c">Unlocking the Power of Session State in Streamlit (1/2)</a> was originally published in <a href="https://pub.towardsai.net/">Towards AI</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Empowering Your App with Streamlit’s New Connections Feature and Interactive Plotly Maps]]></title>
            <link>https://pub.towardsai.net/empowering-your-app-with-streamlits-new-connections-feature-and-interactive-plotly-maps-8029cf0787e8?source=rss-216e390c9a41------2</link>
            <guid isPermaLink="false">https://medium.com/p/8029cf0787e8</guid>
            <category><![CDATA[plotly]]></category>
            <category><![CDATA[streamlit-app-deployment]]></category>
            <category><![CDATA[streamlit]]></category>
            <category><![CDATA[air-quality]]></category>
            <category><![CDATA[python-app-development]]></category>
            <dc:creator><![CDATA[Stavros Theocharis]]></dc:creator>
            <pubDate>Sat, 05 Aug 2023 16:01:55 GMT</pubDate>
            <atom:updated>2024-02-05T16:05:16.769Z</atom:updated>
            <content:encoded><![CDATA[<h4>Aeroa: An app for air quality visualizations</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Wetl2JooJk9UCkyrNaJsnA.png" /><figcaption>Image created by the author</figcaption></figure><h3>Introduction</h3><p><a href="https://streamlit.io/">Streamlit</a> recently, and at the time that this article is being written, announced its new feature, <em>st.experimental_connection, </em>and I was very interested in using it and understanding how it works. More details can be found in their official <a href="https://docs.streamlit.io/library/api-reference/connections">docs</a>.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/886/1*xt1_OT9ugkG-4Vo5qY45EQ.png" /><figcaption>Image by <a href="https://docs.streamlit.io/library/api-reference/connections">streamlit</a></figcaption></figure><p>So, what is this new feature, and what can you do with it? Through it, you can create a new connection to a data store or API or return an existing one. You also have plenty of configuration options, such as credentials, secrets, etc., for connections that are taken from various sources, such as any connection-specific configuration files and the app’s <em>secrets.toml</em> files and the kwargs passed to this function. If you ask me, for such things, you could build something alone with Streamlit and your own code (required time), but now Streamlit gives you better abilities with a built-in feature.</p><h3>Details of the connection class</h3><p>So, let’s see some more details about the main class that this feature uses. Streamlit gives you the ability to create your own connection class and call it inside your app. There are already some built-in connection classes for SQL and Snowpark in Snowflake. It is very easy to use them, as the example for SQL below:</p><pre>import streamlit as st<br>conn = st.experimental_connection(&quot;sql&quot;)</pre><p>you can also do more complex stuff, but we will discuss it below in the next specific example.</p><h3>Build your own Connection class</h3><p>Streamlit announced its new <a href="https://discuss.streamlit.io/t/enter-the-summit-hackathon/40473">hackathon</a> in order to build apps that allow you to create your own connection classes. So I decided to participate and create a simple app because of time restrictions. This app will use air quality and some weather data provided by an open API called <a href="https://api.openaq.org/docs">OpenAQ</a>. It provided several pieces of data for almost every country in the world based on installed sensors in specific areas.</p><p>In order to use the above API, we have to create a new connection class. This class will include the new session of the requests library, one query that gets the countries (it needs a small custom-made code), one main query that gets the specific data of the chosen country, and…. that’s all. The below part will be included in a <em>“connection.py”</em> file.</p><pre>from streamlit.connections import ExperimentalBaseConnection<br>import requests<br>import streamlit as st<br><br>class OpenAQConnection(ExperimentalBaseConnection[requests.Session]):<br>    def __init__(self, *args, **kwargs):<br>        super().__init__(*args, **kwargs)<br>        self._resource = self._connect(**kwargs)<br><br>    def _connect(self, **kwargs) -&gt; requests.Session:<br>        session = requests.Session()<br><br>        return session<br><br>    def cursor(self):<br>        return self._resource<br><br>    def query_countries(<br>        self, limit=100, page=1, sort=&quot;asc&quot;, order_by=&quot;name&quot;, ttl: int = 3600<br>    ):<br>        @st.cache_data(ttl=ttl)<br>        def _query_countries(limit, page, sort, order_by):<br>            params = {<br>                &quot;limit&quot;: limit,<br>                &quot;page&quot;: page,<br>                &quot;sort&quot;: sort,<br>                &quot;order_by&quot;: order_by,<br>            }<br>            with self._resource as s:<br>                response = s.get(&quot;https://api.openaq.org/v2/countries&quot;, params=params)<br>            return response.json()<br><br>        return _query_countries(limit, page, sort, order_by)<br><br>    def query(<br>        self,<br>        country_id,<br>        limit=1000,<br>        page=1,<br>        offset=0,<br>        sort=&quot;desc&quot;,<br>        radius=1000,<br>        order_by=&quot;lastUpdated&quot;,<br>        dumpRaw=&quot;false&quot;,<br>        ttl: int = 3600,<br>    ):<br>        @st.cache_data(ttl=ttl)<br>        def _get_locations_measurements(<br>            country_id, limit, page, offset, sort, radius, order_by, dumpRaw<br>        ):<br>            params = {<br>                &quot;limit&quot;: limit,<br>                &quot;page&quot;: page,<br>                &quot;offset&quot;: offset,<br>                &quot;sort&quot;: sort,<br>                &quot;radius&quot;: radius,<br>                &quot;order_by&quot;: order_by,<br>                &quot;dumpRaw&quot;: dumpRaw,<br>            }<br>            if country_id is not None:<br>                params[&quot;country_id&quot;] = country_id<br>            with self._resource as s:<br>                response = s.get(&quot;https://api.openaq.org/v2/locations&quot;, params=params)<br>            return response.json()<br><br>        return _get_locations_measurements(<br>            country_id, limit, page, offset, sort, radius, order_by, dumpRaw<br>        )</pre><p>Of course, inside this connection, I use <em>@st.cache_data(ttl=ttl) </em>in order to cache the outputs. In order to better understand the args being used for the calling of the different endpoints, please check the corresponding <a href="https://api.openaq.org/docs">API docs.</a></p><h3>Create the visualization function</h3><p>For the visualization, the <a href="https://plotly.com/python/">plotly library</a> is being used and specifically the <a href="https://plotly.com/python/scattermapbox/">Scattermapbox</a> from the go class. (the below function is very big for layout reasons and could be split into more parts, but please forgive me):</p><pre>import plotly.graph_objects as go<br><br>def visualize_variable_on_map(data_dict, variable):<br>    is_day = is_daytime()<br>    mapbox_style = &quot;carto-darkmatter&quot; if not is_day else &quot;open-street-map&quot;<br><br>    # Initialize lists to store data for multiple locations<br>    latitudes = []<br>    longitudes = []<br>    values = []<br>    display_names = []<br>    last_updated = []<br><br>    # Loop through the results and extract relevant data for each location<br>    for result in data_dict.get(&quot;results&quot;, []):<br>        measurements = result.get(&quot;parameters&quot;, [])<br>        for measurement in measurements:<br>            if measurement[&quot;parameter&quot;] == variable:<br>                value = measurement[&quot;lastValue&quot;]<br>                display_name = measurement[&quot;displayName&quot;]<br>                latitude = result[&quot;coordinates&quot;][&quot;latitude&quot;]<br>                longitude = result[&quot;coordinates&quot;][&quot;longitude&quot;]<br>                last_updated_value = result[&quot;lastUpdated&quot;]<br><br>                latitudes.append(latitude)<br>                longitudes.append(longitude)<br>                values.append(value)<br>                display_names.append(display_name)<br>                last_updated.append(last_updated_value)<br><br>    if not latitudes or not longitudes or not values:<br>        print(f&quot;{variable} data not found.&quot;)<br>        return create_custom_markdown_card(<br>            f&quot;{variable} data not found for the selected country.&quot;<br>        )<br><br>    # Create the visualization<br>    fig = go.Figure()<br><br>    marker = [<br>        custom_markers[&quot;humidity&quot;]<br>        if variable == &quot;humidity&quot;<br>        else custom_markers[&quot;others&quot;]<br>    ]<br><br>    # Add a single scatter mapbox trace with all locations<br>    fig.add_trace(<br>        go.Scattermapbox(<br>            lat=latitudes,<br>            lon=longitudes,<br>            mode=&quot;markers+text&quot;,<br>            marker=dict(<br>                size=20,<br>                color=values,<br>                colorscale=&quot;Viridis&quot;,  # You can choose other color scales as well<br>                colorbar=dict(title=f&quot;{variable.capitalize()}&quot;),<br>            ),<br>            text=[<br>                f&quot;{marker[0]} {display_name}: {values[i]}&lt;br&gt;Last Updated: {last_updated[i]}&quot;<br>                for i, display_name in enumerate(display_names)<br>            ],<br>            hoverinfo=&quot;text&quot;,<br>        )<br>    )<br><br>    # Update map layout<br>    fig.update_layout(<br>        mapbox=dict(<br>            style=mapbox_style,  # Choose the desired map style<br>            zoom=5,  # Adjust the initial zoom level as needed<br>            center=dict(<br>                lat=sum(latitudes) / len(latitudes),<br>                lon=sum(longitudes) / len(longitudes),<br>            ),<br>        ),<br>        margin=dict(l=0, r=0, t=0, b=0),<br>    )<br>    create_custom_markdown_card(information)<br>    st.plotly_chart(fig, use_container_width=True)</pre><h3>Create the app</h3><p>The below code is included inside our <em>“app.py”</em> file:</p><pre>import streamlit as st<br>from connection import OpenAQConnection<br>from utils import * # a customade utils part with support functions<br><br>st.set_page_config(page_title=&quot;OpenAQ Connection&quot;, layout=&quot;wide&quot;)<br>conn = st.experimental_connection(&quot;openaq&quot;, type=OpenAQConnection)<br><br># in case you have a readme toml file<br>readme = load_config(&quot;config_readme.toml&quot;)<br><br><br># Info<br>st.title(&quot;Air quality data&quot;)<br>with st.expander(&quot;What is this app?&quot;, expanded=False):<br>    st.write(readme[&quot;app&quot;][&quot;app_intro&quot;])<br>    st.write(&quot;&quot;)<br>st.write(&quot;&quot;)<br>st.sidebar.image(load_image(&quot;logo.png&quot;), use_column_width=True)<br>display_links(readme[&quot;links&quot;][&quot;repo&quot;], readme[&quot;links&quot;][&quot;other_link&quot;])<br><br>with st.spinner(&quot;Loading the available countries...&quot;):<br>    # Countries exist in first 2 pages<br>    countries = []<br>    for page in [1, 2]:<br>        try:<br>            countries_request = conn.query_countries(page=page)[&quot;results&quot;]<br>            countries = countries + countries_request<br>        except Exception:<br>            countries_error = True<br><br>    transformed_countries = {<br>        country[&quot;name&quot;]: {<br>            &quot;code&quot;: country[&quot;code&quot;],<br>            &quot;parameters&quot;: country[&quot;parameters&quot;],<br>            &quot;locations&quot;: country[&quot;locations&quot;],<br>            &quot;lastUpdated&quot;: country[&quot;lastUpdated&quot;],<br>        }<br>        for country in countries<br>    }<br><br>    # Add a global for default when the app is initialised<br>    transformed_countries[&quot;Global&quot;] = {<br>        &quot;code&quot;: None,<br>        &quot;parameters&quot;: general_parameters,<br>        &quot;locations&quot;: None,<br>        &quot;lastUpdated&quot;: None,<br>    }<br><br># Parameters<br>st.sidebar.title(&quot;Selections&quot;)<br>selected_country = st.sidebar.selectbox(<br>    &quot;Select the desired country&quot;,<br>    transformed_countries,<br>    placeholder=&quot;Country&quot;,<br>    index=len(transformed_countries) - 1,  # Gets the last one &quot;Global&quot;<br>    help=readme[&quot;tooltips&quot;][&quot;country&quot;],<br>)<br><br>selected_viariable = st.sidebar.selectbox(<br>    &quot;Select the desired variable&quot;,<br>    transformed_countries[selected_country][&quot;parameters&quot;],<br>    placeholder=&quot;Variable&quot;,<br>    index=1,<br>    help=readme[&quot;tooltips&quot;][&quot;variable&quot;],<br>)<br><br>radius = st.sidebar.slider(<br>    &quot;Select a radius&quot;,<br>    min_value=100,<br>    max_value=25000,<br>    step=100,<br>    value=1000,<br>    help=readme[&quot;tooltips&quot;][&quot;radius&quot;],<br>)<br><br>total_locations = transformed_countries[selected_country][&quot;locations&quot;]<br>last_time = transformed_countries[selected_country][&quot;lastUpdated&quot;]<br>information = f&quot;The selected country is {selected_country}. The total found locations are {total_locations} with last updates at {last_time}.&quot;<br><br>code = transformed_countries[selected_country][&quot;code&quot;]<br>locations_response = conn.query(code, radius)<br>st.title(&quot;Map&quot;)<br>visualize_variable_on_map(locations_response, selected_viariable)</pre><p>So after running our app<em> “streamlit run app.py” </em>we have our app running.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/730/1*27fRTDhlAlj6DCaClFxAgQ.gif" /></figure><p>I called the app “AEROA,” and you can find it deployed in the streamlit community cloud <a href="https://airqualityapp-aeroa.streamlit.app/">here</a>. You can also find the <a href="https://github.com/stavrostheocharis/air_quality_app">source code on Github</a> and play with it according to your own preferences.</p><h3>Conclusion</h3><p>In this quick tutorial, we showcased the new <em>st.experimental_connection </em>feature from streamlit and used it to establish a connection with an open API that provides data for air quality data. In addition to this, we also developed a nice new app that displays the results in a plotly map.</p><p>🌟 If you enjoyed this article, <a href="https://medium.com/@stavrostheocharis">follow me on Medium to read more</a>!</p><p>🌟 you can also <a href="http://www.linkedin.com/in/stavros-theocharis-ai">follow me on Linkedin!</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=8029cf0787e8" width="1" height="1" alt=""><hr><p><a href="https://pub.towardsai.net/empowering-your-app-with-streamlits-new-connections-feature-and-interactive-plotly-maps-8029cf0787e8">Empowering Your App with Streamlit’s New Connections Feature and Interactive Plotly Maps</a> was originally published in <a href="https://pub.towardsai.net/">Towards AI</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Dynamic AI Project Estimation]]></title>
            <link>https://pub.towardsai.net/dynamic-ai-project-estimation-cb7f99cc0a1b?source=rss-216e390c9a41------2</link>
            <guid isPermaLink="false">https://medium.com/p/cb7f99cc0a1b</guid>
            <category><![CDATA[projects]]></category>
            <category><![CDATA[ai]]></category>
            <category><![CDATA[project-estimation]]></category>
            <category><![CDATA[project-management]]></category>
            <category><![CDATA[estimations]]></category>
            <dc:creator><![CDATA[Stavros Theocharis]]></dc:creator>
            <pubDate>Sat, 05 Aug 2023 14:01:46 GMT</pubDate>
            <atom:updated>2024-02-05T16:05:38.177Z</atom:updated>
            <content:encoded><![CDATA[<h4>Mastering the Basics for Agile Success</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*YbbzeMPxnvutnIiMcC7ynA.jpeg" /><figcaption>Photo by <a href="https://unsplash.com/@tomparkes">Tom Parkes</a> on <a href="https://unsplash.com/photos/Ns-BIiW_cNU">Unsplash</a></figcaption></figure><h3>Estimations</h3><p>Nowadays, estimations are used by almost everyone. The customers need them to both plan and control when they will start using the results of the project. Estimations also help the project manager figure out the scope, total amount of work, and rough cost of each task or the whole project.</p><p>Estimation is helpful in a number of situations, such as:</p><ul><li>Knowing how work is set up: Split a task into several smaller tasks to see the main steps you need to take.</li><li>Understanding complexity: It’s hard to give an estimation for a complex task by itself, but it’s easier to give an estimate for each part of the work structure. It helps to figure out how hard the job is and how long it will take to finish.</li><li>Figuring out costs: In most businesses, you won’t be able to start working on a project until you’ve explained and defended how much it will cost and what resources it will need.</li></ul><h4>What is the reality?</h4><p>Let’s face a specific truth…. Estimations, in general, <strong>don’t work, </strong>and this is their biggest issue. Our plans are wrong, not complete, and often have nothing to do with how the work will actually be done. Even if the team has faced a similar task many times, it’s hard for even the most experienced software developers to guess how many hours it will take to finish it. You need <strong>relevant samples</strong> and a good <strong>estimation process</strong> to use relative estimates in AI projects. Relevant estimates can, for example, be some simple statistical estimations that take the average length of all relevant tasks done in the past. To make this kind of estimator, we must first gather a set of data.</p><p>The trick, as mentioned above, is to break down each task into its own level. Because of this, Scrum says you should use relative story points instead of exact hours. First, your estimations become more accurate at the level of the task, then at the level of the sprint, and finally at the level of the project. If you don’t have any past experience that can help you make relative estimations, you should only make an absolute estimation for the first sprint of the project. From here on, you should use the tasks you’ve already done to make new estimations.</p><h3>Business and implementation estimations</h3><p>Estimations can be identified from two different points of view. The first point of view is the implementation part, which is mostly understandable to both project managers and team leaders who are willing to get the project done. At this point, the main goal of the estimations is to better understand the time and money needed to build the final solution.</p><p>The second point of view has a lot to do with the business goals of the project. This point of view is usually not visible to the implementation team. Most of the projects usually have a business model to set goals for increased revenue, making customers happy, lowering costs, and so on. When someone is proceeding with the implementation estimations, this business model should be taken into account because it somehow sets the possible restrictions. In AI projects, business estimations can be made by first taking into consideration the business model’s <strong>budget constraints</strong> and then making a set of <strong>business metrics</strong> that can be used to calculate how well the project is performing.</p><p>You should start by laying out the general steps, and then go into more detail. If you’ve done projects like this before, you can look at their plans to figure out where to start. Collecting and using data from other projects can be a great way to get estimates, so don’t discount your past work.</p><p>When your outline has enough information, it’s time to make a proposal for the software architecture. This is a very important step because it’s not always possible or even cost-effective to match up outlines with customer or end-user needs. You should have at least a general idea of what technologies you will use, how they will work with the rest of the customer’s system, and how your solution should be deployed. If there are important non-functional requirements, like being available 24 hours a day, 7 days a week, the software architect should also think about how to make them happen in terms of technology and system design. Putting together a high-level architectural vision will help this outline make sense. If you think the outline needs to be changed, don’t be afraid to do so. Software design is a difficult task that should be done by an experienced engineer. If you don’t have a lot of experience designing software solutions, ask someone on your team for help, or even better, make software design a <strong>group effort</strong>.</p><p>Once the outline is done and you have a plan for the software architecture, you can start estimating the project. Simple statistical methods like the Program Evaluation and Review technique to estimate numbers (PERT) can do the job.</p><h3>What is PERT?</h3><p>PERT, known as the Program Evaluation and Review Technique, serves the purpose of estimating the anticipated duration required for task completion. This method proves exceptionally valuable when dealing with scenarios featuring an abundance of unfamiliar variables. Initially crafted within the United States Navy, PERT has since gained substantial traction among numerous project overseers.</p><p>Within the framework of PERT, there exists the capability to assign a rating to each task, utilizing a range from 1 to 3. Specifically, this involves contemplating the time investment a task would demand under optimal conditions. Furthermore, the potential for minor technical glitches or complications arising from prerequisites that hinder the progress must also be factored into the developmental trajectory.</p><p>Therefore, the primary factors that necessitate computation encompass the following:</p><ol><li><strong>Most likely estimation</strong>: This entails providing the most precise assessment feasible for the given task.</li><li><strong>A pessimistic estimation</strong>: This represents the duration required for task completion in the event of adverse circumstances. This category encompasses higher risks, such as unsuccessful experiments and intricate debugging sessions.</li><li><strong>An optimistic estimation</strong>: This refers to the anticipated time span to accomplish the task should conditions proceed optimally.</li></ol><p>PERT estimation = (<strong>optimistic estimation + 4 x most likely estimation + pessimistic estimation) / 6</strong></p><p>PERT standard deviation = (<strong>pessimistic estimation — optimistic estimation)/6</strong></p><p>In order to have a confidence interval of about 99.7% (be sure of the extent of probability) you can calculate: <strong>Pert estimation ± 3 x PERT standard deviation </strong>(3 can be set to 2 for restricting the range).</p><p>Do not forget to use data from projects that are already done as a starting point for relative estimation. When estimating, the more outside sources you use, the more accurate and risk-averse your estimates will be.</p><h3>Goals of estimations</h3><p>While formulating projections, maintaining a steadfast focus on the ultimate objective holds the utmost significance. Crafting and sustaining accurate estimations demands a substantial investment of effort and time. Particularly within the realm of AI ventures, prognosticating outcomes proves intricate due to their intricate nature, thereby amplifying the significance of garnering trust from both your team and clients in these forecasts. This trust is pivotal as it correlates positively with the likelihood of successful execution.</p><p>It’s worth noting that the level of certainty tied to estimations diminishes when confronted with uncharted territories, such as crafting solutions for novel business domains or the integration of pioneering algorithms and technologies. In these instances, possessing a coherent roadmap toward the culmination becomes a guiding beacon.</p><p>However, it’s judicious to avoid excessive reliance on exact calculations pinpointing the temporal aspect or meticulously detailed blueprints. Instead, a discerning application of estimates is advisable. They serve as tools not only for ensuring congruence between implementation strategies and customer expectations but also for steering projects in alignment with these desires.</p><h3>Risks</h3><p>In the realm of AI projects, the initial and pivotal point of vulnerability lies in delineating the project’s objectives. The main point of success in a good understanding of the desired outcomes. It is very interesting when the project implementation begins in a quick way, but if there is a lack of precision, this can diverge significantly from the actual business requisites. Hence, it is very important to have well-established and well-defined objectives. These objectives can operate like a compass for the team, enabling them to discern between accurate and erroneous resolutions.</p><h3>How to approach research projects?</h3><p>A research endeavor encompasses any project geared towards unraveling solutions to previously unencountered predicaments. Notably, the motivation behind research projects extends beyond the enhancement of scientific knowledge. They encompass scenarios where teams delve into unexplored realms, such as novel business domains or emerging AI libraries, and strive to uncover innovative applications of AI within business contexts. This holds true for almost every AI initiative, wherein a subsidiary research project takes charge of the modeling process.</p><p>Nevertheless, a fundamental issue with research projects is their tendency to lack comprehensive breadth. Each research undertaking mandates a <strong>well-defined objective</strong>; without such clarity, successful culmination remains elusive. Moreover, addressing external challenges holds equal importance in the realm of research endeavors. The financial allocations for research naturally escalate in proportion to the expansiveness of the project scope. <strong>Budget constraints</strong>, if present, can also impose <strong>limitations</strong> on the <strong>depth</strong> and <strong>duration</strong> of the research.</p><p>Once the quantum of research feasible is determined, collaborative efforts can be directed towards tackling the pending experiments. Each entry on the backlog should embody an idea capable of enriching model quality or facilitating the realization of desired functionalities. The <strong>SMART</strong> criteria — specific, measurable, achievable, relevant, and time-bound — serve as a pertinent framework for articulating the specifics of each experiment.</p><p>Conduct swift yet comprehensive quality assessments on all ongoing experiments within your current research cycle. This practice aids in gauging the anticipated time investments for each experiment. To safeguard the trajectory of your research projects and prevent potential missteps, it’s imperative to adhere to the following guidelines:</p><ul><li>Set an exact goal</li><li>Set the criteria for success</li><li>Define the limits, such as the time and money limits</li><li>Fill up the queue of experiments</li><li>Prioritise based on what you want</li><li>Keep track of all the tests and their results</li><li>Make the code easy to copy</li><li>Write down what you find</li></ul><p>Some additional parts that need to be considered are:</p><ul><li>Identify what the nice-to-have is and what is the main part</li><li>Reduce effort for not important parts in the beginning</li><li>Try to be as lean as possible (based on the budget you have)</li></ul><p>A considerable portion of projects relies on a <strong>top-down estimation</strong> approach, wherein the process originates with the overarching budget allocation for the project and subsequently deconstructs it into smaller components. This method is particularly employed when the project’s <strong>financial framework</strong> and <strong>pricing</strong> are already <strong>established</strong>. However, this approach encounters a notable predicament: initial estimates tend to be less reliable at the project’s outset. The challenge arises from the fact that determining the required budget is intricate before a comprehensive understanding of the project’s requirements and a detailed plan are in place.</p><p>This challenge can be further exacerbated, particularly when gauging the initial quote’s accuracy against the eventual project outcome is unfeasible. The efficacy of top-down estimation is optimized when there exists a profound comprehension of how each task within the project’s scope contributes to the initial fixed price. Nonetheless, this level of understanding demands substantial time and effort, which is often not feasible to ascertain manually.</p><h3>Some additional helpful parts</h3><ul><li>No one can work on projects all the time because everyone needs breaks, goes to meetings, gets stuck in traffic, and so on. So, you should assume that a resource isn’t available 20% of the time but is available 80% of the time. If a project resource is only available half the time, set the maximum availability units to 40%. When setting up the schedule for your project, don’t forget to account for each resource’s holidays, plant shutdowns, training, and vacations. No plan ever goes exactly as planned. You need some wiggle room because some tasks will be late.</li><li>Include a buffer: No plan ever goes exactly as planned. You need to have some margin for error because some tasks will be late. A good idea is to add a buffer task at the end of certain phases (like those that use new technology that your team has little or no experience with) or to extend the project’s overview deadline for that phase by 20% from its original length. For instance, if the original length of a phase is 100 days, you could make it 120 days.</li><li>Try to identify some of the possible risks at the beginning of the project and make this a continuous procedure.</li></ul><h3>Conclusions</h3><ul><li>Estimations are used to plan and control projects, understand complexity, and figure out costs.</li><li>Estimation is difficult and inaccurate, so a relevant sample and a good estimation process are needed.</li><li>Use relative story points instead of exact hours to improve accuracy.</li><li>Differentiate between business and implementation estimates, and consider the business model’s budget constraints.</li><li>Outline steps, make a proposal for software architecture, and use statistical methods like PERT to estimate projects.</li><li>PERT involves rating for each task on a scale of 1–3 (best case, most likely, and pessimistic estimates).</li></ul><p>🌟 If you enjoyed this article, <a href="https://medium.com/@stavrostheocharis">follow me on Medium to read more</a>!</p><p>🌟 you can also <a href="http://www.linkedin.com/in/stavros-theocharis-ai">follow me on Linkedin!</a></p><h3>References</h3><p>Dubovikov K. (2019). Managing Data Science. Packt Publishing</p><p><a href="https://www.forecast.app/blog/how-to-create-a-project-budget">Creating a Project Budget - A Complete Guide</a></p><p><a href="https://projectmanagementacademy.net/resources/blog/a-three-point-estimating-technique-pert/">https://projectmanagementacademy.net/resources/blog/a-three-point-estimating-technique-pert</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=cb7f99cc0a1b" width="1" height="1" alt=""><hr><p><a href="https://pub.towardsai.net/dynamic-ai-project-estimation-cb7f99cc0a1b">Dynamic AI Project Estimation</a> was originally published in <a href="https://pub.towardsai.net/">Towards AI</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[easy-explain: Explainable AI for images]]></title>
            <link>https://pub.towardsai.net/easy-explain-explainable-ai-for-images-285777a004e3?source=rss-216e390c9a41------2</link>
            <guid isPermaLink="false">https://medium.com/p/285777a004e3</guid>
            <category><![CDATA[explainable-ai]]></category>
            <category><![CDATA[ai]]></category>
            <category><![CDATA[computer-vision]]></category>
            <category><![CDATA[image]]></category>
            <category><![CDATA[xai]]></category>
            <dc:creator><![CDATA[Stavros Theocharis]]></dc:creator>
            <pubDate>Sat, 18 Feb 2023 12:02:39 GMT</pubDate>
            <atom:updated>2024-02-05T16:05:56.684Z</atom:updated>
            <content:encoded><![CDATA[<h4>A quick and easy-to-use package for fast explainability results on images</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*TPxLbOeUozOo7svITRmQtQ.png" /><figcaption>(<strong>Right</strong>) Photo by <a href="https://unsplash.com/@pollsa">Tomas Allsop</a> on <a href="https://unsplash.com/?utm_source=medium&amp;utm_medium=referral">Unsplash</a> | (<strong>Left</strong>) <a href="https://unsplash.com/?utm_source=medium&amp;utm_medium=referral">Unsplash</a> Image adjusted by the showcased algorithm</figcaption></figure><h3>Introduction</h3><p>Understanding how artificial intelligence (AI) decides what to do is becoming increasingly important as AI finds more and more uses in everyday life. Particularly relevant here are image classification models, which employ AI to detect and label specific features in pictures, such as faces and objects. We need to be able to explain how these models come up with their predictions to make sure we can trust and account for them.</p><p>Explainable AI (XAI) is a collection of methods and techniques for making AI easier to understand and explain. Image classification techniques typically employ convoluted neural networks, making XAI all the more crucial. We may learn about the decision-making processes of these models, the attributes they use to recognize things, and any inherent biases they may have by employing XAI methods.</p><p>GitHub is teeming with new packages and repositories containing XAI methods derived from the literature or developed under custom cases.</p><p>In this article, I will present the <a href="https://github.com/stavrostheocharis/easy_explain">“<strong>easy-explain</strong>” library</a>, which comes from the new <a href="https://github.com/stavrostheocharis/easy_explain">repository</a> I created for explaining AI <strong>PyTorch</strong> models trained for images. I split this article into two sections. If you want to know how the easy-explain package works in detail, please read the first section, “<strong>easy-explain package in detail</strong>”. Otherwise, if you just want to know how to use the easy-explain package, please read directly “<strong>Simple use of the “easy-explain package”. </strong>For more information and guides, please have a look in the <a href="https://github.com/stavrostheocharis/easy_explain/tree/main/examples">examples folder</a> with the corresponding Jupyter notebooks.</p><p>For all the parts that will be shown below, we can consider as an example, the pre-trained Resnet50 model. We will load it from Torchvision:</p><pre>import torchvision<br>model = torchvision.models.resnet50(pretrained=True).eval()</pre><p>The images that are being used in the whole article are coming from <a href="https://unsplash.com/">Unsplash</a>.</p><h3>easy-explain package in detail</h3><p>easy-explain uses under the hood <a href="https://captum.ai/">Captum</a>. Captum aids in comprehending how the data properties impact the model predictions or neuron activations, offering insights into how the model performs. Captum comes together with the <a href="https://pytorch.org/">Pytorch library</a>. Currently, easy-explain is working only for images and only for Pytorch.</p><p>Captum allows for the unified application of several different cutting-edge feature attribution techniques, such as Guided GradCam and Integrated Gradients. In addition, the Occlusion methodology is being used.</p><h4>Loading &amp; Pre-processing of an image</h4><p>Let’s get an image from Unsplash right away…</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*VNa7ae6hYJxcZUpQ-D-DFw.png" /><figcaption>Photo by <a href="https://unsplash.com/@detpho">Francesco</a> on <a href="https://unsplash.com/?utm_source=medium&amp;utm_medium=referral">Unsplash</a></figcaption></figure><p>… and convert it into the desired format for our model with the needed transformations:</p><pre>import requests<br>from PIL import Image<br>from io import BytesIO<br><br>response = requests.get(&quot;https://unsplash.com/photos/ZxNKxnR32Ng/download?ixid=MnwxMjA3fDB8MXxzZWFyY2h8NHx8bGlvbnxlbnwwfHx8fDE2NzU3OTY5NjE&amp;force=true&quot;)<br>image = Image.open(BytesIO(response.content))</pre><pre>from torchvision import transforms<br><br>def process_image(image):<br>    center_crop = transforms.Compose([<br>        transforms.Resize(256),<br>        transforms.CenterCrop(224),<br>        ])<br>    normalize = transforms.Compose([<br>        # convert the image to a tensor with values between 0 and 1<br>        transforms.ToTensor(), <br>        # normalize to follow 0-centered imagenet pixel rgb distribution              <br>        transforms.Normalize(                <br>        mean=[0.485, 0.456, 0.406],<br>        std=[0.229, 0.224, 0.225]<br>        )<br>        ])<br>    return normalize(center_crop(image)).unsqueeze(0)<br>input_img = process_image(image)</pre><h4>Get predictions</h4><p>We can also get the pre-trained classes’ labels from the above Resnet50 model by <a href="https://github.com/stavrostheocharis/easy_explain/blob/main/examples/imagenet_class_index.json">clicking here</a>. This is a JSON file, and we can load it directly from our save path:</p><pre>import json<br><br>def load_data_labels(path: str =  &#39;imagenet_class_index.json&#39;):<br>    # Opening JSON file<br>    f = open(path)<br>    # returns JSON object as <br>    # a dictionary<br>    data = json.load(f)<br>return data<br><br>labels = load_data_labels()</pre><p>In order to provide an <strong>explanation</strong> for our findings, we must first determine the classes that require an explanation. This occurs as a result of the need to have one explanation at a time for each individual class.</p><p>So we need first to predict the needed classes.</p><p>In this walkthrough, we will focus on explaining the first option. In principle, a person is free to define and describe her own class on her own terms. But keep in mind that the first classes have meaning that needs to be explained. For example, if we have an image of a dog, we do not want to know why the model predicted that maybe our image represents a shark for a percentage of 0.005%.</p><p>So, as you probably guessed, we also get the needed percentages with the function below…</p><pre>import torch<br><br>def predict_classes(input_img, labels, model, total_preds:int=5):<br>    # Find the score in terms of percentage by using torch.nn.functional.softmax function<br>    # which normalizes the output to range [0,1] and multiplying by 100<br>    out = model(input_img)<br>    percentage = torch.nn.functional.softmax(out, dim=1)[0] * 100<br>    # Find the index (tensor) corresponding to the maximum score in the out tensor.<br>    # Torch.max function can be used to find the information<br>    _, indices = torch.sort(out, descending=True)<br>    prediction = [(idx.item(), labels[str(idx.item())][1], percentage[idx].item()) for idx in indices[0][:total_preds]]<br>    <br>    return prediction<br>prediction = predict_classes(input_img, labels, model, 5)</pre><p>Let’s see more of the XAI part, so…</p><h4>How does Occlusion work?</h4><p>Attribution can be calculated using a perturbation-based method by first replacing all adjacent rectangular regions with a particular baseline or reference and then calculating the change in output. Features spread over many hyperrectangles have their attributions calculated by averaging the differences in output from each hyperrectangle.</p><p>The initial patch is applied such that its corner is aligned with all zeros in the index range, and subsequent patches are applied in steps until the full dimension range has been patched. Keep in mind that this might lead to the final patch applied in a direction being smaller than the intended occlusion form due to being cut off.</p><p>Let’s dive into the code…</p><p>We need to import the needed functions:</p><pre>import numpy as np<br>from captum.attr import visualization as viz<br>from captum.attr import Occlusion</pre><p>Now we need the main functionality of Occlusion. As a target, we use the class we want to have the explanation for (as stated above).</p><p>Maybe we want to check the second or third in-the-row prediction. Keep in mind again that each time we can explain only one of the categories.</p><p>The important parts here are the following:</p><p>- strides: For each iteration, this specifies how far the occlusion hyperrectangle should be adjusted in each direction. This may be a single integer that is used as the step size in each direction for a single tensor input, or it can be a tuple of numbers that corresponds to the number of dimensions in the occlusion form.</p><p>- baselines: They define reference value which replaces each feature when occluded</p><p>- sliding_window_shapes: Shape of the patch (hyperrectangle) to occlude each input.</p><p>For more information, please read <a href="https://captum.ai/api/occlusion.html">Captum’s Occlusion Docs</a>.</p><pre>def create_attribution(target, model, input_img):<br>    occlusion = Occlusion(model)<br>    strides = (3, 9, 9)               # smaller = more fine-grained attribution but slower<br>    sliding_window_shapes=(3,45, 45)  # choose size enough to change object appearance<br>    baselines = 0                     # values to occlude the image with. 0 corresponds to gray<br>    attribution = occlusion.attribute(input_img,<br>                                       strides = strides,<br>                                       target=target,<br>                                       sliding_window_shapes=sliding_window_shapes,<br>                                       baselines=baselines)<br>    <br>    trans_attribution = np.transpose(attribution.squeeze().cpu().detach().numpy(), (1,2,0))<br><br>    return trans_attribution</pre><p>And also some helpful functions:</p><pre>def get_prediction_name_from_predictions(predictions):<br>&#39;&#39;&#39; A simple function to get the prediction name (we need it only for the title of the plots)&#39;&#39;&#39;<br>    name_of_prediction = predictions[0][1]<br>    name_of_prediction = name_of_prediction.capitalize().replace(&#39;_&#39;, &#39; &#39;)<br>    return name_of_prediction<br><br>def get_image_titles(vis_types, vis_signs, name_of_prediction):<br>&#39;&#39;&#39;A helpful function to construct the titles of our images&#39;&#39;&#39;<br>    image_titles_list = []<br>    for i in range(len(vis_types)):<br><br>        if vis_signs[i]!=&quot;all&quot;:<br>            title = vis_types[i].capitalize().replace(&#39;_&#39;, &#39; &#39;) + &quot; for &quot; + name_of_prediction<br>        else:<br>            title = vis_signs[i].capitalize().replace(&#39;_&#39;, &#39; &#39;) + &quot; &quot; + vis_types[i].capitalize().replace(&#39;_&#39;, &#39; &#39;) + &quot; for &quot; + name_of_prediction<br>        image_titles_list.append(title)<br>    return image_titles_list</pre><p>Our below function will visualize the results. There are several combinations for vis_types and vis_signs. You can play a bit with them.</p><pre>def create_explanation(attribution, image, name_of_prediction, vis_types=[[&quot;blended_heat_map&quot;, &quot;original_image&quot;]], vis_signs = [[&quot;all&quot;, &quot;all&quot;]]):<br>    center_crop = transforms.Compose([<br>        transforms.Resize(256),<br>        transforms.CenterCrop(224),<br>        ])<br>    image_titles_list = get_image_titles(vis_types, vis_signs, name_of_prediction)<br>    _ = viz.visualize_image_attr_multiple(attribution,<br>                                      np.array(center_crop(image)),<br>                                      vis_types,<br>                                      vis_signs,<br>                                      image_titles_list,<br>                                      show_colorbar = True<br>                                     )</pre><p>Run the above functions:</p><pre>prediction_name = get_prediction_name_from_predictions(prediction)<br>trans_attribution = create_attribution(prediction[0][0], model, input_img)</pre><p>The main 5 predictions are:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/848/1*S9G8g7Vcrp2KrmDJlM25ag.png" /></figure><p>The model is pretty sure about the lion class. Let’s see the explanations…</p><p>(We will use separate parts for each explanation, each time only one set, e.g., “blended_heat_map”, “original_image”).</p><pre>vis_types=[[&quot;blended_heat_map&quot;, &quot;original_image&quot;]]<br>vis_signs = [[&quot;positive&quot;,&quot;all&quot;]]<br>number_of_sets = len(vis_types)<br><br>for i in range(number_of_sets):<br>    create_explanation(trans_attribution, image, prediction_name, vis_types = vis_types[i], vis_signs=vis_signs[i])</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*rWy-vjyg5V1YrfMKFWAjRw.png" /><figcaption>(<strong>Right</strong>) Photo by <a href="https://unsplash.com/@detpho">Francesco</a> on <a href="https://unsplash.com/?utm_source=medium&amp;utm_medium=referral">Unsplash</a> | (<strong>Left</strong>) <a href="https://unsplash.com/?utm_source=medium&amp;utm_medium=referral">Unsplash</a> Image adjusted by the showcased algorithm</figcaption></figure><pre>vis_types=[[&quot;blended_heat_map&quot;, &quot;original_image&quot;]]<br>vis_signs = [[&quot;negative&quot;,&quot;all&quot;]]<br>number_of_sets = len(vis_types)<br><br>for i in range(number_of_sets):<br>    create_explanation(trans_attribution, image, prediction_name, vis_types = vis_types[i], vis_signs=vis_signs[i])</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*9TqaUl62KRYDQNdHYMpG-Q.png" /><figcaption>(<strong>Right</strong>) Photo by <a href="https://unsplash.com/@detpho">Francesco</a> on <a href="https://unsplash.com/?utm_source=medium&amp;utm_medium=referral">Unsplash</a> | (<strong>Left</strong>) <a href="https://unsplash.com/?utm_source=medium&amp;utm_medium=referral">Unsplash</a> Image adjusted by the showcased algorithm</figcaption></figure><pre>vis_types=[[&quot;masked_image&quot;, &quot;original_image&quot;]]<br>vis_signs = [[&quot;positive&quot;,&quot;all&quot;]]<br>number_of_sets = len(vis_types)<br><br>for i in range(number_of_sets):<br>    create_explanation(trans_attribution, image, prediction_name, vis_types = vis_types[i], vis_signs=vis_signs[i])</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*zmWZrsVIReQHq2ijP8RiQg.png" /><figcaption>(<strong>Right</strong>) Photo by <a href="https://unsplash.com/@detpho">Francesco</a> on <a href="https://unsplash.com/?utm_source=medium&amp;utm_medium=referral">Unsplash</a> | (<strong>Left</strong>) <a href="https://unsplash.com/?utm_source=medium&amp;utm_medium=referral">Unsplash</a> Image adjusted by the showcased algorithm</figcaption></figure><pre>vis_types=[[&quot;alpha_scaling&quot;, &quot;original_image&quot;]]<br>vis_signs = [[&quot;positive&quot;,&quot;all&quot;]]<br>number_of_sets = len(vis_types)<br><br>for i in range(number_of_sets):<br>    create_explanation(trans_attribution, image, prediction_name, vis_types = vis_types[i], vis_signs=vis_signs[i])</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*HW38Xbi76WgOH4xLqB_d2g.png" /><figcaption>(<strong>Right</strong>) Photo by <a href="https://unsplash.com/@detpho">Francesco</a> on <a href="https://unsplash.com/?utm_source=medium&amp;utm_medium=referral">Unsplash</a> | (<strong>Left</strong>) <a href="https://unsplash.com/?utm_source=medium&amp;utm_medium=referral">Unsplash</a> Image adjusted by the showcased algorithm</figcaption></figure><p>By looking at the visualizations that are located above, we are able to comprehend some of the primary components that our model “saw” before concluding that the picture contains a lion. The legs, the mouth, and the belly are some of these parts.</p><p>The upper part of the lion’s head and the ground were the parts of our model that were able to convince it otherwise.</p><p>The ground should not play a major role in the selection since it should not help with the classification of the image. This is based on the training set and inserts some <strong>bias</strong> into our model.</p><p>So, let’s have one more try. This time, we will use the next predicted class:</p><pre>input_img = process_image(image)<br>prediction = predict_classes(input_img, labels, model, 5)<br>prediction = prediction[1:]<br>prediction_name = get_prediction_name_from_predictions(prediction)<br>trans_attribution = create_attribution(prediction[0][0], model, input_img)</pre><p>The prediction now becomes:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/904/1*Dc5Fto-DeBoObPxoaZnDiQ.png" /></figure><pre>vis_types=[[&quot;blended_heat_map&quot;, &quot;original_image&quot;]]<br>vis_signs = [[&quot;positive&quot;,&quot;all&quot;]]<br><br>number_of_sets = len(vis_types)<br><br>for i in range(number_of_sets):<br>    create_explanation(trans_attribution, image, prediction_name, vis_types = vis_types[i], vis_signs=vis_signs[i])</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*3jRR5UfAy6oSEPvTcPgpug.png" /><figcaption>(<strong>Right</strong>) Photo by <a href="https://unsplash.com/@detpho">Francesco</a> on <a href="https://unsplash.com/?utm_source=medium&amp;utm_medium=referral">Unsplash</a> | (<strong>Left</strong>) <a href="https://unsplash.com/?utm_source=medium&amp;utm_medium=referral">Unsplash</a> Image adjusted by the showcased algorithm</figcaption></figure><pre>vis_types=[[&quot;blended_heat_map&quot;, &quot;original_image&quot;]]<br>vis_signs = [[&quot;negative&quot;,&quot;all&quot;]]<br>number_of_sets = len(vis_types)<br><br>for i in range(number_of_sets):<br>    create_explanation(trans_attribution, image, prediction_name, vis_types = vis_types[i], vis_signs=vis_signs[i])</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*XfcDtnNRfjLgx4BYks3PmQ.png" /><figcaption>(<strong>Right</strong>) Photo by <a href="https://unsplash.com/@detpho">Francesco</a> on <a href="https://unsplash.com/?utm_source=medium&amp;utm_medium=referral">Unsplash</a> | (<strong>Left</strong>) <a href="https://unsplash.com/?utm_source=medium&amp;utm_medium=referral">Unsplash</a> Image adjusted by the showcased algorithm</figcaption></figure><p>The animal’s legs primarily led the model to believe that the image represented chow with 0.40% of certainty.</p><h3>Simple use of the “easy-explain package”</h3><p>For the simple use of the package, just run the below lines of code:</p><p>(I have changed the link of the given image to show a variation in the results.)</p><pre>from easy_explain import OcclusionExplain<br><br>occlusion_explain = OcclusionExplain(model=model)<br>vis_types=[[&quot;blended_heat_map&quot;, &quot;original_image&quot;], [&quot;blended_heat_map&quot;, &quot;original_image&quot;], [&quot;masked_image&quot;, &quot;original_image&quot;], [&quot;alpha_scaling&quot;, &quot;original_image&quot;]]<br>vis_signs = [[&quot;positive&quot;,&quot;all&quot;], [&quot;negative&quot;,&quot;all&quot;], [&quot;positive&quot;,&quot;all&quot;], [&quot;positive&quot;,&quot;all&quot;]]<br><br>occlusion_explain.generate_explanation(image_url=&quot;https://unsplash.com/photos/aGQMKvPiBN4/download?ixid=MnwxMjA3fDB8MXxzZWFyY2h8M3x8c3F1aXJyZWwlMjBtb25rZXl8ZW58MHx8fHwxNjc1NzczNTIy&amp;force=true&quot;,total_preds=5,vis_types = vis_types, vis_signs = vis_signs, labels_path=&quot;imagenet_class_index.json&quot;)</pre><p>And the results:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*m5tXdFhOJLB_mqIA59OtQg.png" /><figcaption>(<strong>Right</strong>) Photo by <a href="https://unsplash.com/@pollsa">Tomas Allsop</a> on <a href="https://unsplash.com/?utm_source=medium&amp;utm_medium=referral">Unsplash</a> | (<strong>Left</strong>) <a href="https://unsplash.com/?utm_source=medium&amp;utm_medium=referral">Unsplash</a> Image adjusted by the showcased algorithm</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*NwXMpyR9Fu5uuWQ35UJfUg.png" /><figcaption>(<strong>Right</strong>) Photo by <a href="https://unsplash.com/@pollsa">Tomas Allsop</a> on <a href="https://unsplash.com/?utm_source=medium&amp;utm_medium=referral">Unsplash</a> | (<strong>Left</strong>) <a href="https://unsplash.com/?utm_source=medium&amp;utm_medium=referral">Unsplash</a> Image adjusted by the showcased algorithm</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*DhC3hnIUHgqc1fER4ESZ_A.png" /><figcaption>(<strong>Right</strong>) Photo by <a href="https://unsplash.com/@pollsa">Tomas Allsop</a> on <a href="https://unsplash.com/?utm_source=medium&amp;utm_medium=referral">Unsplash</a> | (<strong>Left</strong>) <a href="https://unsplash.com/?utm_source=medium&amp;utm_medium=referral">Unsplash</a> Image adjusted by the showcased algorithm</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*4eMh5XPArcjbW7xDnmJzkg.png" /><figcaption>(<strong>Right</strong>) Photo by <a href="https://unsplash.com/@pollsa">Tomas Allsop</a> on <a href="https://unsplash.com/?utm_source=medium&amp;utm_medium=referral">Unsplash</a> | (<strong>Left</strong>) <a href="https://unsplash.com/?utm_source=medium&amp;utm_medium=referral">Unsplash</a> Image adjusted by the showcased algorithm</figcaption></figure><p>The great aspect of this case is that we have nice results that are easy to explain with only a few lines of code. The rapid construction and testing of the outputs of our models may be accomplished using this extremely easy and quick procedure.</p><h3>Conclusion</h3><p>In general, exploratory artificial intelligence (XAI) is an essential field that is helping to guarantee that artificial intelligence is trustworthy, interpretable, and transparent. By applying XAI methods to the development of image classification models, we are able to gain a better understanding of their operation and make well-informed choices on how they should be utilized.</p><p>In this article, I showcased the easy-explain package. Through it, someone can easily and quickly explain and check the predictions of the trained models.</p><p>🌟 If you enjoyed this article, <a href="https://medium.com/@stavrostheocharis">follow me on Medium to read more</a>!</p><p>🌟 you can also <a href="http://www.linkedin.com/in/stavros-theocharis-ai">follow me on Linkedin!</a></p><p>If you liked this one and you also want to contribute, please check the <a href="https://github.com/stavrostheocharis/easy_explain/blob/main/CONTRIBUTING.md">contribution guide</a>.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=285777a004e3" width="1" height="1" alt=""><hr><p><a href="https://pub.towardsai.net/easy-explain-explainable-ai-for-images-285777a004e3">easy-explain: Explainable AI for images</a> was originally published in <a href="https://pub.towardsai.net/">Towards AI</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
    </channel>
</rss>