<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: FIORELA MILADY</title>
    <description>The latest articles on DEV Community by FIORELA MILADY (@fiorelamilady).</description>
    <link>https://dev.to/fiorelamilady</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F1437335%2F34ca3936-9578-4ccd-9ef4-f1c16abe0ece.png</url>
      <title>DEV Community: FIORELA MILADY</title>
      <link>https://dev.to/fiorelamilady</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/fiorelamilady"/>
    <language>en</language>
    <item>
      <title>Creating a Generative AI Chatbot with Python and Streamlit</title>
      <dc:creator>FIORELA MILADY</dc:creator>
      <pubDate>Thu, 11 Jul 2024 01:53:33 +0000</pubDate>
      <link>https://dev.to/fiorelamilady/creating-a-generative-ai-chatbot-with-python-and-streamlit-2g3b</link>
      <guid>https://dev.to/fiorelamilady/creating-a-generative-ai-chatbot-with-python-and-streamlit-2g3b</guid>
      <description>&lt;p&gt;&lt;strong&gt;Introduction&lt;/strong&gt;&lt;br&gt;
In the current era of artificial intelligence (AI), chatbots have revolutionized digital interaction by enabling natural conversations through natural language processing (NLP) and advanced language models. In this article, we will explore how to create a generative chatbot using Python and Streamlit.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Development Step by Step&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;****Environment Setup:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
We will install the necessary libraries and configure the connection with the OpenAI API.
&lt;/li&gt;
&lt;/ul&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;pip install openai streamlit
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;import openai
from dotenv import load_dotenv
import os
import streamlit as st
import time

load_dotenv()

api_key = os.getenv("OPENAI_API_KEY")

if not api_key:
    raise ValueError("No API key provided for OpenAI")

openai.api_key = api_key
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;


&lt;p&gt;User Interface with Streamlit: We will develop a simple web interface where users can interact with the generative chatbot.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;# Set the title for the Streamlit web app
st.title("My ChatGPT")

# Initialize session state for storing chat messages
if "messages" not in st.session_state:
    st.session_state["messages"] = [{"role": "assistant", "content": "Hello, I'm ChatGPT, how can I assist you today?"}]

# Display existing chat messages
for msg in st.session_state["messages"]:
    st.chat_message(msg["role"]).write(msg["content"])

# Check for user input and handle interaction with ChatGPT
if user_input := st.chat_input():
    # Add user input to session state as a message
    st.session_state["messages"].append({"role": "user", "content": user_input})

    # Attempt to call OpenAI's ChatCompletion API with error handling
    retries = 3
    success = False

    for attempt in range(retries):
        try:
            # Call the OpenAI ChatCompletion API with the current session messages
            response = openai.ChatCompletion.create(
                model="gpt-3.5-turbo",
                messages=st.session_state["messages"]
            )
            # Get the response message from the API and add it to session state
            response_message = response['choices'][0]['message']['content']
            st.session_state["messages"].append({"role": "assistant", "content": response_message})
            # Display the assistant's response in the chat interface
            st.chat_message("assistant").write(response_message)
            success = True  # Mark the request as successful
            break  # Exit the retry loop if successful
        except openai.error.RateLimitError as e:
            # Handle rate limit errors by warning and retrying after 5 seconds
            st.warning(f"RateLimitError: {e}. Retrying in 5 seconds...")
            time.sleep(5)
        except Exception as e:
            # Handle other exceptions by displaying an error message
            st.error(f"Error calling OpenAI API: {e}")
            break

    # Display an error message if the request was not successful after retries
    if not success:
        st.error("Could not complete request due to rate limit errors.")
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Result&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fenizwbeicgubs3wxfbi1.JPG" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fenizwbeicgubs3wxfbi1.JPG" alt="The Visual Studio Code editor displaying a Python file (app.py)." width="800" height="426"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F1pkpr2inec1k0whi30w2.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F1pkpr2inec1k0whi30w2.png" alt="The web interface generated by Streamlit for the chatbot " width="800" height="398"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Conclusion&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Creating a generative chatbot with Python and Streamlit is an endeavor that not only delves into natural language processing and machine learning but also showcases the potential of artificial intelligence to revolutionize digital interaction.&lt;/p&gt;

</description>
    </item>
    <item>
      <title>Building and Deploying a Dashboard in the Cloud with Streamlit and Python</title>
      <dc:creator>FIORELA MILADY</dc:creator>
      <pubDate>Sat, 20 Apr 2024 16:28:24 +0000</pubDate>
      <link>https://dev.to/fiorelamilady/building-and-deploying-a-dashboard-in-the-cloud-with-streamlit-and-python-4hm2</link>
      <guid>https://dev.to/fiorelamilady/building-and-deploying-a-dashboard-in-the-cloud-with-streamlit-and-python-4hm2</guid>
      <description>&lt;p&gt;&lt;strong&gt;DASHBOARD&lt;/strong&gt; &lt;br&gt;
