{ "cells": [ { "cell_type": "code", "execution_count": 1, "metadata": { "id": "ylbT549oymIl" }, "outputs": [ { "name": "stderr", "output_type": "stream", "text": [ "/home/vasim/Khatir/Programming/ML Projects/gemini-pro with docs/.venv/lib/python3.10/site-packages/tqdm/auto.py:21: TqdmWarning: IProgress not found. Please update jupyter and ipywidgets. See https://ipywidgets.readthedocs.io/en/stable/user_install.html\n", " from .autonotebook import tqdm as notebook_tqdm\n" ] }, { "data": { "text/plain": [ "True" ] }, "execution_count": 1, "metadata": {}, "output_type": "execute_result" } ], "source": [ "import os\n", "from langchain.document_loaders import (\n", " PyPDFLoader,\n", " TextLoader,\n", " Docx2txtLoader\n", ")\n", "\n", "from langchain.text_splitter import CharacterTextSplitter\n", "# from PyPDF2 import PdfReader\n", "from langchain.text_splitter import RecursiveCharacterTextSplitter\n", "from langchain_google_genai import GoogleGenerativeAIEmbeddings\n", "import google.generativeai as genai\n", "from langchain.vectorstores import FAISS\n", "from langchain_google_genai import ChatGoogleGenerativeAI\n", "from langchain.chains.question_answering import load_qa_chain\n", "from langchain.prompts import PromptTemplate\n", "from langchain.memory import ConversationBufferMemory\n", "from dotenv import load_dotenv\n", "load_dotenv()" ] }, { "cell_type": "code", "execution_count": 2, "metadata": {}, "outputs": [], "source": [ "os.chdir(\"../\")" ] }, { "cell_type": "code", "execution_count": 3, "metadata": {}, "outputs": [], "source": [ "from src.utils import (\n", " process_files, answer_query, extract_text_from_file\n", ")" ] }, { "cell_type": "code", "execution_count": 8, "metadata": { "colab": { "background_save": true }, "id": "a8tNUutJB9EA" }, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "Running on local URL: http://127.0.0.1:7862\n", "\n", "To create a public link, set `share=True` in `launch()`.\n" ] }, { "data": { "text/html": [ "
" ], "text/plain": [ "" ] }, "metadata": {}, "output_type": "display_data" }, { "name": "stdout", "output_type": "stream", "text": [ "Text extracted\n", "Chunks splitted\n", "Document search created\n" ] }, { "name": "stderr", "output_type": "stream", "text": [ "/home/vasim/Khatir/Programming/ML Projects/gemini-pro with docs/.venv/lib/python3.10/site-packages/langchain_core/_api/deprecation.py:117: LangChainDeprecationWarning: The function `__call__` was deprecated in LangChain 0.1.0 and will be removed in 0.2.0. Use invoke instead.\n", " warn_deprecated(\n" ] } ], "source": [ "# Gradio App\n", "import gradio as gr\n", "\n", "gr.close_all()\n", "\n", "title = \"\"\n", "description = f\"Chat with any docs\"\n", "\n", "# def answer_query(message, history):\n", "# docs = db.similarity_search(message)\n", "# message = agent(\n", "# {\"input_documents\":docs, \"question\": message}\n", "# ,return_only_outputs=True)\n", "# return message['output_text']\n", "\n", "\n", "chatbot = gr.Chatbot(label=\"ExploreText\")\n", "\n", "with gr.Blocks(\n", " title=\"ExploreText\",\n", " ) as textbot:\n", "\n", " gr.Markdown(\"#
Welcome to ExploreDoc Web App
\")\n", " \n", " with gr.Accordion(\"Upload a file here\", open=False):\n", " file_output = gr.File()\n", " upload_button = gr.UploadButton(\"Click to Upload a File\", file_types=[\"txt\",\"doc\",\"pdf\"])\n", " upload_button.upload(process_files, upload_button, file_output)\n", "\n", " # with gr.Row(\"Chat with Text\"):\n", " gr.ChatInterface(fn=answer_query, chatbot=chatbot, submit_btn=\"Ask\", undo_btn=None, retry_btn=None, clear_btn=None)\n", " gr.Markdown(\"
Developed by Mohammed Vasim | AI Engineer & Computer Vision Engineer @ ZestIoT.
\")\n", " \n", "\n", "if __name__ == \"__main__\":\n", " textbot.queue().launch()\n", "\n" ] }, { "cell_type": "markdown", "metadata": {}, "source": [] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [] } ], "metadata": { "colab": { "provenance": [] }, "kernelspec": { "display_name": "Python 3", "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.10.12" } }, "nbformat": 4, "nbformat_minor": 0 }