DEV Community

Cover image for MotivateMe: Empowering Daily Quotes - Your Personal Streamlit Chatbot
arjun
arjun

Posted on

MotivateMe: Empowering Daily Quotes - Your Personal Streamlit Chatbot

Empower Your Day with MotivateMe: A Streamlit Chatbot for Daily Motivation

In a world brimming with distractions and challenges, finding moments of inspiration can be a game-changer. Whether you're striving towards personal goals, navigating professional endeavors, or simply seeking a boost of positivity, having access to motivational quotes can make all the difference. Enter MotivateMe – a Streamlit-powered chatbot designed to infuse your day with inspiration and encouragement.

How Does MotivateMe Work?
Navigating MotivateMe is a breeze. With a sleek and intuitive interface, users can simply open the chatbot in their web browser and receive a fresh dose of motivation with just a few clicks. Whether you're looking for a quick pick-me-up or a dose of long-term inspiration, MotivateMe has you covered.

Technical Breakdown

  1. Importing Libraries
    We start by importing the necessary libraries. streamlit is used for building the web application, and requests is used to make HTTP requests to the API that provides the motivational quotes.

  2. Defining the fetch_motivational_quote Function
    This function sends a GET request to the ZenQuotes API to fetch a random motivational quote. If the request is successful (status code 200), it extracts the quote from the response JSON and returns it. Otherwise, it displays an error message.

  3. Defining the main Function
    The main function is the entry point of the Streamlit application. It sets the title of the web page and displays a message prompting the user to click a button to generate a motivational quote.

  4. Generating a Motivational Quote
    When the user clicks the "Generate Quote" button, the fetch_motivational_quote function is called to fetch a random motivational quote. If successful, the quote is displayed on the page in a success message. If there is an error fetching the quote, an error message is displayed instead.

  5. Running the Application
    The main function is executed if the script is run directly (name == "main"), launching the Streamlit web application.

import streamlit as st
import requests

def fetch_motivational_quote():
    url = "https://zenquotes.io/api/random"
    try:
        response = requests.get(url)
        if response.status_code == 200:
            data = response.json()
            quote = data[0]['q'] + " -" + data[0]['a']
            return quote
        else:
            st.error(f"Failed to fetch quote. Status code: {response.status_code}")
    except Exception as e:
        st.error(f"An error occurred: {e}")

def main():
    st.title("MotivateMe: Your Daily Dose of Inspiration")
    st.write("Click below to get your daily motivational quote.")

    if st.button("Generate Quote"):
        motivational_quote = fetch_motivational_quote()
        if motivational_quote:
            st.success("Here's a motivational quote for you:")
            st.write(motivational_quote)
        else:
            st.error("Failed to fetch a motivational quote.")

if __name__ == "__main__":
    main()

Enter fullscreen mode Exit fullscreen mode

Deployment on Streamlit
Streamlit is an open-source Python library that allows developers to create web applications quickly and easily. With Streamlit, developers can build interactive data-driven applications using familiar Python syntax, without the need for extensive web development experience. Streamlit simplifies the process of creating web apps by providing a high-level API that handles many common tasks, such as layout design, data visualization, and user interaction. It's particularly popular among data scientists and machine learning engineers for building prototype dashboards, sharing research findings, and creating interactive demos.

To deploy this Streamlit application, follow these steps:

Save the script as a Python file (e.g., motivateme.py).
Install Streamlit using pip install streamlit.
Run the Streamlit app using the command streamlit run motivateme.py.
Share the URL provided by Streamlit to allow others to access the application.
With these steps, users can access the MotivateMe web app and receive their daily dose of inspiration with just a click of a button.

Image description

Just click "deploy," and voila! Start deploying, and then it can be used by sharing the URL link with anyone.

Here, I am sharing the link to my chatbot.
https://quotemotivate-vghu6cgqq9ruc8luuxnrsp.streamlit.app/

Conclusion
In conclusion, this article has provided a comprehensive overview of deploying a Python chatbot on Streamlit, a powerful framework for building interactive web applications. By leveraging Streamlit's intuitive interface and Pythonic syntax, developers can quickly transform their code into engaging and user-friendly web apps without the need for extensive web development experience. Through the step-by-step technical breakdown and deployment instructions, readers have gained insights into seamlessly integrating their chatbot functionality into Streamlit, empowering them to share their projects with a wider audience and enhance user engagement. With Streamlit, the possibilities for creating dynamic and interactive web applications are limitless, making it an invaluable tool for developers seeking to bring their Python projects to life on the web.

Top comments (1)

Collapse
 
shadowruge profile image
izaias

Very good 🌹