It is a visual interface that condenses key information to facilitate informed decision-making in data analysis. Upon starting, the question arises: How can we effectively present our findings? This article details the process of creating a dashboard using visualization tools such as Streamlit and Python, as well as deploying our app in the Streamlit Cloud environment.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;STREAMLIT&lt;/strong&gt; &lt;br&gt;
It is an open-source framework for creating interactive web applications based on data, useful for the simple creation of interactive dashboards. It is an essential Python library for implementing dashboards with simple and fast lines of code.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fs6m7h85b4u2v8a96gwk6.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fs6m7h85b4u2v8a96gwk6.png" alt="Image description" width="800" height="468"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;STEPS&lt;/strong&gt;&lt;br&gt;
How to create and deploy a Dashboard step by step using Streamlit and Python. We will use the supermarket_sales dataset, which provides a detailed view of sales records that could be used for sales analysis, accounting, inventory management, or to better understand customer behavior.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;REQUIREMENTS&lt;/strong&gt;&lt;br&gt;
• Git installed on our local machine &lt;br&gt;
• GitHub account &lt;br&gt;
• Python installed&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;REPOSITORY&lt;/strong&gt;&lt;br&gt;
• Creation of the Local Repository &lt;br&gt;
• Create a folder containing all the files needed for your dashboard.&lt;br&gt;
• Start a local repository by running the command 'git init' in the command line.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;DATA ANALYSIS&lt;/strong&gt;&lt;br&gt;
Data can be viewed in the supermarket_sales.xls file&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;INSTALLATIONS&lt;/strong&gt;&lt;br&gt;
The necessary modules are installed using the following commands in the console: &lt;br&gt;
• pip install streamlit &lt;br&gt;
• pip install plotly &lt;br&gt;
• pip install openpyxl&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;DASHBOARD WITH STREAMLIT&lt;/strong&gt;&lt;br&gt;
For programming the dashboard with Streamlit, we will use the editor of our choice, in this case, Visual Studio Code. The code of the app.py&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;import pandas as pd
import plotly.express as px
import streamlit as st

# Page configuration
st.set_page_config(page_title="Sales Dashboard", page_icon=":bar_chart:", layout="wide")

# Function to read data from Excel file
@st.cache_data
def get_data_from_excel():
    df = pd.read_excel(
        io="supermarkt_sales.xlsx",
        engine="openpyxl",
        sheet_name="Sales",
        skiprows=3,
        usecols="B:R",
        nrows=1000,
    )
    # Add 'hour' column to the dataframe
    df["hour"] = pd.to_datetime(df["Time"], format="%H:%M:%S").dt.hour
    return df

df = get_data_from_excel()

# Sidebar for data filtering
st.sidebar.header("Please Filter Here:")
city = st.sidebar.multiselect(
    "Select the City:",
    options=df["City"].unique(),
    default=df["City"].unique()
)
customer_type = st.sidebar.multiselect(
    "Select the Customer Type:",
    options=df["Customer_type"].unique(),
    default=df["Customer_type"].unique(),
)
gender = st.sidebar.multiselect(
    "Select the Gender:",
    options=df["Gender"].unique(),
    default=df["Gender"].unique()
)
df_selection = df.query(
    "City == @city &amp;amp; Customer_type == @customer_type &amp;amp; Gender == @gender"
)

# Data verification
if df_selection.empty:
    st.warning("No data available based on the current filter settings!")
    st.stop()

# Main page
st.title(":bar_chart: Sales Dashboard")
st.markdown("##")

# Key Performance Indicators (KPIs)
total_sales = int(df_selection["Total"].sum())
average_rating = round(df_selection["Rating"].mean(), 1)
star_rating = ":star:" * int(round(average_rating, 0))
average_sale_by_transaction = round(df_selection["Total"].mean(), 2)

left_column, middle_column, right_column = st.columns(3)
with left_column:
    st.subheader("Total Sales:")
    st.subheader(f"US $ {total_sales:,}")
with middle_column:
    st.subheader("Average Rating:")
    st.subheader(f"{average_rating} {star_rating}")
with right_column:
    st.subheader("Average Sales Per Transaction:")
    st.subheader(f"US $ {average_sale_by_transaction}")

st.markdown("""---""")

# Sales by hour [Bar chart]
sales_by_hour = df_selection.groupby(by=["hour"])[["Total"]].sum()
fig_hourly_sales = px.bar(
    sales_by_hour,
    x=sales_by_hour.index,
    y="Total",
    title="&amp;lt;b&amp;gt;Sales by Hour&amp;lt;/b&amp;gt;",
    color_discrete_sequence=px.colors.qualitative.Bold,
    template="plotly_white",
)
fig_hourly_sales.update_layout(
    xaxis=dict(tickmode="linear"),
    plot_bgcolor="rgba(0,0,0,0)",
    yaxis=(dict(showgrid=False)),
)

