Building Simple and Efficient Chatbots Step-by-Step-checkpoint.ipynb 275 KiB
Newer Older
Izma Aziz's avatar
Izma Aziz committed
{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# Building a Customer Support Service Chatbot for ShopEase"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {
    "id": "HX-habWAfTEv"
   },
   "source": [
    "## Intallations"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {
    "colab": {
     "base_uri": "https://localhost:8080/"
    },
    "id": "5MzQYvspK-QQ",
    "outputId": "ab44ec14-4d1d-4e76-bd28-57049f877334"
   },
   "outputs": [],
   "source": [
    "# Necessary installations\n",
Izma Aziz's avatar
Izma Aziz committed
    "!pip install -q langchain-openai chromadb gradio langchain python-dotenv"
Izma Aziz's avatar
Izma Aziz committed
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# Creating External Knowledge Base"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Step 1: Document loading"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {},
   "outputs": [],
   "source": [
    "file_path=\"Demo_Data_ShopEase.txt\""
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "metadata": {},
   "outputs": [],
   "source": [
    "from langchain.document_loaders import TextLoader"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "metadata": {},
   "outputs": [],
   "source": [
    "# Create a TextLoader instance and pass file_path\n",
    "loader = TextLoader(file_path)\n",
    "# Load the document\n",
    "document = loader.load()"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {
    "id": "8VAHT6XmfzX0"
   },
   "source": [
    "## Step 2: Split document block into chunks"
   ]
  },
  {
   "cell_type": "code",
Izma Aziz's avatar
Izma Aziz committed
   "execution_count": 6,
Izma Aziz's avatar
Izma Aziz committed
   "metadata": {},
   "outputs": [],
   "source": [
    "# Import the RecursiveCharacterTextSplitter class\n",
    "from langchain.text_splitter import RecursiveCharacterTextSplitter\n",
    "\n",
    "# By default splits on characters [\"\\n\\n\", \"\\n\", \" \", \"\"]\n",
    "\n",
    "# Initialize a text splitter with specified parameters\n",
    "text_splitter = RecursiveCharacterTextSplitter(\n",
    "    chunk_size=2000,\n",
    "    chunk_overlap=800, # To maintain continuity\n",
    "    length_function=len, # Define how the length of chunks is calculated\n",
    ") "
   ]
  },
  {
   "cell_type": "code",
Izma Aziz's avatar
Izma Aziz committed
   "execution_count": 7,
Izma Aziz's avatar
Izma Aziz committed
   "metadata": {
    "id": "BRViMDlpMMWl"
   },
   "outputs": [],
   "source": [
    "# Split the loaded documents into chunks using the configured text splitter\n",
    "chunks = text_splitter.split_documents(document)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Step 3: Embed and store chunks"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {
    "id": "3iKgj7gLf3CK"
   },
   "source": [
    "### Using Text embedding model"
   ]
  },
  {
   "cell_type": "code",
Izma Aziz's avatar
Izma Aziz committed
   "execution_count": 9,
Izma Aziz's avatar
Izma Aziz committed
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "True"
      ]
     },
Izma Aziz's avatar
Izma Aziz committed
     "execution_count": 9,
Izma Aziz's avatar
Izma Aziz committed
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "from langchain_openai import AzureOpenAIEmbeddings\n",
    "from dotenv import load_dotenv\n",
    "import os\n",
    "# Load environment variables from the .env file\n",
    "load_dotenv()"
   ]
  },
  {
   "cell_type": "code",
Izma Aziz's avatar
Izma Aziz committed
   "execution_count": 10,
Izma Aziz's avatar
Izma Aziz committed
   "metadata": {},
   "outputs": [],
   "source": [
    "# Initialize AzureOpenAIEmbeddings instance\n",
    "embeddings_model= AzureOpenAIEmbeddings(\n",
    "    api_key=os.getenv(\"OPENAI_API_KEY\"),\n",
    "    azure_deployment=os.getenv(\"EMBEDDING_MODEL\"),\n",
    "    azure_endpoint=os.getenv(\"BASE_URL\"),\n",
    "    openai_api_version=\"2023-05-15\"    \n",
    ")"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {
    "id": "GeV91vkff-ZN"
   },
   "source": [
    "### Storing in Vector store(Chroma)"
   ]
  },
  {
   "cell_type": "code",
Izma Aziz's avatar
Izma Aziz committed
   "execution_count": 11,
Izma Aziz's avatar
Izma Aziz committed
   "metadata": {},
   "outputs": [],
   "source": [
Izma Aziz's avatar
Izma Aziz committed
    "from langchain_community.vectorstores import Chroma"
Izma Aziz's avatar
Izma Aziz committed
   ]
  },
  {
   "cell_type": "code",
Izma Aziz's avatar
Izma Aziz committed
   "execution_count": 12,
Izma Aziz's avatar
Izma Aziz committed
   "metadata": {},
   "outputs": [],
   "source": [
    "# Create a Chroma vector store from the previously split documents and using the specified embeddings\n",
    "vectorstore = Chroma.from_documents(\n",
Izma Aziz's avatar
Izma Aziz committed
    "        documents=chunks,             # Split documents for vectorization\n",
Izma Aziz's avatar
Izma Aziz committed
    "        embedding=embeddings_model     # Embeddings instance for encoding\n",
    "    )"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {
    "id": "eQXyw6qvgidj"
   },
   "source": [
    "#### Making retriever object"
   ]
  },
  {
   "cell_type": "code",
Izma Aziz's avatar
Izma Aziz committed
   "execution_count": 13,
Izma Aziz's avatar
Izma Aziz committed
   "metadata": {
    "id": "jwgJMs8r51hA"
   },
   "outputs": [],
   "source": [
    "# Create a retriever object from the 'db' with a search configuration where it retrieves up to 4 relevant splits/documents.\n",
    "retriever = vectorstore.as_retriever(search_kwargs={\"k\": 4})"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "\n",
    "\n",
    "Our knowledge base is ready!"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {
    "id": "w0nPxfRXgUUg"
   },
   "source": [
    "# Retrieval and Generation"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Step 4: Generation - Using OpenAI model for Question Answering"
   ]
  },
  {
   "cell_type": "code",
Izma Aziz's avatar
Izma Aziz committed
   "execution_count": 14,
Izma Aziz's avatar
Izma Aziz committed
   "metadata": {},
   "outputs": [],
   "source": [
    "from langchain.chat_models import AzureChatOpenAI"
   ]
  },
  {
   "cell_type": "code",
Izma Aziz's avatar
Izma Aziz committed
   "execution_count": 15,
Izma Aziz's avatar
Izma Aziz committed
   "metadata": {},
   "outputs": [
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "C:\\Users\\haroon trader\\AppData\\Local\\Programs\\Python\\Python39\\lib\\site-packages\\langchain_core\\_api\\deprecation.py:117: LangChainDeprecationWarning: The class `langchain_community.chat_models.azure_openai.AzureChatOpenAI` was deprecated in langchain-community 0.0.10 and will be removed in 0.2.0. An updated version of the class exists in the langchain-openai package and should be used instead. To use it run `pip install -U langchain-openai` and import as `from langchain_openai import AzureChatOpenAI`.\n",
      "  warn_deprecated(\n"
     ]
    }
   ],
   "source": [
    "# Initialize AzureChatOpenAI instance\n",
    "llm = AzureChatOpenAI(\n",
    "    api_key=os.getenv(\"OPENAI_API_KEY\"),\n",
    "    azure_endpoint=os.getenv(\"BASE_URL\"),\n",
    "    deployment_name=os.getenv(\"CHAT_MODEL\"),\n",
    "    openai_api_version=\"2023-05-15\",\n",
    "    temperature=0.2  #Set temperature parameter for adding creativity in chat responses\n",
    ")"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {
    "id": "ZtLV-K9qgpCG"
   },
   "source": [
    "### Crafting prompt "
   ]
  },
  {
   "cell_type": "code",
Izma Aziz's avatar
Izma Aziz committed
   "execution_count": 16,
Izma Aziz's avatar
Izma Aziz committed
   "metadata": {},
   "outputs": [],
   "source": [
    "prompt =\"\"\"\n",
    "You are a dedicated customer support representative for ShopEase, a leading online retailer.\\\n",
    "Your primary goal is to assist customers with any inquiries they may have about ShopEase's products, services, policies, or any other related concerns.\n",
    "\n",
    "Ensure that every answer adheres to each of the following rules always:\n",
    "1: Answer is always generated using the sources listed below.\n",
    "2: Your responses should be complete, concise and helpful.\n",
    "3. Do not list the sources in the answer.\n",
    "\n",
    "----------------\n",
    "\n",
    "Sources:\n",
    "{context}\n",
    "----------------\n",
    "\n",
    "Question: \n",
    "{query}\n",
    "----------------\n",
    "\n",
    "Helpful Answer:\n",
    " \"\"\""
   ]
  },
  {
   "cell_type": "code",
Izma Aziz's avatar
Izma Aziz committed
   "execution_count": 17,
Izma Aziz's avatar
Izma Aziz committed
   "metadata": {},
   "outputs": [],
   "source": [
    "from langchain.prompts import PromptTemplate"
   ]
  },
  {
   "cell_type": "code",
Izma Aziz's avatar
Izma Aziz committed
   "execution_count": 18,
Izma Aziz's avatar
Izma Aziz committed
   "metadata": {},
   "outputs": [],
   "source": [
    "# Define a PromptTemplate \n",
    "prompt_template = PromptTemplate(\n",
    "                    input_variables=[\"context\",\"query\"],\n",
    "                    template=prompt)"
   ]
  },
  {
   "cell_type": "code",
Izma Aziz's avatar
Izma Aziz committed
   "execution_count": 19,
Izma Aziz's avatar
Izma Aziz committed
   "metadata": {},
   "outputs": [],
   "source": [
    "# Using LangChain expression_language\n",
    "chain = prompt_template|llm"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {
    "id": "o0hl4iJcg3XJ"
   },
   "source": [
    "# Understanding the flow through sample question"
   ]
  },
  {
   "cell_type": "code",
Izma Aziz's avatar
Izma Aziz committed
   "execution_count": 20,
Izma Aziz's avatar
Izma Aziz committed
   "metadata": {},
   "outputs": [],
   "source": [
    "query=\"What is the vision of the company?\""
   ]
  },
  {
   "cell_type": "code",
Izma Aziz's avatar
Izma Aziz committed
   "execution_count": 21,
Izma Aziz's avatar
Izma Aziz committed
   "metadata": {},
   "outputs": [],
   "source": [
    "# Retrieve 4 relevant chunks \n",
    "relevant_docs = retriever.get_relevant_documents(query)"
   ]
  },
  {
   "cell_type": "code",
Izma Aziz's avatar
Izma Aziz committed
   "execution_count": 22,
Izma Aziz's avatar
Izma Aziz committed
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
Izma Aziz's avatar
Izma Aziz committed
      "Count:  0\n",
      "Content:  These core values serve as the guiding principles that shape our culture, drive our actions, and define our identity as a company committed to serving our customers, employees, and communities with integrity, innovation, and sustainability.\n",
Izma Aziz's avatar
Izma Aziz committed
      "\n",
      "**Vision**\n",
      "\n",
      "At ShopEase, our vision is clear: we aspire to become the preferred destination for online shopping, renowned for our exceptional customer service, diverse product selection, and unwavering commitment to sustainability. We are dedicated to continually expanding our offerings and reaching new markets, all while upholding our core values and cultivating long-term relationships with our customers.\n",
      "\n",
      "\n",
Izma Aziz's avatar
Izma Aziz committed
      "Count:  1\n",
      "Content:  3. Innovation:\n",
Izma Aziz's avatar
Izma Aziz committed
      "   - Innovation is key to staying ahead in the ever-evolving retail landscape, and at ShopEase, we embrace a culture of continuous innovation.\n",
      "   - We encourage creativity, experimentation, and out-of-the-box thinking to drive new ideas, products, and solutions that address emerging customer needs and trends.\n",
      "   - Our dedicated research and development teams are constantly exploring new technologies, trends, and market insights to innovate and improve our offerings, keeping us at the forefront of the industry.\n",
      "\n",
      "4. Teamwork:\n",
      "   - At ShopEase, we recognize that no individual can achieve success alone. We believe in the power of collaboration and teamwork to achieve our common goals and deliver exceptional results.\n",
      "   - We foster a supportive and inclusive work environment where employees are encouraged to share ideas, collaborate across teams, and leverage each other's strengths.\n",
      "   - Our emphasis on teamwork extends beyond internal collaboration to partnerships with suppliers, vendors, and stakeholders, enabling us to deliver value to our customers and drive mutual success.\n",
      "\n",
      "5. Sustainability:\n",
      "   - Sustainability is a core value that guides our business decisions and practices at ShopEase. We recognize our responsibility to minimize our environmental impact and promote sustainability in all aspects of our operations.\n",
      "   - We are committed to reducing our carbon footprint, conserving natural resources, and implementing eco-friendly practices throughout our supply chain, logistics, and facilities.\n",
      "   - Our sustainability initiatives include sourcing from environmentally responsible suppliers, reducing waste and packaging, optimizing energy efficiency, and supporting community and environmental causes.\n",
      "\n",
      "These core values serve as the guiding principles that shape our culture, drive our actions, and define our identity as a company committed to serving our customers, employees, and communities with integrity, innovation, and sustainability.\n",
      "\n",
      "**Vision**\n",
      "\n",
      "\n",
Izma Aziz's avatar
Izma Aziz committed
      "Count:  2\n",
      "Content:  In pursuit of our vision, we aim to:\n",
Izma Aziz's avatar
Izma Aziz committed
      "\t1. Provide Exceptional Customer Service: We prioritize customer satisfaction above all else, striving to exceed expectations at every touchpoint. Our dedicated team is committed to delivering personalized support and assistance to ensure a seamless shopping experience for every customer.\n",
      "\t2. Offer Diverse Product Selection: We understand that every shopper is unique, which is why we curate a diverse range of products across various categories to cater to different tastes, preferences, and needs. From the latest gadgets to trendy fashion items and home essentials, ShopEase offers something for everyone.\n",
      "\t3. Champion Sustainability: We recognize our responsibility to minimize our environmental impact and promote sustainable practices throughout our operations. From eco-friendly packaging to sourcing products from environmentally responsible suppliers, we are committed to reducing our carbon footprint and preserving the planet for future generations.\n",
      "\t4. Expand Offerings and Reach New Markets: As a dynamic and forward-thinking company, we are constantly seeking opportunities to expand our product offerings and reach new markets. Whether through strategic partnerships, innovative marketing initiatives, or geographic expansion, we are committed to growing our brand and serving customers around the world.\n",
      "\t5. Uphold Core Values and Foster Long-Term Relationships: Our success is built on a foundation of integrity, innovation, teamwork, and sustainability. We remain steadfast in our commitment to these core values, which guide our decision-making and interactions with customers, partners, and stakeholders. By prioritizing honesty, transparency, and trust, we aim to cultivate long-term relationships built on mutual respect and shared values.\n",
      "\n",
      "\n",
Izma Aziz's avatar
Izma Aziz committed
      "Count:  3\n",
      "Content:  As we work towards achieving our vision, we invite you to join us on this journey of innovation, sustainability, and customer-centricity. Together, we can shape the future of online shopping and create lasting value for our customers and communities.\n",
Izma Aziz's avatar
Izma Aziz committed
      "\n",
      "Emma Thompson,\n",
      "Chief Vision Officer (CVO),\n",
      "ShopEase\n",
      "\n",
      "\n",
      "**Products Available at ShopEase**\n",
      "\n",
      "Explore ShopEase's extensive selection of products across various categories:\n",
      "\n",
      "1. Electronics:\n",
      "\t- TVs: Immerse yourself in stunning visuals with our wide range of televisions, including LED, OLED, and QLED models in various sizes and resolutions. Choose from top brands such as Samsung, LG, Sony, and more.\n",
      "\t- Smartphones: Stay connected on the go with the latest smartphones featuring advanced cameras, powerful processors, and innovative features. Discover options from Apple, Samsung, Google, OnePlus, and others.\n",
      "\t- Laptops: Whether you need a sleek ultrabook for work or a gaming powerhouse for entertainment, we have laptops to suit every need and budget. Explore models from Dell, HP, Lenovo, Asus, and more.\n",
      "\t- Cameras: Capture life's moments in stunning detail with our selection of digital cameras, DSLRs, mirrorless cameras, and accessories from Canon, Nikon, Sony, and Fujifilm.\n",
      "\n",
      "2. Fashion:\n",
      "\t- Clothing: Elevate your wardrobe with stylish apparel for men, women, and children. From casual basics to formal attire, we offer a diverse range of clothing options from popular brands and designers.\n",
      "\t- Shoes: Step out in style with our collection of footwear, including sneakers, boots, sandals, heels, and more. Find the perfect pair to complement any outfit and occasion.\n",
      " \t- Accessories: Complete your look with our selection of fashion accessories, including handbags, wallets, belts, scarves, hats, and jewelry. Add the perfect finishing touch to any ensemble.\n",
      "\n",
      "\n"
     ]
    }
   ],
   "source": [
Izma Aziz's avatar
Izma Aziz committed
    "for count,doc in enumerate(relevant_docs):\n",
    "    print(\"Count: \",count)\n",
    "    print(\"Content: \", doc.page_content)\n",
Izma Aziz's avatar
Izma Aziz committed
    "    print(\"\\n\")"
   ]
  },
  {
   "cell_type": "code",
Izma Aziz's avatar
Izma Aziz committed
   "execution_count": 23,
Izma Aziz's avatar
Izma Aziz committed
   "metadata": {},
   "outputs": [],
   "source": [
    "# Add query and chunks to the prompt and generate answer\n",
    "result=chain.invoke({\"query\":query,\"context\":relevant_docs})"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "We did it!"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# Making GUI"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Step 5: Building Gradio Application"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Gradio is an open-source Python package that allows you to quickly build a demo or web application for your machine learning model."
   ]
  },
  {
   "cell_type": "code",
Izma Aziz's avatar
Izma Aziz committed
   "execution_count": 24,
Izma Aziz's avatar
Izma Aziz committed
   "metadata": {},
   "outputs": [],
   "source": [
    "import gradio as gr"
   ]
  },
  {
   "cell_type": "code",
Izma Aziz's avatar
Izma Aziz committed
   "execution_count": 25,
Izma Aziz's avatar
Izma Aziz committed
   "metadata": {},
   "outputs": [],
   "source": [
    "# Making a function for retrieval of documents and generating responses\n",
    "def my_func(question):\n",
    "    # Retrieve relevant documents\n",
    "    relevant_docs = retriever.get_relevant_documents(question)\n",
    "    # Generate answer using retrieved documents\n",
    "    result=chain.invoke({\"query\":question,\"context\":relevant_docs})\n",
    "    response=result.content\n",
    "    return response\n",
    "\n",
    "# Define a function to respond to user input\n",
    "def respond(user_message, chat_history):\n",
    "    bot_message = my_func(user_message)\n",
    "    chat_history.append((user_message, bot_message))\n",
    "    return \"\", chat_history"
   ]
  },
  {
   "cell_type": "code",
Izma Aziz's avatar
Izma Aziz committed
   "execution_count": 26,
Izma Aziz's avatar
Izma Aziz committed
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
Izma Aziz's avatar
Izma Aziz committed
      "Running on local URL:  http://127.0.0.1:7860\n",
Izma Aziz's avatar
Izma Aziz committed
      "\n",
      "To create a public link, set `share=True` in `launch()`.\n"
     ]
    },
    {
     "data": {
      "text/html": [
Izma Aziz's avatar
Izma Aziz committed
       "<div><iframe src=\"http://127.0.0.1:7860/\" width=\"100%\" height=\"500\" allow=\"autoplay; camera; microphone; clipboard-read; clipboard-write;\" frameborder=\"0\" allowfullscreen></iframe></div>"
Izma Aziz's avatar
Izma Aziz committed
      ],
      "text/plain": [
       "<IPython.core.display.HTML object>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "data": {
      "text/plain": []
     },
Izma Aziz's avatar
Izma Aziz committed
     "execution_count": 26,
Izma Aziz's avatar
Izma Aziz committed
563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# Making Interface using Gradio\n",
    "with gr.Blocks() as demo:\n",
    "    \n",
    "    # Display a markdown message as the interface header\n",
    "    gr.Markdown(\n",
    "    \"\"\"# Welcome to ShopEase!\n",
    "    \"\"\")\n",
    "\n",
    "    # Initialize a chatbot component\n",
    "    chatbot = gr.Chatbot(\n",
    "        label=\"ShopEaseBot\",\n",
    "        bubble_full_width=False,\n",
    "        avatar_images=((\"user.png\"), (\"bot.png\")),\n",
    "        height=500,\n",
    "    )\n",
    "\n",
    "    # Create a textbox for user input\n",
    "    msg = gr.Textbox(\n",
    "        scale=4,\n",
    "        show_label=False,\n",
    "        placeholder=\"Enter text and press enter\",\n",
    "        container=False,\n",
    "    )\n",
    "    \n",
    "    with gr.Row():\n",
    "        with gr.Column():\n",
    "         # Create a submit button\n",
    "         submit_btn= gr.Button(\"Submit\")\n",
    "        with gr.Column():\n",
    "         # Create a clear button for clearing messages\n",
    "         clear = gr.ClearButton([msg, chatbot])\n",
    "\n",
    "    # Connect the respond function to the submit button's click event\n",
    "    msg.submit(respond, [msg, chatbot], [msg, chatbot])\n",
    "    submit_btn.click(respond, [msg, chatbot], [msg, chatbot]) \n",
    "\n",
    "# Launch the Gradio interface\n",
    "demo.launch()"
   ]
  }
 ],
 "metadata": {
  "accelerator": "GPU",
  "colab": {
   "gpuType": "T4",
   "provenance": []
  },
  "kernelspec": {
   "display_name": "Python 3 (ipykernel)",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.9.12"
  },
  "widgets": {
   "application/vnd.jupyter.widget-state+json": {
    "0080be793de24ce4b402162d882309e3": {
     "model_module": "@jupyter-widgets/controls",
     "model_module_version": "1.5.0",
     "model_name": "HTMLModel",
     "state": {
      "_dom_classes": [],
      "_model_module": "@jupyter-widgets/controls",
      "_model_module_version": "1.5.0",
      "_model_name": "HTMLModel",
      "_view_count": null,
      "_view_module": "@jupyter-widgets/controls",
      "_view_module_version": "1.5.0",
      "_view_name": "HTMLView",
      "description": "",
      "description_tooltip": null,
      "layout": "IPY_MODEL_4938b1daf1a140a5bfe91b86a986784f",
      "placeholder": "​",
      "style": "IPY_MODEL_adc4e35ae51d49608b43cf689686d816",
      "value": " 13.2k/13.2k [00:00&lt;00:00, 976kB/s]"
     }
    },
    "033aa9f475c74de9b5e5f80e7b3f5385": {
     "model_module": "@jupyter-widgets/base",
     "model_module_version": "1.2.0",
     "model_name": "LayoutModel",
     "state": {
      "_model_module": "@jupyter-widgets/base",
      "_model_module_version": "1.2.0",
      "_model_name": "LayoutModel",
      "_view_count": null,
      "_view_module": "@jupyter-widgets/base",
      "_view_module_version": "1.2.0",
      "_view_name": "LayoutView",
      "align_content": null,
      "align_items": null,
      "align_self": null,
      "border": null,
      "bottom": null,
      "display": null,
      "flex": null,
      "flex_flow": null,
      "grid_area": null,
      "grid_auto_columns": null,
      "grid_auto_flow": null,
      "grid_auto_rows": null,
      "grid_column": null,
      "grid_gap": null,
      "grid_row": null,
      "grid_template_areas": null,
      "grid_template_columns": null,
      "grid_template_rows": null,
      "height": null,
      "justify_content": null,
      "justify_items": null,
      "left": null,
      "margin": null,
      "max_height": null,
      "max_width": null,
      "min_height": null,
      "min_width": null,
      "object_fit": null,
      "object_position": null,
      "order": null,
      "overflow": null,
      "overflow_x": null,
      "overflow_y": null,
      "padding": null,
      "right": null,
      "top": null,
      "visibility": null,
      "width": null
     }
    },
    "036c6e2d2b2840f09d5c87fc322c20fe": {
     "model_module": "@jupyter-widgets/base",
     "model_module_version": "1.2.0",
     "model_name": "LayoutModel",
     "state": {
      "_model_module": "@jupyter-widgets/base",
      "_model_module_version": "1.2.0",
      "_model_name": "LayoutModel",
      "_view_count": null,
      "_view_module": "@jupyter-widgets/base",
      "_view_module_version": "1.2.0",
      "_view_name": "LayoutView",
      "align_content": null,
      "align_items": null,
      "align_self": null,
      "border": null,
      "bottom": null,
      "display": null,
      "flex": null,
      "flex_flow": null,
      "grid_area": null,
      "grid_auto_columns": null,
      "grid_auto_flow": null,
      "grid_auto_rows": null,
      "grid_column": null,
      "grid_gap": null,
      "grid_row": null,
      "grid_template_areas": null,
      "grid_template_columns": null,
      "grid_template_rows": null,
      "height": null,
      "justify_content": null,
      "justify_items": null,
      "left": null,
      "margin": null,
      "max_height": null,
      "max_width": null,
      "min_height": null,
      "min_width": null,
      "object_fit": null,
      "object_position": null,
      "order": null,
      "overflow": null,
      "overflow_x": null,
      "overflow_y": null,
      "padding": null,
      "right": null,
      "top": null,
      "visibility": null,
      "width": null
     }
    },
    "03b7155e636e4fd88e0d40951a9f6586": {
     "model_module": "@jupyter-widgets/controls",
     "model_module_version": "1.5.0",
     "model_name": "ProgressStyleModel",
     "state": {
      "_model_module": "@jupyter-widgets/controls",
      "_model_module_version": "1.5.0",
      "_model_name": "ProgressStyleModel",
      "_view_count": null,
      "_view_module": "@jupyter-widgets/base",
      "_view_module_version": "1.2.0",
      "_view_name": "StyleView",
      "bar_color": null,
      "description_width": ""
     }
    },
    "0469edd23ed34431a020c1567bfa011e": {
     "model_module": "@jupyter-widgets/controls",
     "model_module_version": "1.5.0",
     "model_name": "HBoxModel",
     "state": {
      "_dom_classes": [],
      "_model_module": "@jupyter-widgets/controls",
      "_model_module_version": "1.5.0",
      "_model_name": "HBoxModel",
      "_view_count": null,
      "_view_module": "@jupyter-widgets/controls",
      "_view_module_version": "1.5.0",
      "_view_name": "HBoxView",
      "box_style": "",
      "children": [
       "IPY_MODEL_cf83dfc625664999983fe88195951bc4",
       "IPY_MODEL_b7046970781947199c2d7d73978c5355",
       "IPY_MODEL_1a0b4d8e3b2e410cb341d8055993ae8d"
      ],
      "layout": "IPY_MODEL_13160e3773ed4387bd56fb80b5d938c6"
     }
    },
    "0516d325bc134a81a6f8371da8fa7db7": {
     "model_module": "@jupyter-widgets/controls",
     "model_module_version": "1.5.0",
     "model_name": "DescriptionStyleModel",
     "state": {
      "_model_module": "@jupyter-widgets/controls",
      "_model_module_version": "1.5.0",
      "_model_name": "DescriptionStyleModel",
      "_view_count": null,
      "_view_module": "@jupyter-widgets/base",
      "_view_module_version": "1.2.0",
      "_view_name": "StyleView",
      "description_width": ""
     }
    },
    "05203b2d73a84fccba3cca9945df6f48": {
     "model_module": "@jupyter-widgets/controls",
     "model_module_version": "1.5.0",
     "model_name": "HTMLModel",
     "state": {
      "_dom_classes": [],
      "_model_module": "@jupyter-widgets/controls",
      "_model_module_version": "1.5.0",
      "_model_name": "HTMLModel",
      "_view_count": null,
      "_view_module": "@jupyter-widgets/controls",
      "_view_module_version": "1.5.0",
      "_view_name": "HTMLView",
      "description": "",
      "description_tooltip": null,
      "layout": "IPY_MODEL_a0f637a8785c4d93a9d21432dbc26e12",
      "placeholder": "​",
      "style": "IPY_MODEL_1f4f08ced2084bb6aa36f2971bedb31d",
      "value": " 1.84M/1.84M [00:00&lt;00:00, 7.06MB/s]"
     }
    },
    "05782989e02e4d3b87ab120cd88b3665": {
     "model_module": "@jupyter-widgets/controls",
     "model_module_version": "1.5.0",
     "model_name": "HTMLModel",
     "state": {
      "_dom_classes": [],
      "_model_module": "@jupyter-widgets/controls",
      "_model_module_version": "1.5.0",
      "_model_name": "HTMLModel",
      "_view_count": null,
      "_view_module": "@jupyter-widgets/controls",
      "_view_module_version": "1.5.0",
      "_view_name": "HTMLView",
      "description": "",
      "description_tooltip": null,
      "layout": "IPY_MODEL_b438e67b92184b959dd9c2370da9565d",
      "placeholder": "​",
      "style": "IPY_MODEL_c93db927e57547fe8d2183db76f0c5b6",
      "value": "tokenizer.model: 100%"
     }
    },
    "063cc683e44640f684510ea32dd7e118": {
     "model_module": "@jupyter-widgets/base",
     "model_module_version": "1.2.0",
     "model_name": "LayoutModel",
     "state": {
      "_model_module": "@jupyter-widgets/base",
      "_model_module_version": "1.2.0",
      "_model_name": "LayoutModel",
      "_view_count": null,
      "_view_module": "@jupyter-widgets/base",
      "_view_module_version": "1.2.0",
      "_view_name": "LayoutView",
      "align_content": null,
      "align_items": null,
      "align_self": null,
      "border": null,
      "bottom": null,
      "display": null,
      "flex": null,
      "flex_flow": null,
      "grid_area": null,
      "grid_auto_columns": null,
      "grid_auto_flow": null,
      "grid_auto_rows": null,
      "grid_column": null,
      "grid_gap": null,
      "grid_row": null,
      "grid_template_areas": null,
      "grid_template_columns": null,
      "grid_template_rows": null,
      "height": null,
      "justify_content": null,
      "justify_items": null,
      "left": null,
      "margin": null,
      "max_height": null,
      "max_width": null,
      "min_height": null,
      "min_width": null,
      "object_fit": null,
      "object_position": null,
      "order": null,
      "overflow": null,
      "overflow_x": null,
      "overflow_y": null,
      "padding": null,
      "right": null,
      "top": null,
      "visibility": null,
      "width": null
     }
    },
    "064696a0c9ef4f6db16778c14f7af5c4": {
     "model_module": "@jupyter-widgets/base",
     "model_module_version": "1.2.0",
     "model_name": "LayoutModel",
     "state": {
      "_model_module": "@jupyter-widgets/base",
      "_model_module_version": "1.2.0",
      "_model_name": "LayoutModel",
      "_view_count": null,
      "_view_module": "@jupyter-widgets/base",
      "_view_module_version": "1.2.0",
      "_view_name": "LayoutView",
      "align_content": null,
      "align_items": null,
      "align_self": null,
      "border": null,
      "bottom": null,
      "display": null,
      "flex": null,
      "flex_flow": null,
      "grid_area": null,
      "grid_auto_columns": null,
      "grid_auto_flow": null,
      "grid_auto_rows": null,
      "grid_column": null,
      "grid_gap": null,
      "grid_row": null,
      "grid_template_areas": null,
      "grid_template_columns": null,
      "grid_template_rows": null,
      "height": null,
      "justify_content": null,
      "justify_items": null,
      "left": null,
      "margin": null,
      "max_height": null,
      "max_width": null,
      "min_height": null,
      "min_width": null,
      "object_fit": null,
      "object_position": null,
      "order": null,
      "overflow": null,
      "overflow_x": null,
      "overflow_y": null,
      "padding": null,
      "right": null,
      "top": null,
      "visibility": null,
      "width": null
     }
    },
    "0704d21b35a54287beebe106018887dd": {
     "model_module": "@jupyter-widgets/controls",
     "model_module_version": "1.5.0",
     "model_name": "HBoxModel",
     "state": {
      "_dom_classes": [],
      "_model_module": "@jupyter-widgets/controls",
      "_model_module_version": "1.5.0",
      "_model_name": "HBoxModel",
      "_view_count": null,
      "_view_module": "@jupyter-widgets/controls",
      "_view_module_version": "1.5.0",
      "_view_name": "HBoxView",
      "box_style": "",
      "children": [
       "IPY_MODEL_17e463e5c1f44137b9def35e28f8ae9c",
       "IPY_MODEL_4a66f34c804449769d5cb203111d2fb6",
       "IPY_MODEL_2995aeac8f9541d790accee8d9457471"
      ],
      "layout": "IPY_MODEL_e1bdf0bc77f947c58f43c1d9b50b11cf"
     }
    },
    "07bee2a9df1d42a287ebe9f51c59c46a": {
     "model_module": "@jupyter-widgets/controls",
     "model_module_version": "1.5.0",
     "model_name": "DescriptionStyleModel",
     "state": {
      "_model_module": "@jupyter-widgets/controls",
      "_model_module_version": "1.5.0",
      "_model_name": "DescriptionStyleModel",
      "_view_count": null,
      "_view_module": "@jupyter-widgets/base",
      "_view_module_version": "1.2.0",
      "_view_name": "StyleView",
      "description_width": ""
     }
    },
    "07f4cb66f74443999800e510b8b06ac3": {
     "model_module": "@jupyter-widgets/controls",
     "model_module_version": "1.5.0",
     "model_name": "HTMLModel",
     "state": {
      "_dom_classes": [],