<?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 Cameron Jones on Medium]]></title>
        <description><![CDATA[Stories by Cameron Jones on Medium]]></description>
        <link>https://medium.com/@cameronjosephjones?source=rss-fcadb85a9bcd------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*nH63d3HiTnSVVgVcdoL8-g.jpeg</url>
            <title>Stories by Cameron Jones on Medium</title>
            <link>https://medium.com/@cameronjosephjones?source=rss-fcadb85a9bcd------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Tue, 01 Dec 2026 00:31:32 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@cameronjosephjones/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[AI Stock Analysis ChatBot Using Deepseek, Python, Streamlit, and APIs]]></title>
            <description><![CDATA[<div class="medium-feed-item"><p class="medium-feed-image"><a href="https://medium.com/@cameronjosephjones/ai-stock-analysis-chatbot-using-deepseek-python-streamlit-and-apis-56db01244212?source=rss-fcadb85a9bcd------2"><img src="https://cdn-images-1.medium.com/max/2600/1*UZ9M04PNjMgSfBgv00pG4A.jpeg" width="2934"></a></p><p class="medium-feed-snippet">How you can utilise Deepseek to make an AI chatbot with stock data. Step-by-step guide.</p><p class="medium-feed-link"><a href="https://medium.com/@cameronjosephjones/ai-stock-analysis-chatbot-using-deepseek-python-streamlit-and-apis-56db01244212?source=rss-fcadb85a9bcd------2">Continue reading on Medium »</a></p></div>]]></description>
            <link>https://medium.com/@cameronjosephjones/ai-stock-analysis-chatbot-using-deepseek-python-streamlit-and-apis-56db01244212?source=rss-fcadb85a9bcd------2</link>
            <guid isPermaLink="false">https://medium.com/p/56db01244212</guid>
            <category><![CDATA[streamlit]]></category>
            <category><![CDATA[chatbots]]></category>
            <category><![CDATA[investing]]></category>
            <category><![CDATA[data-analysis]]></category>
            <category><![CDATA[deepseek]]></category>
            <dc:creator><![CDATA[Cameron Jones]]></dc:creator>
            <pubDate>Wed, 29 Jan 2025 03:12:45 GMT</pubDate>
            <atom:updated>2025-01-29T03:14:29.695Z</atom:updated>
        </item>
        <item>
            <title><![CDATA[Building an AI Chatbot with DeepSeek and Streamlit]]></title>
            <description><![CDATA[<div class="medium-feed-item"><p class="medium-feed-image"><a href="https://medium.com/@cameronjosephjones/building-an-ai-chatbot-with-deepseek-and-streamlit-aec2bab82928?source=rss-fcadb85a9bcd------2"><img src="https://cdn-images-1.medium.com/max/2600/1*la63-3kKSlUphajmPrKVpQ.jpeg" width="2932"></a></p><p class="medium-feed-snippet">A step-by-step guide to creating a conversational AI interface</p><p class="medium-feed-link"><a href="https://medium.com/@cameronjosephjones/building-an-ai-chatbot-with-deepseek-and-streamlit-aec2bab82928?source=rss-fcadb85a9bcd------2">Continue reading on Medium »</a></p></div>]]></description>
            <link>https://medium.com/@cameronjosephjones/building-an-ai-chatbot-with-deepseek-and-streamlit-aec2bab82928?source=rss-fcadb85a9bcd------2</link>
            <guid isPermaLink="false">https://medium.com/p/aec2bab82928</guid>
            <category><![CDATA[streamlit]]></category>
            <category><![CDATA[ai]]></category>
            <category><![CDATA[data-analysis]]></category>
            <category><![CDATA[deepseek]]></category>
            <category><![CDATA[data-science]]></category>
            <dc:creator><![CDATA[Cameron Jones]]></dc:creator>
            <pubDate>Sat, 25 Jan 2025 01:03:56 GMT</pubDate>
            <atom:updated>2025-01-25T01:03:56.108Z</atom:updated>
        </item>
        <item>
            <title><![CDATA[Building an Image Metadata Remover Web App With Python and Streamlit]]></title>
            <link>https://medium.com/@cameronjosephjones/building-an-image-metadata-remover-web-app-with-python-and-streamlit-6e4e33772dd8?source=rss-fcadb85a9bcd------2</link>
            <guid isPermaLink="false">https://medium.com/p/6e4e33772dd8</guid>
            <category><![CDATA[image-processing]]></category>
            <category><![CDATA[metadata]]></category>
            <category><![CDATA[web-app-development]]></category>
            <category><![CDATA[streamlit]]></category>
            <category><![CDATA[python]]></category>
            <dc:creator><![CDATA[Cameron Jones]]></dc:creator>
            <pubDate>Wed, 24 May 2023 12:43:46 GMT</pubDate>
            <atom:updated>2023-05-26T11:43:36.493Z</atom:updated>
            <content:encoded><![CDATA[<p><em>Follow me on </em><a href="https://twitter.com/cameronjoejones"><em>Twitter</em></a></p><p>Hi there! Today I will be diving into something a little different than my previous Streamlit/python projects focused on data. Instead, I will show you how you can create a web app that removes metadata from images. We’ll utilise <a href="http://www.streamlit.io/">Streamlit</a>, a powerful tool for creating custom web apps with Python, as well as Piexif for handling metadata extraction and modification. Let’s get started.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Ni98kwEqeZArK_P5kZH4PQ.png" /><figcaption>image of the application</figcaption></figure><h4>Here’s a demo embedded version of the application:</h4><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fmetadata.streamlit.app%2F%3Fembed%3Dtrue%26embed%3Dtrue&amp;display_name=Streamlit&amp;url=https%3A%2F%2Fmetadata.streamlit.app%2F%3Fembed%3Dtrue&amp;image=https%3A%2F%2Fstorage.googleapis.com%2Fs4a-prod-share-preview%2Fdefault%2Fst_app_fallback_image.png&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;schema=streamlit" width="560" height="630" frameborder="0" scrolling="no"><a href="https://medium.com/media/e06f71e1037b6a046ecfd591f6451d0f/href">https://medium.com/media/e06f71e1037b6a046ecfd591f6451d0f/href</a></iframe><p>Here you will find the source code and link to the main app:</p><ul><li>Main app: <a href="https://metadata.streamlit.app/">https://metadata.streamlit.app</a></li><li>Source code: <a href="https://github.com/cameronjoejones/streamlit-metadata-remover">https://github.com/cameronjoejones/streamlit-metadata-remover</a></li></ul><h3>Introduction</h3><p>Images often come with metadata attached — this might be the date the photo was taken, the camera model, or even the GPS location. While often useful, there might be instances where you want to strip out this data for privacy reasons. That’s exactly what our app does.</p><h3>Setting Up the Environment</h3><p>Before we can start coding, we need to ensure our environment is set up correctly. We’ll be using Python and some specific libraries for this project. Here are the steps to get your development environment ready:</p><h4><strong>1. Virtual Environment Setup</strong></h4><p>It’s a good practice to create a virtual environment for each Python project to manage dependencies better. You can create a new virtual environment in Python using the venv module:</p><pre>python3 -m venv env</pre><h4>2. Install Necessary Python Libraries</h4><p>After setting up and activating the virtual environment, you need to install the Python libraries necessary for this project, namely Streamlit and Piexif:</p><pre>pip install streamlit piexif pillow</pre><h3>Code Breakdown:</h3><p>The script can be divided into three main components: Configuring the page, setting up the sidebar, and the main application.</p><h4><strong>Importing Libraries</strong></h4><pre>import streamlit as st<br>from PIL import Image<br>import piexif<br>import base64<br>import io</pre><p>The code starts with the necessary imports. Streamlit (st) for the web app, Image from the PIL (Python Imaging Library) to handle image data, piexif to extract the image&#39;s metadata (Exif data), and base64 and io for encoding the image data.</p><h4>1. Page Configuration</h4><pre>def page_config():<br>    st.set_page_config(<br>        page_title=&quot;Image Metadata Remover&quot;,<br>        page_icon=&quot;📷&quot;,<br>        layout=&quot;wide&quot;<br>    )<br><br>    hide_menu_style = &quot;&lt;style&gt; footer {visibility: hidden;} &lt;/style&gt;&quot;<br>    st.markdown(hide_menu_style, unsafe_allow_html=True)</pre><p>We start by defining the page_config function. We use the st.set_page_config method to set up the page title, page icon, and layout. Also, we use some custom CSS to hide the default Streamlit footer.</p><h4>2. Sidebar Configuration</h4><pre>def sidebar():<br>    st.sidebar.markdown(<br>    st.sidebar.title(&quot;About&quot;)<br>    st.sidebar.info(<br>        &quot;&quot;&quot;This is a simple web app to remove metadata from images.&quot;&quot;&quot;)<br>    st.sidebar.title(&quot;How to use it?&quot;)<br>    st.sidebar.info(<br>        &quot;&quot;&quot;1. Upload an JPG image<br>2. Click on the button to remove metadata.<br>3. The metadata and image will be displayed.<br>4. Download the image without metadata&quot;&quot;&quot;)</pre><p>Next, we create a sidebar using st.sidebar to provide instructions to the user.</p><h4>3. Main Application</h4><pre>def app():<br>    st.title(&#39;📷 Image Metadata Remover&#39;)<br><br>    example_image = st.checkbox(&#39;Use Example Image&#39;)<br><br>    if example_image == False:<br>        uploaded_file = st.file_uploader(&quot;Choose an image...&quot;, type=[&quot;jpg&quot;, &quot;jpeg&quot;])<br><br>    elif example_image == True:<br>        uploaded_file = &#39;input/streamlit-picture.jpeg&#39;<br><br>    button = st.button(&#39;Remove Metadata&#39;)</pre><p>The main application begins by providing an image uploader using st.file_uploader, which accepts .jpg or .jpeg files. We then show a button to remove the metadata from the uploaded image.</p><pre>if button:<br>        if uploaded_file is None:<br>            st.warning(&#39;Please upload an image first!&#39;)<br><br>        elif uploaded_file is not None:<br>            image = Image.open(uploaded_file)<br>            col1, col2 = st.columns(2)<br>            exif_dict = None<br><br>            if &quot;exif&quot; in image.info:<br>                exif_dict = piexif.load(image.info[&quot;exif&quot;])<br>                with col1:<br>                    st.write(&quot;Original Metadata:&quot;)<br>                    st.json(exif_dict)<br><br>            else:<br>                with col1:<br>                    st.write(&quot;No Metadata Found!&quot;)<br><br>            data = image.getdata()<br>            image_without_exif = Image.new(image.mode, image.size)<br>            image_without_exif.putdata(data)<br><br>            with col2:<br>                st.image(image_without_exif, caption=&#39;Image without metadata&#39;, use_column_width=True)<br><br>            if exif_dict is not None:<br>                st.success(&#39;Metadata has been removed successfully!&#39;)<br>            else:<br>                st.info(&#39;The image did not contain metadata.&#39;)</pre><p>When the user clicks the button, the script opens the image and checks if it contains any metadata. If it does, we display the metadata in one column and the image without metadata in another column. If the image does not contain metadata, a message is displayed to the user.</p><pre>st.markdown(get_image_download_link(image_without_exif, image.format, &#39;image_without_metadata.&#39; + image.format.lower(), &#39;Download image without metadata&#39;), unsafe_allow_html=True)</pre><p>Lastly, we provide a link for the user to download the image without metadata.</p><h3>Running the Web App</h3><p>open a terminal window, navigate to the directory where your .py file is saved, and run the command</p><pre>streamlit run &lt;your-file-name.py&gt;</pre><p>The app will open in a web browser in a local environment.</p><h3>Deploying the App to the web</h3><p>Simply follow Streamlit’s simple documentation on how to deploy your app to the web <a href="https://docs.streamlit.io/streamlit-community-cloud/get-started/deploy-an-app">https://docs.streamlit.io/streamlit-community-cloud/get-started/deploy-an-app</a></p><p>Happy coding!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=6e4e33772dd8" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Building a KPI dashboard in Streamlit using Python]]></title>
            <link>https://medium.com/@cameronjosephjones/building-a-kpi-dashboard-in-streamlit-using-python-c88ac63903f5?source=rss-fcadb85a9bcd------2</link>
            <guid isPermaLink="false">https://medium.com/p/c88ac63903f5</guid>
            <category><![CDATA[data-science]]></category>
            <category><![CDATA[data-analysis]]></category>
            <category><![CDATA[portfolio]]></category>
            <category><![CDATA[python]]></category>
            <category><![CDATA[streamlit]]></category>
            <dc:creator><![CDATA[Cameron Jones]]></dc:creator>
            <pubDate>Sat, 06 May 2023 13:22:32 GMT</pubDate>
            <atom:updated>2023-05-06T13:22:32.640Z</atom:updated>
            <content:encoded><![CDATA[<h4>A step-by-step guide to creating a Python data analyst portfolio project</h4><p><em>Follow me on </em><a href="https://twitter.com/cameronjoejones"><em>Twitter</em></a><em> and check out the source code on </em><a href="https://github.com/cameronjoejones/streamlit-sales-dashboard"><em>GitHub</em></a></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*8ASf5xmZQ3v6ckh_3tyWqQ.png" /><figcaption>Sales KPIs dashboard</figcaption></figure><p>Checkout the web app here: <a href="https://cameronjoejones-streamlit-sales-dashboard-app-3pmk71.streamlit.app/">https://cameronjoejones-streamlit-sales-dashboard-app-3pmk71.streamlit.app/</a></p><p>In today’s data-driven world, the ability to quickly and effectively analyse data is crucial. Data analysts need powerful tools that can help them gain insights from data and share their findings with others. In this tutorial, I’ll walk you through the process of building an interactive sales dashboard using Streamlit, Pandas, and Plotly.</p><p>Streamlit is an open-source Python library that enables you to build interactive web applications quickly and easily. Pandas is a popular data manipulation library, and Plotly is a library for creating interactive visualisations. Together, these libraries make it simple to create an engaging and informative dashboard.</p><h4>Data for the project</h4><p>In this project, the data is from Kaggle — you can download the dataset from here: <a href="https://www.kaggle.com/datasets/kyanyoga/sample-sales-data">https://www.kaggle.com/datasets/kyanyoga/sample-sales-data</a> or use your own dataset and rebuild the project yourself.</p><h4>Setting up your environment</h4><p>To get started, install the required packages:</p><pre>pip install streamlit<br>pip install pandas<br>pip install plotly</pre><p>I’ll be using the following code to create our sales dashboard. In the sections below, I will explain each part of the code and how it contributes to the final product.</p><h3>Code</h3><h4>Import libraries and set up the environment:</h4><pre>from typing import List, Tuple<br><br>import pandas as pd<br>import plotly.express as px<br>import streamlit as st</pre><p>This section imports the necessary libraries: pandas, plotly.express, and streamlit. Additionally, it imports List and Tuple from the typing module for type hinting.</p><h4>Set up the page configuration:</h4><pre>def set_page_config():<br>    st.set_page_config(<br>        page_title=&quot;Sales Dashboard&quot;,<br>        page_icon=&quot;:bar_chart:&quot;,<br>        layout=&quot;wide&quot;,<br>        initial_sidebar_state=&quot;expanded&quot;,<br>    )<br>    st.markdown(&quot;&lt;style&gt; footer {visibility: hidden;} &lt;/style&gt;&quot;, unsafe_allow_html=True)</pre><p>The set_page_config() function sets the page title, icon, layout, and initial sidebar state for the Streamlit app. It also hides the default footer using custom CSS.</p><h4>Load and cache data</h4><pre>@st.cache_data<br>def load_data() -&gt; pd.DataFrame:<br>    data = pd.read_csv(&#39;data/sales_data_sample.csv&#39;, encoding=&#39;latin1&#39;)<br>    data[&#39;ORDERDATE&#39;] = pd.to_datetime(data[&#39;ORDERDATE&#39;])<br>    return data</pre><p>The load_data() function reads a CSV file containing sales data and converts the ORDERDATE column to a datetime format. The @st.cache_data decorator caches the result of this function, ensuring that the data is only loaded once.</p><h4>Data filtering and KPI calculation:</h4><pre>def filter_data(data: pd.DataFrame, column: str, values: List[str]) -&gt; pd.DataFrame:<br>    return data[data[column].isin(values)] if values else data<br><br><br>@st.cache_data<br>def calculate_kpis(data: pd.DataFrame) -&gt; List[float]:<br>    total_sales = data[&#39;SALES&#39;].sum()<br>    sales_in_m = f&quot;{total_sales / 1000000:.2f}M&quot;<br>    total_orders = data[&#39;ORDERNUMBER&#39;].nunique()<br>    average_sales_per_order = f&quot;{total_sales / total_orders / 1000:.2f}K&quot;<br>    unique_customers = data[&#39;CUSTOMERNAME&#39;].nunique()<br>    return [sales_in_m, total_orders, average_sales_per_order, unique_customers]</pre><p>The filter_data() function filters a DataFrame based on the given column and list of values. The calculate_kpis() function calculates four key performance indicators (KPIs): total sales, total orders, average sales per order, and the number of unique customers.</p><h4>Display KPI metrics:</h4><pre>def display_kpi_metrics(kpis: List[float], kpi_names: List[str]):<br>    st.header(&quot;KPI Metrics&quot;)<br>    for i, (col, (kpi_name, kpi_value)) in enumerate(zip(st.columns(4), zip(kpi_names, kpis))):<br>        col.metric(label=kpi_name, value=kpi_value)</pre><p>The display_kpi_metrics() function takes a list of KPIs and their corresponding names and displays them as metric cards in a row using Streamlit&#39;s st.metric() function.</p><h4>Display the sidebar and filters:</h4><pre>def display_sidebar(data: pd.DataFrame) -&gt; Tuple[List[str], List[str], List[str]]:<br>    st.sidebar.header(&quot;Filters&quot;)<br>    start_date = pd.Timestamp(st.sidebar.date_input(&quot;Start date&quot;, data[&#39;ORDERDATE&#39;].min().date()))<br>    end_date = pd.Timestamp(st.sidebar.date_input(&quot;End date&quot;, data[&#39;ORDERDATE&#39;].max().date()))<br><br>    product_lines = sorted(data[&#39;PRODUCTLINE&#39;].unique())<br>    selected_product_lines = st.sidebar.multiselect(&quot;Product lines&quot;, product_lines, product_lines)<br><br>    selected_countries = st.sidebar.multiselect(&quot;Select Countries&quot;, data[&#39;COUNTRY&#39;].unique())<br><br>    selected_statuses = st.sidebar.multiselect(&quot;Select Order Statuses&quot;, data[&#39;STATUS&#39;].unique())<br><br>    return selected_product_lines, selected_countries, selected_statuses</pre><p>The display_sidebar() function creates a sidebar with various filters (date range, product lines, countries, order statuses).</p><h4>Display charts and data tables:</h4><pre>def display_charts(data: pd.DataFrame):<br>    combine_product_lines = st.checkbox(&quot;Combine Product Lines&quot;, value=True)<br><br>    if combine_product_lines:<br>        fig = px.area(data, x=&#39;ORDERDATE&#39;, y=&#39;SALES&#39;,<br>                      title=&quot;Sales by Product Line Over Time&quot;, width=900, height=500)<br>    else:<br>        fig = px.area(data, x=&#39;ORDERDATE&#39;, y=&#39;SALES&#39;, color=&#39;PRODUCTLINE&#39;,<br>                      title=&quot;Sales by Product Line Over Time&quot;, width=900, height=500)<br><br>    fig.update_layout(margin=dict(l=20, r=20, t=50, b=20))<br>    fig.update_xaxes(rangemode=&#39;tozero&#39;, showgrid=False)<br>    fig.update_yaxes(rangemode=&#39;tozero&#39;, showgrid=True)<br>    st.plotly_chart(fig, use_container_width=True)<br><br>    col1, col2, col3 = st.columns(3)<br><br>    with col1:<br>        st.subheader(&quot;Top 10 Customers&quot;)<br>        top_customers = data.groupby(&#39;CUSTOMERNAME&#39;)[&#39;SALES&#39;].sum().reset_index().sort_values(&#39;SALES&#39;,<br>                                                                                              ascending=False).head(10)<br>        st.write(top_customers)<br><br>    with col2:<br>        st.subheader(&quot;Top 10 Products by Sales&quot;)<br>        top_products = data.groupby([&#39;PRODUCTCODE&#39;, &#39;PRODUCTLINE&#39;])[&#39;SALES&#39;].sum().reset_index().sort_values(&#39;SALES&#39;,<br>                                                                                                             ascending=False).head(<br>            10)<br>        st.write(top_products)<br><br>    with col3:<br>        st.subheader(&quot;Total Sales by Product Line&quot;)<br>        total_sales_by_product_line = data.groupby(&#39;PRODUCTLINE&#39;)[&#39;SALES&#39;].sum().reset_index()<br>        st.write(total_sales_by_product_line)</pre><p>The display_charts() function creates and displays interactive charts and data tables using Plotly and Streamlit. It includes an area chart for sales by product line over time, a top 10 customers table, a top 10 products by sales table, and a total sales by product line table.</p><h4>The main function:</h4><pre>def main():<br>    set_page_config()<br><br>    data = load_data()<br><br>    st.title(&quot;📊 Sales Dashboard&quot;)<br><br>    selected_product_lines, selected_countries, selected_statuses = display_sidebar(data)<br><br>    filtered_data = data.copy()<br>    filtered_data = filter_data(filtered_data, &#39;PRODUCTLINE&#39;, selected_product_lines)<br>    filtered_data = filter_data(filtered_data, &#39;COUNTRY&#39;, selected_countries)<br>    filtered_data = filter_data(filtered_data, &#39;STATUS&#39;, selected_statuses)<br><br>    kpis = calculate_kpis(filtered_data)<br>    kpi_names = [&quot;Total Sales&quot;, &quot;Total Orders&quot;, &quot;Average Sales per Order&quot;, &quot;Unique Customers&quot;]<br>    display_kpi_metrics(kpis, kpi_names)<br><br>    display_charts(filtered_data)<br><br><br>if __name__ == &#39;__main__&#39;:<br>    main()</pre><p>The main() function ties everything together. It sets up the page configuration, loads the data, and displays the title, sidebar, KPI metrics, and charts. The data is filtered based on the selected filters in the sidebar, and the KPIs are recalculated and displayed accordingly. The dashboard is executed by calling the main() function when the script is run.</p><h3>Testing the app/ running locally</h3><p>To run the app, save the code in a file named app.py, and then run the following command:</p><pre>streamlit run app.py</pre><p>Your app will open in a web browser and allow you to see the dashboard in a local environement.</p><h3>Deploying the App to the web</h3><p>Simply follow Streamlit’s simple documentation on how to deploy your app to the web <a href="https://docs.streamlit.io/streamlit-community-cloud/get-started/deploy-an-app">https://docs.streamlit.io/streamlit-community-cloud/get-started/deploy-an-app</a></p><p>Happy coding!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=c88ac63903f5" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Building Your Own ChatGPT Data Assistant: Streamline Data Analysis with AI-Powered Responses]]></title>
            <link>https://medium.com/@cameronjosephjones/building-your-own-chatgpt-data-assistant-streamline-data-analysis-with-ai-powered-responses-ad6ef4ee7a4d?source=rss-fcadb85a9bcd------2</link>
            <guid isPermaLink="false">https://medium.com/p/ad6ef4ee7a4d</guid>
            <category><![CDATA[chatgpt]]></category>
            <category><![CDATA[openai]]></category>
            <category><![CDATA[streamlit]]></category>
            <category><![CDATA[python]]></category>
            <category><![CDATA[data]]></category>
            <dc:creator><![CDATA[Cameron Jones]]></dc:creator>
            <pubDate>Tue, 02 May 2023 15:21:19 GMT</pubDate>
            <atom:updated>2023-05-02T15:21:19.118Z</atom:updated>
            <content:encoded><![CDATA[<h4><strong>An easy-to-use data analysis tool that combines the flexibility of Streamlit and the intelligence of OpenAI GPT-4.</strong></h4><p><em>Follow me on </em><a href="https://twitter.com/cameronjoejones"><em>Twitter</em></a><em> and check out the source code on </em><a href="https://github.com/cameronjoejones/streamlit-gpt-data-assistant"><em>GitHub</em></a><em>.</em></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/959/1*Y_cI1ujrY9HWNco9gtGwwA.png" /><figcaption>Data Assistant Web App</figcaption></figure><p>Checkout the deployed web app here: <a href="https://aidata.streamlit.app/">https://aidata.streamlit.app/</a></p><p>Data analysis is crucial for making informed decisions, but it can be a time-consuming process. The ChatGPT Data Assistant aims to simplify this task by leveraging the power of OpenAI’s GPT-4 and Streamlit’s user-friendly interface. In this guide, we’ll walk you through the process of building your own ChatGPT Data Assistant, a web application that provides quick and accurate AI-powered responses to data-related questions.</p><h3>Getting Started:</h3><p>Before diving into the code, make sure you have the following requirements to build this yourself:</p><ul><li>Basic knowledge of Python</li><li>OpenAI API access (get it <a href="https://platform.openai.com/">here</a>)</li><li>Basic knowledge of Pandas</li></ul><h4><strong>Overview</strong></h4><p>Our project will have the following features:</p><ul><li>Connection to OpenAIs GPT API</li><li>Ability to upload CSV files to get AI analysis</li><li>Storage bank of prompts (JSON format)</li></ul><h4>Setting up your environment</h4><p>Have these required packages installed:</p><pre>pip install streamlit<br>pip install openai<br>pip install pandas</pre><h3>Set up the API key</h3><p>When developing your app locally, add a file called secrets.toml in a folder called .streamlit at the root of your app repo</p><pre>[api_key]<br>open_ai = &quot;&lt;your api key here&gt;&quot;</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/373/0*uKLRYhBG6erONTFv.png" /><figcaption>setting up secrets</figcaption></figure><h4>Establishing a connection to the API</h4><p>Now create a Python file named api.py this is where we will store the function to call our API and with our prompts.</p><p>To facilitate the AI-powered response generation, create a Python class called OpenAI_API and a function named open_ai_response. The OpenAI_API class ensures that you have a working API key before running the app. The open_ai_response function generates the AI response based on the provided question and dataframe.</p><pre>import openai<br>import pandas as pd<br><br><br>class OpenAI_API: # this class ensures we have an working API key<br>    def __init__(self, api_key):<br>        self.api_key = api_key<br><br>    def __enter__(self):<br>        openai.api_key = self.api_key<br><br>    def __exit__(self, exc_type, exc_val, exc_tb):<br>        pass<br><br><br>def open_ai_response(question: str, dataframe: pd.DataFrame) -&gt; str:<br>    # here we create the prompt that is fed into GPT<br>    prompt = f&#39;&#39;&#39;{question}<br>    \n<br>    [dataframe]<br>    \n{dataframe}&#39;&#39;&#39; <br>    model_engine = &quot;text-davinci-003&quot; # model, here it is GPT-3<br><br>    response = openai.Completion.create(<br>    engine=model_engine,<br>    prompt=prompt,<br>    max_tokens=1000, # number of tokens allowed<br>    )<br><br>    answer = response.choices[0].text.strip() # ensures we only the text<br>    print(prompt)<br><br>    return answer</pre><h4>Prompt generation/ Bank of questions</h4><p>Before diving into the main app function, create a dictionary named question_bank that contains pre-defined prompts for the application. Each key in the dictionary represents a specific data analysis task, and its value is another dictionary containing a question and a response format. This structure will allow users to select from a range of predefined prompts when using the app.</p><pre>question_bank = {<br>    &quot;FileOverview&quot;: {<br>        &quot;question&quot;: &quot;Can you provide an overview of the data file, including the number of rows, columns, and data types?&quot;,<br>        &quot;response_format&quot;: &quot;text&quot;<br>    },<br>    # ... (include the rest of the question_bank entries here)<br>}</pre><p>Full list of prompts <a href="https://github.com/cameronjoejones/streamlit-gpt-data-assistant/blob/main/question_bank.py">here</a></p><p>Now save this is a Python file named question_bank.py by saving this in Python it makes it easy to import this dictionary later.</p><h3>Creating the main application</h3><p>Once the previous setup has been completed you can now created the main Streamlit application.</p><p>Start by creating a Python file named app.py</p><p><strong>Importing libraries and modules:</strong></p><pre>import streamlit as st<br>import pandas as pd<br>from api import OpenAI_API, open_ai_response<br>from question_bank import question_bank</pre><p>This section imports necessary libraries and modules, such as Streamlit, pandas, OpenAI_API, and open_ai_response.</p><h4><strong>Configure the page:</strong></h4><pre>def page_config():<br>    st.set_page_config(page_title=&quot;ChatGPT Data Assistant&quot;, page_icon=&quot;📊&quot;, layout=&quot;centered&quot;)<br>    hide_menu_style = &quot;&lt;style&gt; footer {visibility: hidden;} &lt;/style&gt;&quot;<br>    st.markdown(hide_menu_style, unsafe_allow_html=True)<br>    st.title(&#39;🤵🏻‍♂️ ChatGPT Data Assistant&#39;)</pre><p>The page_config() function sets the page configuration, such as the title, icon, layout, and hiding the footer.</p><h4><strong>Create the sidebar</strong></h4><pre>def sidebar():<br>    st.sidebar.title(&#39;About&#39;)<br>    st.sidebar.info(&#39;&#39;&#39;<br>        This app uses the [OpenAI API](https://beta.openai.com/) to generate responses to questions about data files.<br>                    &#39;&#39;&#39;)<br>    st.sidebar.title(&#39;Guide&#39;)<br>    st.sidebar.info(&#39;&#39;&#39;<br>        1. Upload a data file in CSV format.<br>        2. Select a prompt from the dropdown menu.<br>        3. Click the &quot;Generate response&quot; button.<br>                    &#39;&#39;&#39;)</pre><p>The sidebar() function creates the sidebar content, including the About section, and Guide.</p><h4>Define the main app function</h4><p><strong>Check for API key</strong></p><pre>def run_app():<br>  api_key = st.secrets[&quot;api_key&quot;][&#39;open_ai&#39;]<br>  if api_key is None:<br>    st.error(&#39;API key not found. Please set the api_key in the .streamlit/secrets.toml file.&#39;)</pre><p>This section checks if the API key is present in the .streamlit/secrets.toml file. If not, it displays an error message asking the user to set the API key. (this will also apply to the deployed web app version).</p><p><strong>Initialise OpenAI_API context:</strong></p><pre>with OpenAI_API(api_key):</pre><p>Using the OpenAI_API class we previously created, this section initialises the API context with the provided API key.</p><p><strong>Allow users to choose between example data or uploading their own:</strong></p><pre>example_data = st.checkbox(&#39;Use example data&#39;, value=False)<br>if example_data == True:<br>    upload_file = r&#39;input/example_data.csv&#39;<br>    st.write(pd.read_csv(upload_file))<br>elif example_data == False:<br>    upload_file = st.file_uploader(&quot;Upload your data file&quot;, type=&#39;csv&#39;)</pre><p>This section provides a checkbox for users to choose between using example data or uploading their own data file in CSV format.</p><p><strong>Display a dropdown menu for prompt selection:</strong></p><pre>prompt_selected = st.selectbox(&#39;Select a prompt&#39;, list(question_bank.keys()))<br>prompt = question_bank[prompt_selected][&#39;question&#39;]<br>st.write(prompt)</pre><p>This part displays a dropdown menu for users to select a prompt from the question_bank. The selected prompt is then displayed on the page.</p><p><strong>Create a “Generate response” button:</strong></p><pre>submit = st.button(&#39;Generate response&#39;)</pre><p>This line creates a button that, when clicked, triggers the AI response generation process.</p><p><strong>Generate and display AI response:</strong></p><pre>if submit:<br>    with st.spinner(&#39;Generating response...&#39;):            <br>        if upload_file is not None:<br>            if example_data == False:<br>                if upload_file.name.endswith(&#39;.csv&#39;):<br>                    df = pd.read_csv(upload_file)<br>                elif upload_file.name.endswith(&#39;.xlsx&#39;) or upload_file.name.endswith(&#39;.xls&#39;):<br>                    df = pd.read_excel(upload_file)<br>            elif example_data == True:<br>                df = pd.read_csv(upload_file)<br>            <br>            prompt = question_bank[prompt_selected][&#39;question&#39;]<br>            answer = open_ai_response(prompt, df)<br>            st.markdown(&#39;### Ouput:&#39;)<br>            st.write(answer)<br><br>            print(answer)<br>        else:<br>            st.error(&#39;Please upload a data file&#39;)<br>            st.stop()<br>        return df</pre><p>This section is responsible for generating the AI response. If the “Generate response” button is clicked, it checks whether a data file has been uploaded. If so, it reads the data into a pandas DataFrame, selects the appropriate prompt, and calls the open_ai_response() function to generate the AI response. The generated response is then displayed on the page.</p><p>If no data file is uploaded, it displays an error message asking the user to upload a data file.</p><p><strong>Main execution:</strong></p><pre>if __name__ == &#39;__main__&#39;:<br>    page_config()<br>    run_app()<br>    sidebar()</pre><p>The main execution block calls the page_config() function to set up the page, the run_app() function to handle the core app functionality, and the sidebar() function to display the sidebar content.</p><h3>Running the App locally</h3><p>To run the app, save the code in a file named app.py, and then run the following command:</p><pre>streamlit run app.py</pre><p>Your app will open in a web browser.</p><h3>Deploying the App to the web</h3><p>Simply follow Streamlit’s simple documentation on how to deploy your app to the web <a href="https://docs.streamlit.io/streamlit-community-cloud/get-started/deploy-an-app">https://docs.streamlit.io/streamlit-community-cloud/get-started/deploy-an-app</a></p><h3>Conclusion:</h3><p>By following this step-by-step guide and incorporating the OpenAI_API class and open_ai_response function, you can build your own ChatGPT Data Assistant, a powerful tool that streamlines data analysis using AI-powered responses. With the combination of OpenAI&#39;s GPT-4 and Streamlit&#39;s user-friendly interface, you can create a custom web application that simplifies the process of data analysis and makes it more accessible for users of all skill levels.</p><p>Happy coding!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=ad6ef4ee7a4d" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Building a Stock Price Dashboard with Streamlit, Python, and APIs]]></title>
            <link>https://medium.com/@cameronjosephjones/building-a-stock-price-dashboard-with-streamlit-python-and-apis-bc57011758d4?source=rss-fcadb85a9bcd------2</link>
            <guid isPermaLink="false">https://medium.com/p/bc57011758d4</guid>
            <category><![CDATA[portfolio]]></category>
            <category><![CDATA[python]]></category>
            <category><![CDATA[api]]></category>
            <category><![CDATA[streamlit]]></category>
            <category><![CDATA[data-analysis]]></category>
            <dc:creator><![CDATA[Cameron Jones]]></dc:creator>
            <pubDate>Fri, 28 Apr 2023 20:07:03 GMT</pubDate>
            <atom:updated>2023-05-03T10:37:10.091Z</atom:updated>
            <content:encoded><![CDATA[<h4>A step-by-step guide to creating a data analyst portfolio project</h4><p><em>Follow me on </em><a href="https://twitter.com/cameronjoejones"><em>Twitter</em></a><em> and check out the source code on </em><a href="https://github.com/cameronjoejones/streamlit-kpi-dashboard"><em>GitHub</em></a><em>.</em></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*f2Ma_wt34Q-Ei2lZ2mdx0g.png" /><figcaption>stock price dashboard</figcaption></figure><p>Checkout the web app here: <a href="https://stocksapi.streamlit.app/">https://stocksapi.streamlit.app/</a></p><p>Are you looking to build an impressive data analyst portfolio project? Look no further! In this tutorial, I will guide you through creating a stock dashboard app using Streamlit, Python, and the IEX Cloud API. This app showcases your skills in Python, data visualisation, and working with APIs.</p><h4>Prerequisites</h4><p>Before we start, make sure you have the following:</p><ul><li>Basic understanding of Python programming</li><li>Familiarity with Pandas</li><li>An IEX Cloud API key (get it <a href="https://iexcloud.io/">here</a>)</li></ul><h4>Overview</h4><p>Our stock dashboard app will have the following features:</p><ul><li>Displaying stock data for user-selected symbols</li><li>Calculating price differences and percentage changes</li><li>Visualising stock data using a candlestick chart</li><li>Exporting stock data as a CSV file</li></ul><h4>Setting up your environment</h4><p>To get started, install the required packages:</p><pre>pip install streamlit<br>pip install requests<br>pip install pandas<br>pip install plotly</pre><h4>Set up the API key</h4><p>When developing your app locally, add a file called secrets.toml in a folder called .streamlit at the root of your app repo</p><pre>[api]<br>iex_key = &quot;&lt;your_iex_cloud_api_key&gt;&quot;</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/373/1*0-6jwNdHAuPnJ2zGYy5rxQ.png" /><figcaption>setting up secrets</figcaption></figure><p>Streamlit is a powerful library that allows you to build interactive web apps with just a few lines of code. In our app, we’ll use Streamlit to create a user-friendly interface, display stock data, and handle user inputs.</p><h4>Fetching Stock Data with IEX Cloud API</h4><p>We’ll use the IEX Cloud API to fetch stock data for our app. The API provides historical stock data, such as open, high, low, close, and volume values. Create an account on the <a href="https://iexcloud.io/">IEX Cloud website</a> and get your API key.</p><h3>Building the App</h3><p><strong>Imports and global variables</strong></p><pre>import streamlit as st<br>import requests<br>import pandas as pd<br>import plotly.graph_objs as go<br><br>API_KEY = st.secrets[&quot;api&quot;][&quot;iex_key&quot;]<br>API_BASE_URL = &quot;https://cloud.iexapis.com/stable/&quot;</pre><p>Here, we import the necessary libraries and set up global variables for the API key and the API’s base URL.</p><p><strong>Fetching stock data</strong></p><pre>def get_stock_data(symbol, time_range=&quot;5y&quot;):<br>    params = {<br>        &quot;token&quot;: API_KEY<br>    }<br><br>    response = requests.get(API_BASE_URL + f&quot;stock/{symbol}/chart/{time_range}&quot;, params=params)<br>    data = response.json()<br><br>    if &quot;error&quot; in data:<br>        st.error(f&quot;Error: {data[&#39;error&#39;]}&quot;)<br>        return None<br><br>    stock_data = pd.DataFrame(data)<br>    stock_data[&quot;date&quot;] = pd.to_datetime(stock_data[&quot;date&quot;])<br>    stock_data.set_index(&quot;date&quot;, inplace=True)<br>    stock_data = stock_data[[&quot;open&quot;, &quot;high&quot;, &quot;low&quot;, &quot;close&quot;, &quot;volume&quot;]]<br>    stock_data.columns = [&quot;Open&quot;, &quot;High&quot;, &quot;Low&quot;, &quot;Close&quot;, &quot;Volume&quot;]<br>    return stock_data</pre><p>This function fetches stock data for a given symbol and time range from the IEX Cloud API. It converts the fetched data into a Pandas DataFrame, processes the date column, and returns the processed stock data.</p><p><strong>Calculating price differences</strong></p><pre>def calculate_price_difference(stock_data):<br>    latest_price = stock_data.iloc[-1][&quot;Close&quot;]<br>    previous_year_price = stock_data.iloc[-252][&quot;Close&quot;] if len(stock_data) &gt; 252 else stock_data.iloc[0][&quot;Close&quot;]<br>    price_difference = latest_price - previous_year_price<br>    percentage_difference = (price_difference / previous_year_price) * 100<br>    return price_difference, percentage_difference</pre><p>This function calculates the price difference and percentage change for the stock data. It takes the latest closing price and the closing price from one year ago (or the earliest available data) and computes the difference and percentage.</p><p><strong>Main app function</strong></p><pre>def app():<br>    #-- BOLIERPLATE --#<br>    st.set_page_config(page_title=&quot;Stock Dashboard&quot;, layout=&quot;wide&quot;, page_icon=&quot;📈&quot;)<br>    hide_menu_style = &quot;&lt;style&gt; footer {visibility: hidden;} &lt;/style&gt;&quot;<br>    st.markdown(hide_menu_style, unsafe_allow_html=True)<br><br>    st.title(&quot;📈 Stock Dashboard&quot;)<br>    popular_symbols = [&quot;AAPL&quot;, &quot;GOOGL&quot;, &quot;MSFT&quot;, &quot;AMZN&quot;, &quot;TSLA&quot;, &quot;FB&quot;, &quot;BRK-B&quot;, &quot;V&quot;, &quot;NVDA&quot;, &quot;JPM&quot;]<br>    symbol = st.sidebar.selectbox(&quot;Select a stock symbol:&quot;, popular_symbols, index=2)</pre><p>The app() function starts by configuring the Streamlit app with a title, layout, and icon. It then creates a sidebar with a select box for users to choose a stock symbol.</p><p><strong>Displaying stock data</strong></p><pre>    if symbol:<br>        stock_data = get_stock_data(symbol)<br><br>        if stock_data is not None:<br>            price_difference, percentage_difference = calculate_price_difference(stock_data)<br>            latest_close_price = stock_data.iloc[-1][&quot;Close&quot;]<br>            max_52_week_high = stock_data[&quot;High&quot;].tail(252).max()<br>            min_52_week_low = stock_data[&quot;Low&quot;].tail(252).min()</pre><p>Once the user selects a symbol, the app fetches the stock data and calculates the necessary metrics, such as the latest closing price, price difference, 52-week high, and 52-week low.</p><p><strong>Displaying metrics</strong></p><pre>col1, col2, col3, col4 = st.columns(4)<br>with col1:<br>    st.metric(&quot;Close Price&quot;, f&quot;${latest_close_price:.2f}&quot;)<br>with col2:<br>    st.metric(&quot;Price Difference (YoY)&quot;, f&quot;${price_difference:.2f}&quot;, f&quot;{percentage_difference:+.2f}%&quot;)<br>with col3:<br>    st.metric(&quot;52-Week High&quot;, f&quot;${max_52_week_high:.2f}&quot;)<br>with col4:<br>    st.metric(&quot;52-Week Low&quot;, f&quot;${min_52_week_low:.2f}&quot;)</pre><p>The app displays the calculated metrics using Streamlit’s st.metric() function, which creates visually appealing metric cards on the dashboard.</p><p><strong>Candlestick chart</strong></p><pre>st.subheader(&quot;Candlestick Chart&quot;)<br>candlestick_chart = go.Figure(data=[go.Candlestick(x=stock_data.index, open=stock_data[&#39;Open&#39;], high=stock_data[&#39;High&#39;], low=stock_data[&#39;Low&#39;], close=stock_data[&#39;Close&#39;])])<br>candlestick_chart.update_layout(title=f&quot;{symbol} Candlestick Chart&quot;, xaxis_rangeslider_visible=False)<br>st.plotly_chart(candlestick_chart, use_container_width=True)</pre><p>Next, the app creates a candlestick chart using Plotly’s go.Candlestick() function, which visualizes the stock data. The chart is then displayed using Streamlit&#39;s st.plotly_chart() function.</p><p><strong>Summary and data export</strong></p><pre>st.subheader(&quot;Summary&quot;)<br>st.dataframe(stock_data.tail())<br><br>st.download_button(&quot;Download Stock Data Overview&quot;, stock_data.to_csv(index=True), file_name=f&quot;{symbol}_stock_data.csv&quot;, mime=&quot;text/csv&quot;)</pre><p>The app shows a summary of the latest stock data using st.dataframe() and provides a download button for users to export the stock data as a CSV file.</p><p><strong>Running the function</strong></p><pre>if __name__ == &quot;__main__&quot;:<br>    app()</pre><p>Finally, the app() function is called when the script is run, starting the Streamlit app.</p><h3>Running the App locally</h3><p>To run the app, save the code in a file named stock_dashboard.py, and then run the following command:</p><pre>streamlit run stock_dashboard.py</pre><p>Your app will open in a web browser, and you can interact with it by selecting a stock symbol from the sidebar.</p><h4>Deploying the App to the web</h4><p>Simply follow Streamlit’s simple documentation on how to deploy your app to the web <a href="https://docs.streamlit.io/streamlit-community-cloud/get-started/deploy-an-app">https://docs.streamlit.io/streamlit-community-cloud/get-started/deploy-an-app</a></p><h4>Conclusion</h4><p>In this tutorial, we built a stock dashboard app using Streamlit, Python, and the IEX Cloud API. This app is a great addition to your data analyst portfolio, showcasing your skills in Python programming, data visualisation, and working with APIs.</p><p>Happy coding!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=bc57011758d4" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>