# Sales by product line [Pie chart]
sales_by_product_line = df_selection.groupby(by=["Product line"])[["Total"]].sum().sort_values(by="Total")
fig_product_sales_pie = px.pie(
    sales_by_product_line,
    names=sales_by_product_line.index,
    values="Total",
    title="&amp;lt;b&amp;gt;Sales by Product Line&amp;lt;/b&amp;gt;",
    color_discrete_sequence=px.colors.qualitative.Set3,
    template="plotly_white",
)

# Sales by product line [Second bar chart]
fig_product_sales_bar = px.bar(
    sales_by_product_line,
    x=sales_by_product_line.index,
    y="Total",
    title="&amp;lt;b&amp;gt;Sales by Product Line&amp;lt;/b&amp;gt;",
    color_discrete_sequence=px.colors.qualitative.Bold,
    template="plotly_white",
)
fig_product_sales_bar.update_layout(
    plot_bgcolor="rgba(0,0,0,0)",
    xaxis=(dict(showgrid=False))
)

# New chart: Sales by day [Line chart]
sales_by_day = df_selection.groupby(by=pd.Grouper(freq='D', key='Date'))[['Total']].sum()
fig_daily_sales = px.line(
    sales_by_day,
    x=sales_by_day.index,
    y="Total",
    title="&amp;lt;b&amp;gt;Sales by Day&amp;lt;/b&amp;gt;",
    color_discrete_sequence=px.colors.qualitative.Light24,
    template="plotly_white",
)

# New chart: Price distribution [Histogram]
fig_price_distribution = px.histogram(
    df_selection,
    x="Unit price",
    title="&amp;lt;b&amp;gt;Price Distribution&amp;lt;/b&amp;gt;",
    color_discrete_sequence=px.colors.qualitative.Bold,
    template="plotly_white",
)

# New chart: Relationship between price and quantity [Scatter plot]
fig_price_quantity_scatter = px.scatter(
    df_selection,
    x="Unit price",
    y="Quantity",
    title="&amp;lt;b&amp;gt;Price vs. Quantity&amp;lt;/b&amp;gt;",
    color_discrete_sequence=px.colors.qualitative.Light24,
    template="plotly_white",
)

# Display the charts
left_column, middle_column, right_column = st.columns(3)
left_column.plotly_chart(fig_hourly_sales, use_container_width=True)
middle_column.plotly_chart(fig_product_sales_bar, use_container_width=True)
right_column.plotly_chart(fig_product_sales_pie, use_container_width=True)

st.markdown("""---""")

left_column, middle_column, right_column = st.columns(3)
left_column.plotly_chart(fig_daily_sales, use_container_width=True)
middle_column.plotly_chart(fig_price_distribution, use_container_width=True)
right_column.plotly_chart(fig_price_quantity_scatter, use_container_width=True)

# Hide Streamlit's style
hide_st_style = """
            &amp;lt;style&amp;gt;
            #MainMenu {visibility: hidden;}
            footer {visibility: hidden;}
            header {visibility: hidden;}
            &amp;lt;/style&amp;gt;
            """
st.markdown(hide_st_style, unsafe_allow_html=True)


&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;TRANSFER CHANGES FROM LOCAL REPOSITORY TO REMOTE REPOSITORY&lt;/strong&gt;&lt;br&gt;
We need the URL of the repository on GitHub &lt;br&gt;
• To obtain it, go to GitHub &lt;br&gt;
• Access Repositories &lt;br&gt;
• Select the Code button &lt;br&gt;
• Click on HTTPS &lt;br&gt;
• Copy the URL to the clipboard: &lt;a href="https://github.com/2020068765/Streamlit.git"&gt;https://github.com/2020068765/Streamlit.git&lt;/a&gt;&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;From our machine, we locate ourselves in our directory where we created our app.py and write these lines in the console.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;&lt;strong&gt;DEPLOY DASHBOARD WITH STREAMLIT COMMUNITY CLOUD&lt;/strong&gt;&lt;br&gt;
Streamlit Cloud account: To deploy our dashboard with Streamlit, it is necessary to create an account in Streamlit Community Cloud. Click on Get Started to begin the process. During the registration process, it is essential to link our GitHub account, where our repository ready for deployment is hosted.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fx8u20w2eitlmsaqym5uw.JPG" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fx8u20w2eitlmsaqym5uw.JPG" alt="Image description" width="800" height="404"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://ejemplotarea.streamlit.app"&gt;https://ejemplotarea.streamlit.app&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Conclusions:&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;The use of Streamlit and Python allows for rapid and efficient development of an interactive data panel.&lt;/li&gt;
&lt;li&gt;The resulting panel provides a clear and understandable presentation of key information, facilitating informed decision-making.&lt;/li&gt;
&lt;li&gt;Integration with Streamlit Community Cloud simplifies panel sharing through an accessible online link.&lt;/li&gt;
&lt;/ul&gt;

</description>
      <category>python</category>
      <category>development</category>
      <category>streamlit</category>
    </item>
  </channel>
</rss>
