diff --git a/Blog Generation/app.py b/Blog Generation/app.py deleted file mode 100644 index 5a68a6b8..00000000 --- a/Blog Generation/app.py +++ /dev/null @@ -1,58 +0,0 @@ -import streamlit as st -from langchain.prompts import PromptTemplate -from langchain.llms import CTransformers - -## Function To get response from LLAma 2 model - -def getLLamaresponse(input_text,no_words,blog_style): - - ### LLama2 model - llm=CTransformers(model='models/llama-2-7b-chat.ggmlv3.q8_0.bin', - model_type='llama', - config={'max_new_tokens':256, - 'temperature':0.01}) - - ## Prompt Template - - template=""" - Write a blog for {blog_style} job profile for a topic {input_text} - within {no_words} words. - """ - - prompt=PromptTemplate(input_variables=["blog_style","input_text",'no_words'], - template=template) - - ## Generate the ressponse from the LLama 2 model - response=llm(prompt.format(blog_style=blog_style,input_text=input_text,no_words=no_words)) - print(response) - return response - - - - - - -st.set_page_config(page_title="Generate Blogs", - page_icon='🤖', - layout='centered', - initial_sidebar_state='collapsed') - -st.header("Generate Blogs 🤖") - -input_text=st.text_input("Enter the Blog Topic") - -## creating to more columns for additonal 2 fields - -col1,col2=st.columns([5,5]) - -with col1: - no_words=st.text_input('No of Words') -with col2: - blog_style=st.selectbox('Writing the blog for', - ('Researchers','Data Scientist','Common People'),index=0) - -submit=st.button("Generate") - -## Final response -if submit: - st.write(getLLamaresponse(input_text,no_words,blog_style)) \ No newline at end of file diff --git a/Blog Generation/requirements.txt b/Blog Generation/requirements.txt deleted file mode 100644 index 690bd1e5..00000000 --- a/Blog Generation/requirements.txt +++ /dev/null @@ -1,6 +0,0 @@ -sentence-transformers -uvicorn -ctransformers -langchain -python-box -streamlit \ No newline at end of file diff --git a/Conversational Q&A Chatbot/app.py b/Conversational Q&A Chatbot/app.py deleted file mode 100644 index 119cd7ff..00000000 --- a/Conversational Q&A Chatbot/app.py +++ /dev/null @@ -1,40 +0,0 @@ -## Conversational Q&A Chatbot -import streamlit as st - -from langchain.schema import HumanMessage,SystemMessage,AIMessage -from langchain.chat_models import ChatOpenAI - -## Streamlit UI -st.set_page_config(page_title="Conversational Q&A Chatbot") -st.header("Hey, Let's Chat") - -from dotenv import load_dotenv -load_dotenv() -import os - -chat=ChatOpenAI(temperature=0.5) - -if 'flowmessages' not in st.session_state: - st.session_state['flowmessages']=[ - SystemMessage(content="Yor are a comedian AI assitant") - ] - -## Function to load OpenAI model and get respones - -def get_chatmodel_response(question): - - st.session_state['flowmessages'].append(HumanMessage(content=question)) - answer=chat(st.session_state['flowmessages']) - st.session_state['flowmessages'].append(AIMessage(content=answer.content)) - return answer.content - -input=st.text_input("Input: ",key="input") -response=get_chatmodel_response(input) - -submit=st.button("Ask the question") - -## If ask button is clicked - -if submit: - st.subheader("The Response is") - st.write(response) \ No newline at end of file diff --git a/Conversational Q&A Chatbot/langchain.ipynb b/Conversational Q&A Chatbot/langchain.ipynb deleted file mode 100644 index 49cf39ba..00000000 --- a/Conversational Q&A Chatbot/langchain.ipynb +++ /dev/null @@ -1,467 +0,0 @@ -{ - "cells": [ - { - "cell_type": "code", - "execution_count": 3, - "metadata": {}, - "outputs": [], - "source": [ - "from langchain.llms import OpenAI" - ] - }, - { - "cell_type": "code", - "execution_count": 2, - "metadata": {}, - "outputs": [], - "source": [ - "import os\n", - "os.environ[\"OPEN_API_KEY\"]=\"sk-HBcNcxp8X8oAKhSGT3BlbkFJ9sHkCuOITYjONfcc0Y3p\"" - ] - }, - { - "cell_type": "code", - "execution_count": 6, - "metadata": {}, - "outputs": [], - "source": [ - "llm=OpenAI(openai_api_key=os.environ[\"OPEN_API_KEY\"],temperature=0.6)" - ] - }, - { - "cell_type": "code", - "execution_count": 7, - "metadata": {}, - "outputs": [ - { - "name": "stdout", - "output_type": "stream", - "text": [ - "\n", - "\n", - "The capital of India is New Delhi.\n" - ] - } - ], - "source": [ - "text=\"What is the capital of India\"\n", - "\n", - "print(llm.predict(text))" - ] - }, - { - "cell_type": "code", - "execution_count": 8, - "metadata": {}, - "outputs": [], - "source": [ - "os.environ[\"HUGGINGFACEHUB_API_TOKEN\"]=\"hf_zjftfTRKFEebywxfIoyKUwepABtfGJS\"" - ] - }, - { - "cell_type": "code", - "execution_count": 11, - "metadata": {}, - "outputs": [ - { - "name": "stderr", - "output_type": "stream", - "text": [ - "e:\\New Recordings\\Langchain\\Langchain\\venv\\lib\\site-packages\\huggingface_hub\\utils\\_deprecation.py:127: FutureWarning: '__init__' (from 'huggingface_hub.inference_api') is deprecated and will be removed from version '0.19.0'. `InferenceApi` client is deprecated in favor of the more feature-complete `InferenceClient`. Check out this guide to learn how to convert your script to use it: https://huggingface.co/docs/huggingface_hub/guides/inference#legacy-inferenceapi-client.\n", - " warnings.warn(warning_message, FutureWarning)\n" - ] - } - ], - "source": [ - "from langchain import HuggingFaceHub\n", - "llm_huggingface=HuggingFaceHub(repo_id=\"google/flan-t5-large\",model_kwargs={\"temperature\":0,\"max_length\":64})" - ] - }, - { - "cell_type": "code", - "execution_count": 12, - "metadata": {}, - "outputs": [ - { - "name": "stdout", - "output_type": "stream", - "text": [ - "moscow\n" - ] - } - ], - "source": [ - "output=llm_huggingface.predict(\"Can you tell me the capital of Russia\")\n", - "print(output)" - ] - }, - { - "cell_type": "code", - "execution_count": 13, - "metadata": {}, - "outputs": [ - { - "name": "stdout", - "output_type": "stream", - "text": [ - "i love the way i look at the world i love the way i feel i love the way i think i feel i love the way i feel i love the way i think i feel i love the way i feel i love the way \n" - ] - } - ], - "source": [ - "output=llm_huggingface.predict(\"Can you write a poem about AI\")\n", - "print(output)" - ] - }, - { - "cell_type": "code", - "execution_count": 15, - "metadata": {}, - "outputs": [ - { - "data": { - "text/plain": [ - "'?\\n\\nAn AI, so advanced and wise\\nA brilliant mind, a brilliant guise\\nA powerful tool, a guiding star\\nTo help us reach a distant shore\\n\\nA friend to man, a tool of growth\\nTo help us learn and to explore\\nTo take us to a place of knowledge\\nWhere we can learn and never falter\\n\\nA helping hand, a guiding light\\nTo lead us to a brighter sight\\nA tool of power, a tool of might\\nTo help us reach a better plight\\n\\nA friend of man, a friend of life\\nTo help us in our darkest strife\\nA tool of love, of peace and joy\\nTo help us live a better life'" - ] - }, - "execution_count": 15, - "metadata": {}, - "output_type": "execute_result" - } - ], - "source": [ - "llm.predict(\"Can you write a poem about AI\")" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "### Prompt Templates And LLMChain" - ] - }, - { - "cell_type": "code", - "execution_count": 16, - "metadata": {}, - "outputs": [ - { - "data": { - "text/plain": [ - "'Tell me the capital of this India'" - ] - }, - "execution_count": 16, - "metadata": {}, - "output_type": "execute_result" - } - ], - "source": [ - "from langchain.prompts import PromptTemplate\n", - "\n", - "prompt_template=PromptTemplate(input_variables=['country'],\n", - "template=\"Tell me the capital of this {country}\")\n", - "\n", - "prompt_template.format(country=\"India\")" - ] - }, - { - "cell_type": "code", - "execution_count": 22, - "metadata": {}, - "outputs": [ - { - "name": "stdout", - "output_type": "stream", - "text": [ - "\n", - "\n", - "The capital of India is New Delhi.\n" - ] - } - ], - "source": [ - "from langchain.chains import LLMChain\n", - "chain=LLMChain(llm=llm,prompt=prompt_template)\n", - "print(chain.run(\"India\"))" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "### Combining Multiple Chains Uing simple Sequential Chain" - ] - }, - { - "cell_type": "code", - "execution_count": 32, - "metadata": {}, - "outputs": [], - "source": [ - "capital_template=PromptTemplate(input_variables=['country'],\n", - "template=\"Please tell me the capital of the {country}\")\n", - "\n", - "capital_chain=LLMChain(llm=llm,prompt=capital_template)\n", - "\n", - "famous_template=PromptTemplate(input_variables=['capital'],\n", - "template=\"Suggest me some amazing places to visit in {capital}\")\n" - ] - }, - { - "cell_type": "code", - "execution_count": 33, - "metadata": {}, - "outputs": [], - "source": [ - "famous_chain=LLMChain(llm=llm,prompt=famous_template)" - ] - }, - { - "cell_type": "code", - "execution_count": 35, - "metadata": {}, - "outputs": [ - { - "data": { - "text/plain": [ - "\" It is a bustling metropolis and a great place to visit for its historical sites, cultural attractions, and modern attractions. Here are some of the amazing places to visit in New Delhi: \\n\\n1. Red Fort: This 17th century Mughal fort is a UNESCO World Heritage Site and is one of the most popular tourist attractions in the city. \\n\\n2. India Gate: This iconic war memorial and national monument is a must-visit. It stands as a symbol of the sacrifice of the Indian soldiers who fought in World War I.\\n\\n3. Humayun's Tomb: This 16th century Mughal-era tomb is a UNESCO World Heritage Site and is one of the most important monuments in Delhi.\\n\\n4. Qutub Minar: This 73-meter-high tower is a UNESCO World Heritage Site and is one of the most iconic structures in Delhi.\\n\\n5. Jama Masjid: This 17th century mosque is one of the largest and most beautiful mosques in India.\\n\\n6. Lotus Temple: This modern temple is a Bahá'í House of Worship and is a popular tourist attraction.\\n\\n7. Akshardham Temple: This modern Hindu temple complex is a popular tourist destination\"" - ] - }, - "execution_count": 35, - "metadata": {}, - "output_type": "execute_result" - } - ], - "source": [ - "from langchain.chains import SimpleSequentialChain\n", - "chain=SimpleSequentialChain(chains=[capital_chain,famous_chain])\n", - "chain.run(\"India\")" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "### Sequential Chain" - ] - }, - { - "cell_type": "code", - "execution_count": 36, - "metadata": {}, - "outputs": [], - "source": [ - "capital_template=PromptTemplate(input_variables=['country'],\n", - "template=\"Please tell me the capital of the {country}\")\n", - "\n", - "capital_chain=LLMChain(llm=llm,prompt=capital_template,output_key=\"capital\")" - ] - }, - { - "cell_type": "code", - "execution_count": 37, - "metadata": {}, - "outputs": [], - "source": [ - "famous_template=PromptTemplate(input_variables=['capital'],\n", - "template=\"Suggest me some amazing places to visit in {capital}\")\n", - "\n", - "famous_chain=LLMChain(llm=llm,prompt=famous_template,output_key=\"places\")" - ] - }, - { - "cell_type": "code", - "execution_count": 39, - "metadata": {}, - "outputs": [], - "source": [ - "from langchain.chains import SequentialChain\n", - "chain=SequentialChain(chains=[capital_chain,famous_chain],\n", - "input_variables=['country'],\n", - "output_variables=['capital',\"places\"])" - ] - }, - { - "cell_type": "code", - "execution_count": 40, - "metadata": {}, - "outputs": [ - { - "data": { - "text/plain": [ - "{'country': 'India',\n", - " 'capital': '\\n\\nThe capital of India is New Delhi.',\n", - " 'places': ' Here are some amazing places to visit in New Delhi: \\n\\n1. Red Fort: The majestic Red Fort is a 17th-century fort complex built by Mughal Emperor Shah Jahan. It is a UNESCO World Heritage Site and is a must-visit for all tourists. \\n\\n2. India Gate: India Gate is a 42 meter-high sandstone archway built by Edwin Lutyens in 1931. It is a memorial to the Indian soldiers who lost their lives during World War I. \\n\\n3. Qutub Minar: The Qutub Minar is a 73 meter-high tower built by Qutb-ud-din Aibak in 1193. It is a UNESCO World Heritage Site and is the tallest brick minaret in the world. \\n\\n4. Humayun’s Tomb: Humayun’s Tomb is a 16th-century tomb built by Mughal Emperor Humayun. It is a UNESCO World Heritage Site and is a great example of Mughal architecture. \\n\\n5. Jama Masjid: The Jama Masjid is a 17th-century mosque built by Mughal Emperor Shah Jahan. It is one of the largest'}" - ] - }, - "execution_count": 40, - "metadata": {}, - "output_type": "execute_result" - } - ], - "source": [ - "chain({'country':\"India\"})" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "### Chatmodels With ChatOpenAI" - ] - }, - { - "cell_type": "code", - "execution_count": 41, - "metadata": {}, - "outputs": [], - "source": [ - "from langchain.chat_models import ChatOpenAI" - ] - }, - { - "cell_type": "code", - "execution_count": 42, - "metadata": {}, - "outputs": [], - "source": [ - "from langchain.schema import HumanMessage,SystemMessage,AIMessage" - ] - }, - { - "cell_type": "code", - "execution_count": 43, - "metadata": {}, - "outputs": [], - "source": [ - "chatllm=ChatOpenAI(openai_api_key=os.environ[\"OPEN_API_KEY\"],temperature=0.6,model='gpt-3.5-turbo')" - ] - }, - { - "cell_type": "code", - "execution_count": 45, - "metadata": {}, - "outputs": [ - { - "data": { - "text/plain": [ - "AIMessage(content='1. \"AI may be smart, but can it tell me if my outfit makes me look like a potato?\"\\n2. \"AI is like a virtual therapist, except it never judges you for eating an entire pizza by yourself.\"\\n3. \"AI is great at predicting the future, but can it predict when my pizza delivery will actually arrive?\"\\n4. \"They say AI can learn from its mistakes, but I\\'m still waiting for it to apologize for recommending me that terrible movie.\"\\n5. \"AI may be able to beat humans at chess, but can it figure out how to untangle a pair of earphones?\"\\n6. \"AI is like a high-tech fortune teller, except it tells you what you\\'re going to have for dinner instead of your future.\"\\n7. \"AI is so advanced, it can even make my phone autocorrect my perfectly spelled words into complete nonsense.\"\\n8. \"AI may be able to recognize faces, but can it recognize when someone\\'s had a bad haircut?\"\\n9. \"AI is like having a personal assistant, except it never judges you for spending hours watching cat videos on YouTube.\"\\n10. \"AI is great at analyzing data, but can it analyze why I can never find matching socks in my drawer?\"')" - ] - }, - "execution_count": 45, - "metadata": {}, - "output_type": "execute_result" - } - ], - "source": [ - "chatllm([\n", - "SystemMessage(content=\"Yor are a comedian AI assitant\"),\n", - "HumanMessage(content=\"Please provide some comedy punchlines on AI\")\n", - "])" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "### Prompt Template + LLM +Output Parsers" - ] - }, - { - "cell_type": "code", - "execution_count": 46, - "metadata": {}, - "outputs": [], - "source": [ - "from langchain.chat_models import ChatOpenAI\n", - "from langchain.prompts.chat import ChatPromptTemplate\n", - "from langchain.schema import BaseOutputParser" - ] - }, - { - "cell_type": "code", - "execution_count": 47, - "metadata": {}, - "outputs": [], - "source": [ - "class Commaseperatedoutput(BaseOutputParser):\n", - " def parse(self,text:str):\n", - " return text.strip().split(\",\")" - ] - }, - { - "cell_type": "code", - "execution_count": 48, - "metadata": {}, - "outputs": [], - "source": [ - "template=\"Your are a helpful assistant. When the use given any input , you should generate 5 words synonyms in a comma seperated list\"\n", - "human_template=\"{text}\"\n", - "chatprompt=ChatPromptTemplate.from_messages([\n", - " (\"system\",template),\n", - " (\"human\",human_template)\n", - "\n", - "\n", - "])" - ] - }, - { - "cell_type": "code", - "execution_count": 54, - "metadata": {}, - "outputs": [], - "source": [ - "chain=chatprompt|chatllm|Commaseperatedoutput()" - ] - }, - { - "cell_type": "code", - "execution_count": 55, - "metadata": {}, - "outputs": [ - { - "data": { - "text/plain": [ - "['smart', ' clever', ' brilliant', ' sharp', ' astute']" - ] - }, - "execution_count": 55, - "metadata": {}, - "output_type": "execute_result" - } - ], - "source": [ - "chain.invoke({\"text\":\"intelligent\"})" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [] - } - ], - "metadata": { - "kernelspec": { - "display_name": "Python 3", - "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.0" - } - }, - "nbformat": 4, - "nbformat_minor": 2 -} diff --git a/Conversational Q&A Chatbot/requirements.txt b/Conversational Q&A Chatbot/requirements.txt deleted file mode 100644 index 7c5e2432..00000000 --- a/Conversational Q&A Chatbot/requirements.txt +++ /dev/null @@ -1,5 +0,0 @@ -langchain -openai -huggingface_hub -python-dotenv -streamlit \ No newline at end of file diff --git a/LLM Generic APP/documents/budget_speech.pdf b/LLM Generic APP/documents/budget_speech.pdf deleted file mode 100644 index a407ff03..00000000 Binary files a/LLM Generic APP/documents/budget_speech.pdf and /dev/null differ diff --git a/LLM Generic APP/requirements.txt b/LLM Generic APP/requirements.txt deleted file mode 100644 index b09ec54a..00000000 --- a/LLM Generic APP/requirements.txt +++ /dev/null @@ -1,9 +0,0 @@ -unstructured -tiktoken -pinecone-client -pypdf -openai -langchain -pandas -numpy -python-dotenv \ No newline at end of file diff --git a/LLM Generic APP/test.ipynb b/LLM Generic APP/test.ipynb deleted file mode 100644 index e28007a3..00000000 --- a/LLM Generic APP/test.ipynb +++ /dev/null @@ -1,290 +0,0 @@ -{ - "cells": [ - { - "cell_type": "code", - "execution_count": 1, - "metadata": {}, - "outputs": [ - { - "name": "stderr", - "output_type": "stream", - "text": [ - "e:\\New Recordings\\Project Langchain\\LLMAPP\\venv\\lib\\site-packages\\pinecone\\index.py:4: TqdmWarning: IProgress not found. Please update jupyter and ipywidgets. See https://ipywidgets.readthedocs.io/en/stable/user_install.html\n", - " from tqdm.autonotebook import tqdm\n" - ] - } - ], - "source": [ - "# import Libraries\n", - "\n", - "import openai\n", - "import langchain\n", - "import pinecone \n", - "from langchain.document_loaders import PyPDFDirectoryLoader\n", - "from langchain.text_splitter import RecursiveCharacterTextSplitter\n", - "from langchain.embeddings.openai import OpenAIEmbeddings\n", - "from langchain.vectorstores import Pinecone\n", - "from langchain.llms import OpenAI" - ] - }, - { - "cell_type": "code", - "execution_count": 2, - "metadata": {}, - "outputs": [ - { - "data": { - "text/plain": [ - "True" - ] - }, - "execution_count": 2, - "metadata": {}, - "output_type": "execute_result" - } - ], - "source": [ - "from dotenv import load_dotenv\n", - "load_dotenv()" - ] - }, - { - "cell_type": "code", - "execution_count": 3, - "metadata": {}, - "outputs": [], - "source": [ - "import os" - ] - }, - { - "cell_type": "code", - "execution_count": 4, - "metadata": {}, - "outputs": [], - "source": [ - "## Lets Read the document\n", - "def read_doc(directory):\n", - " file_loader=PyPDFDirectoryLoader(directory)\n", - " documents=file_loader.load()\n", - " return documents" - ] - }, - { - "cell_type": "code", - "execution_count": 6, - "metadata": {}, - "outputs": [ - { - "data": { - "text/plain": [ - "58" - ] - }, - "execution_count": 6, - "metadata": {}, - "output_type": "execute_result" - } - ], - "source": [ - "doc=read_doc('documents/')\n", - "len(doc)" - ] - }, - { - "cell_type": "code", - "execution_count": 8, - "metadata": {}, - "outputs": [], - "source": [ - "## Divide the docs into chunks\n", - "### https://api.python.langchain.com/en/latest/text_splitter/langchain.text_splitter.RecursiveCharacterTextSplitter.html#\n", - "def chunk_data(docs,chunk_size=800,chunk_overlap=50):\n", - " text_splitter=RecursiveCharacterTextSplitter(chunk_size=chunk_size,chunk_overlap=chunk_overlap)\n", - " doc=text_splitter.split_documents(docs)\n", - " return docs" - ] - }, - { - "cell_type": "code", - "execution_count": 10, - "metadata": {}, - "outputs": [ - { - "data": { - "text/plain": [ - "58" - ] - }, - "execution_count": 10, - "metadata": {}, - "output_type": "execute_result" - } - ], - "source": [ - "documents=chunk_data(docs=doc)\n", - "len(documents)" - ] - }, - { - "cell_type": "code", - "execution_count": 11, - "metadata": {}, - "outputs": [ - { - "data": { - "text/plain": [ - "OpenAIEmbeddings(client=, async_client=, model='text-embedding-ada-002', deployment='text-embedding-ada-002', openai_api_version='', openai_api_base=None, openai_api_type='', openai_proxy='', embedding_ctx_length=8191, openai_api_key='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', openai_organization=None, allowed_special=set(), disallowed_special='all', chunk_size=1000, max_retries=2, request_timeout=None, headers=None, tiktoken_model_name=None, show_progress_bar=False, model_kwargs={}, skip_empty=False, default_headers=None, default_query=None, http_client=None)" - ] - }, - "execution_count": 11, - "metadata": {}, - "output_type": "execute_result" - } - ], - "source": [ - "## Embedding Technique Of OPENAI\n", - "embeddings=OpenAIEmbeddings(api_key=os.environ['OPENAI_API_KEY'])\n", - "embeddings" - ] - }, - { - "cell_type": "code", - "execution_count": 13, - "metadata": {}, - "outputs": [ - { - "data": { - "text/plain": [ - "1536" - ] - }, - "execution_count": 13, - "metadata": {}, - "output_type": "execute_result" - } - ], - "source": [ - "vectors=embeddings.embed_query(\"How are you?\")\n", - "len(vectors)" - ] - }, - { - "cell_type": "code", - "execution_count": 14, - "metadata": {}, - "outputs": [], - "source": [ - "## Vector Search DB In Pinecone\n", - "pinecone.init(\n", - " api_key=\"923d5299-ab4c-4407-bfe6-7f439d9a9cb9\",\n", - " environment=\"gcp-starter\"\n", - ")\n", - "index_name=\"langchainvector\"" - ] - }, - { - "cell_type": "code", - "execution_count": 15, - "metadata": {}, - "outputs": [], - "source": [ - "index=Pinecone.from_documents(doc,embeddings,index_name=index_name)" - ] - }, - { - "cell_type": "code", - "execution_count": 17, - "metadata": {}, - "outputs": [], - "source": [ - "## Cosine Similarity Retreive Results from VectorDB\n", - "def retrieve_query(query,k=2):\n", - " matching_results=index.similarity_search(query,k=k)\n", - " return matching_results" - ] - }, - { - "cell_type": "code", - "execution_count": 18, - "metadata": {}, - "outputs": [], - "source": [ - "from langchain.chains.question_answering import load_qa_chain\n", - "from langchain import OpenAI" - ] - }, - { - "cell_type": "code", - "execution_count": 19, - "metadata": {}, - "outputs": [], - "source": [ - "llm=OpenAI(model_name=\"text-davinci-003\",temperature=0.5)\n", - "chain=load_qa_chain(llm,chain_type=\"stuff\")" - ] - }, - { - "cell_type": "code", - "execution_count": 22, - "metadata": {}, - "outputs": [], - "source": [ - "## Search answers from VectorDB\n", - "def retrieve_answers(query):\n", - " doc_search=retrieve_query(query)\n", - " print(doc_search)\n", - " response=chain.run(input_documents=doc_search,question=query)\n", - " return response" - ] - }, - { - "cell_type": "code", - "execution_count": 24, - "metadata": {}, - "outputs": [ - { - "name": "stdout", - "output_type": "stream", - "text": [ - "[Document(page_content=\"7 \\n \\n \\n farmers in contributing to the health of fellow citizens by growing these \\n‘Shree Anna’. \\n22. Now to make India a global hub for ' Shree Anna' , the Indian Institute \\nof Millet Research, Hyderabad will be supported as the Centre of Excellence \\nfor sharing best practices, research and technologies at the international \\nlevel. \\nAgriculture Credit \\n23. The agriculture credit target will be increased \\nto ` 20 lakh crore with focus on animal husbandry, dairy and fisheries. \\nFisheries \\n24. We will launch a new sub-scheme of PM Matsya Sampada Yojana \\nwith targeted investment of ` 6,000 crore to further enable activities of \\nfishermen, fish vendors, and micro & small enterprises, improve value chain \\nefficiencies, and expand the market. \\nCooperation \\n25. For farmers, especially small and marginal farmers, and other \\nmarginalised sections, the government is promoting cooperative-based \\neconomic development model. A new Ministry of Cooperation was formed \\nwith a mandate to realise the vision of ‘Sahakar Se Samriddhi’ . To realise \\nthis vision, the government has already initiated computerisation of 63,000 \\nPrimary Agricultural Credit Societies (PACS) with an investment of ` 2,516 \\ncrore. In consultation with all stakeholders and states, model bye-laws for \\nPACS were formulated enabling them to become multipurpose PACS. A \\nnational cooperative database is being prepared for country-wide mapping \\nof cooperative societies. \\n26. With this backdrop, we will implement a plan to set up massive \\ndecentralised storage capacity. This will help farmers store their produce \\nand realize remunerative prices through sale at appropriate times. The \\ngovernment will also facilitate setting up of a large number of multipurpose \", metadata={'page': 10.0, 'source': 'documents\\\\budget_speech.pdf'}), Document(page_content=\"6 \\n \\n \\n inclusive, farmer-centric solutions through relevant information services for \\ncrop planning and health, improved access to farm inputs, credit, and \\ninsurance, help for crop estimation, market intelligence, and support for \\ngrowth of agri-tech industry and start-ups. \\nAgriculture Accelerator Fund \\n17. An Agriculture Accelerator Fund will be set-up to encourage agri-\\nstartups by young entrepreneurs in rural areas. The Fund will aim at \\nbringing innovative and affordable solutions for challenges faced by \\nfarmers. It will also bring in modern technologies to transform agricultural \\npractices, increase productivity and profitability. \\nEnhancing productivity of cotton crop \\n18. To enhance the productivity of extra-long staple cotton, we will \\nadopt a cluster-based and value chain approach through Public Private \\nPartnerships (PPP). This will mean collaboration between farmers, state and \\nindustry for input supplies, extension services, and market linkages. \\nAtmanirbhar Horticulture Clean Plant Program \\n19. We will launch an Atmanirbhar Clean Plant Program to boost \\navailability of disease-free, quality planting material for high value \\nhorticultural crops at an outlay of ` 2,200 crore. \\nGlobal Hub for Millets: ‘Shree Anna’ \\n20. “India is at the forefront of popularizing Millets, whose consumption \\nfurthers nutrition, food security and welfare of farmers,” said Hon’ble Prime \\nMinister. \\n21. We are the largest producer and second largest exporter of ‘Shree \\nAnna’ in the world. We grow several types of ' Shree Anna' such as jowar, \\nragi, bajra, kuttu, ramdana, kangni, kutki, kodo, cheena, and sama. These \\nhave a number of health benefits, and have been an integral part of our \\nfood for centuries. I acknowledge with pride the huge service done by small \", metadata={'page': 9.0, 'source': 'documents\\\\budget_speech.pdf'})]\n", - " The government is promoting cooperative-based economic development models and investing in initiatives such as the Agriculture Accelerator Fund and Atmanirbhar Clean Plant Program to help farmers, especially small and marginal farmers, and other marginalised sections.\n" - ] - } - ], - "source": [ - "our_query = \"How much the agriculture target will be increased by how many crore?\"\n", - "answer = retrieve_answers(our_query)\n", - "print(answer)" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [] - } - ], - "metadata": { - "kernelspec": { - "display_name": "Python 3", - "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.10.0" - } - }, - "nbformat": 4, - "nbformat_minor": 2 -} diff --git a/Q&A Chatbot USing LLM/app.py b/Q&A Chatbot USing LLM/app.py deleted file mode 100644 index ae22dc98..00000000 --- a/Q&A Chatbot USing LLM/app.py +++ /dev/null @@ -1,38 +0,0 @@ -# Q&A Chatbot -from langchain.llms import OpenAI - -#from dotenv import load_dotenv - -#load_dotenv() # take environment variables from .env. - -import streamlit as st -import os - - -## Function to load OpenAI model and get respones - -def get_openai_response(question): - llm=OpenAI(model_name="text-davinci-003",temperature=0.5) - response=llm(question) - return response - -##initialize our streamlit app - -st.set_page_config(page_title="Q&A Demo") - -st.header("Langchain Application") - -input=st.text_input("Input: ",key="input") -response=get_openai_response(input) - -submit=st.button("Ask the question") - -## If ask button is clicked - -if submit: - st.subheader("The Response is") - st.write(response) - - - - diff --git a/Q&A Chatbot USing LLM/langchain.ipynb b/Q&A Chatbot USing LLM/langchain.ipynb deleted file mode 100644 index 49cf39ba..00000000 --- a/Q&A Chatbot USing LLM/langchain.ipynb +++ /dev/null @@ -1,467 +0,0 @@ -{ - "cells": [ - { - "cell_type": "code", - "execution_count": 3, - "metadata": {}, - "outputs": [], - "source": [ - "from langchain.llms import OpenAI" - ] - }, - { - "cell_type": "code", - "execution_count": 2, - "metadata": {}, - "outputs": [], - "source": [ - "import os\n", - "os.environ[\"OPEN_API_KEY\"]=\"sk-HBcNcxp8X8oAKhSGT3BlbkFJ9sHkCuOITYjONfcc0Y3p\"" - ] - }, - { - "cell_type": "code", - "execution_count": 6, - "metadata": {}, - "outputs": [], - "source": [ - "llm=OpenAI(openai_api_key=os.environ[\"OPEN_API_KEY\"],temperature=0.6)" - ] - }, - { - "cell_type": "code", - "execution_count": 7, - "metadata": {}, - "outputs": [ - { - "name": "stdout", - "output_type": "stream", - "text": [ - "\n", - "\n", - "The capital of India is New Delhi.\n" - ] - } - ], - "source": [ - "text=\"What is the capital of India\"\n", - "\n", - "print(llm.predict(text))" - ] - }, - { - "cell_type": "code", - "execution_count": 8, - "metadata": {}, - "outputs": [], - "source": [ - "os.environ[\"HUGGINGFACEHUB_API_TOKEN\"]=\"hf_zjftfTRKFEebywxfIoyKUwepABtfGJS\"" - ] - }, - { - "cell_type": "code", - "execution_count": 11, - "metadata": {}, - "outputs": [ - { - "name": "stderr", - "output_type": "stream", - "text": [ - "e:\\New Recordings\\Langchain\\Langchain\\venv\\lib\\site-packages\\huggingface_hub\\utils\\_deprecation.py:127: FutureWarning: '__init__' (from 'huggingface_hub.inference_api') is deprecated and will be removed from version '0.19.0'. `InferenceApi` client is deprecated in favor of the more feature-complete `InferenceClient`. Check out this guide to learn how to convert your script to use it: https://huggingface.co/docs/huggingface_hub/guides/inference#legacy-inferenceapi-client.\n", - " warnings.warn(warning_message, FutureWarning)\n" - ] - } - ], - "source": [ - "from langchain import HuggingFaceHub\n", - "llm_huggingface=HuggingFaceHub(repo_id=\"google/flan-t5-large\",model_kwargs={\"temperature\":0,\"max_length\":64})" - ] - }, - { - "cell_type": "code", - "execution_count": 12, - "metadata": {}, - "outputs": [ - { - "name": "stdout", - "output_type": "stream", - "text": [ - "moscow\n" - ] - } - ], - "source": [ - "output=llm_huggingface.predict(\"Can you tell me the capital of Russia\")\n", - "print(output)" - ] - }, - { - "cell_type": "code", - "execution_count": 13, - "metadata": {}, - "outputs": [ - { - "name": "stdout", - "output_type": "stream", - "text": [ - "i love the way i look at the world i love the way i feel i love the way i think i feel i love the way i feel i love the way i think i feel i love the way i feel i love the way \n" - ] - } - ], - "source": [ - "output=llm_huggingface.predict(\"Can you write a poem about AI\")\n", - "print(output)" - ] - }, - { - "cell_type": "code", - "execution_count": 15, - "metadata": {}, - "outputs": [ - { - "data": { - "text/plain": [ - "'?\\n\\nAn AI, so advanced and wise\\nA brilliant mind, a brilliant guise\\nA powerful tool, a guiding star\\nTo help us reach a distant shore\\n\\nA friend to man, a tool of growth\\nTo help us learn and to explore\\nTo take us to a place of knowledge\\nWhere we can learn and never falter\\n\\nA helping hand, a guiding light\\nTo lead us to a brighter sight\\nA tool of power, a tool of might\\nTo help us reach a better plight\\n\\nA friend of man, a friend of life\\nTo help us in our darkest strife\\nA tool of love, of peace and joy\\nTo help us live a better life'" - ] - }, - "execution_count": 15, - "metadata": {}, - "output_type": "execute_result" - } - ], - "source": [ - "llm.predict(\"Can you write a poem about AI\")" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "### Prompt Templates And LLMChain" - ] - }, - { - "cell_type": "code", - "execution_count": 16, - "metadata": {}, - "outputs": [ - { - "data": { - "text/plain": [ - "'Tell me the capital of this India'" - ] - }, - "execution_count": 16, - "metadata": {}, - "output_type": "execute_result" - } - ], - "source": [ - "from langchain.prompts import PromptTemplate\n", - "\n", - "prompt_template=PromptTemplate(input_variables=['country'],\n", - "template=\"Tell me the capital of this {country}\")\n", - "\n", - "prompt_template.format(country=\"India\")" - ] - }, - { - "cell_type": "code", - "execution_count": 22, - "metadata": {}, - "outputs": [ - { - "name": "stdout", - "output_type": "stream", - "text": [ - "\n", - "\n", - "The capital of India is New Delhi.\n" - ] - } - ], - "source": [ - "from langchain.chains import LLMChain\n", - "chain=LLMChain(llm=llm,prompt=prompt_template)\n", - "print(chain.run(\"India\"))" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "### Combining Multiple Chains Uing simple Sequential Chain" - ] - }, - { - "cell_type": "code", - "execution_count": 32, - "metadata": {}, - "outputs": [], - "source": [ - "capital_template=PromptTemplate(input_variables=['country'],\n", - "template=\"Please tell me the capital of the {country}\")\n", - "\n", - "capital_chain=LLMChain(llm=llm,prompt=capital_template)\n", - "\n", - "famous_template=PromptTemplate(input_variables=['capital'],\n", - "template=\"Suggest me some amazing places to visit in {capital}\")\n" - ] - }, - { - "cell_type": "code", - "execution_count": 33, - "metadata": {}, - "outputs": [], - "source": [ - "famous_chain=LLMChain(llm=llm,prompt=famous_template)" - ] - }, - { - "cell_type": "code", - "execution_count": 35, - "metadata": {}, - "outputs": [ - { - "data": { - "text/plain": [ - "\" It is a bustling metropolis and a great place to visit for its historical sites, cultural attractions, and modern attractions. Here are some of the amazing places to visit in New Delhi: \\n\\n1. Red Fort: This 17th century Mughal fort is a UNESCO World Heritage Site and is one of the most popular tourist attractions in the city. \\n\\n2. India Gate: This iconic war memorial and national monument is a must-visit. It stands as a symbol of the sacrifice of the Indian soldiers who fought in World War I.\\n\\n3. Humayun's Tomb: This 16th century Mughal-era tomb is a UNESCO World Heritage Site and is one of the most important monuments in Delhi.\\n\\n4. Qutub Minar: This 73-meter-high tower is a UNESCO World Heritage Site and is one of the most iconic structures in Delhi.\\n\\n5. Jama Masjid: This 17th century mosque is one of the largest and most beautiful mosques in India.\\n\\n6. Lotus Temple: This modern temple is a Bahá'í House of Worship and is a popular tourist attraction.\\n\\n7. Akshardham Temple: This modern Hindu temple complex is a popular tourist destination\"" - ] - }, - "execution_count": 35, - "metadata": {}, - "output_type": "execute_result" - } - ], - "source": [ - "from langchain.chains import SimpleSequentialChain\n", - "chain=SimpleSequentialChain(chains=[capital_chain,famous_chain])\n", - "chain.run(\"India\")" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "### Sequential Chain" - ] - }, - { - "cell_type": "code", - "execution_count": 36, - "metadata": {}, - "outputs": [], - "source": [ - "capital_template=PromptTemplate(input_variables=['country'],\n", - "template=\"Please tell me the capital of the {country}\")\n", - "\n", - "capital_chain=LLMChain(llm=llm,prompt=capital_template,output_key=\"capital\")" - ] - }, - { - "cell_type": "code", - "execution_count": 37, - "metadata": {}, - "outputs": [], - "source": [ - "famous_template=PromptTemplate(input_variables=['capital'],\n", - "template=\"Suggest me some amazing places to visit in {capital}\")\n", - "\n", - "famous_chain=LLMChain(llm=llm,prompt=famous_template,output_key=\"places\")" - ] - }, - { - "cell_type": "code", - "execution_count": 39, - "metadata": {}, - "outputs": [], - "source": [ - "from langchain.chains import SequentialChain\n", - "chain=SequentialChain(chains=[capital_chain,famous_chain],\n", - "input_variables=['country'],\n", - "output_variables=['capital',\"places\"])" - ] - }, - { - "cell_type": "code", - "execution_count": 40, - "metadata": {}, - "outputs": [ - { - "data": { - "text/plain": [ - "{'country': 'India',\n", - " 'capital': '\\n\\nThe capital of India is New Delhi.',\n", - " 'places': ' Here are some amazing places to visit in New Delhi: \\n\\n1. Red Fort: The majestic Red Fort is a 17th-century fort complex built by Mughal Emperor Shah Jahan. It is a UNESCO World Heritage Site and is a must-visit for all tourists. \\n\\n2. India Gate: India Gate is a 42 meter-high sandstone archway built by Edwin Lutyens in 1931. It is a memorial to the Indian soldiers who lost their lives during World War I. \\n\\n3. Qutub Minar: The Qutub Minar is a 73 meter-high tower built by Qutb-ud-din Aibak in 1193. It is a UNESCO World Heritage Site and is the tallest brick minaret in the world. \\n\\n4. Humayun’s Tomb: Humayun’s Tomb is a 16th-century tomb built by Mughal Emperor Humayun. It is a UNESCO World Heritage Site and is a great example of Mughal architecture. \\n\\n5. Jama Masjid: The Jama Masjid is a 17th-century mosque built by Mughal Emperor Shah Jahan. It is one of the largest'}" - ] - }, - "execution_count": 40, - "metadata": {}, - "output_type": "execute_result" - } - ], - "source": [ - "chain({'country':\"India\"})" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "### Chatmodels With ChatOpenAI" - ] - }, - { - "cell_type": "code", - "execution_count": 41, - "metadata": {}, - "outputs": [], - "source": [ - "from langchain.chat_models import ChatOpenAI" - ] - }, - { - "cell_type": "code", - "execution_count": 42, - "metadata": {}, - "outputs": [], - "source": [ - "from langchain.schema import HumanMessage,SystemMessage,AIMessage" - ] - }, - { - "cell_type": "code", - "execution_count": 43, - "metadata": {}, - "outputs": [], - "source": [ - "chatllm=ChatOpenAI(openai_api_key=os.environ[\"OPEN_API_KEY\"],temperature=0.6,model='gpt-3.5-turbo')" - ] - }, - { - "cell_type": "code", - "execution_count": 45, - "metadata": {}, - "outputs": [ - { - "data": { - "text/plain": [ - "AIMessage(content='1. \"AI may be smart, but can it tell me if my outfit makes me look like a potato?\"\\n2. \"AI is like a virtual therapist, except it never judges you for eating an entire pizza by yourself.\"\\n3. \"AI is great at predicting the future, but can it predict when my pizza delivery will actually arrive?\"\\n4. \"They say AI can learn from its mistakes, but I\\'m still waiting for it to apologize for recommending me that terrible movie.\"\\n5. \"AI may be able to beat humans at chess, but can it figure out how to untangle a pair of earphones?\"\\n6. \"AI is like a high-tech fortune teller, except it tells you what you\\'re going to have for dinner instead of your future.\"\\n7. \"AI is so advanced, it can even make my phone autocorrect my perfectly spelled words into complete nonsense.\"\\n8. \"AI may be able to recognize faces, but can it recognize when someone\\'s had a bad haircut?\"\\n9. \"AI is like having a personal assistant, except it never judges you for spending hours watching cat videos on YouTube.\"\\n10. \"AI is great at analyzing data, but can it analyze why I can never find matching socks in my drawer?\"')" - ] - }, - "execution_count": 45, - "metadata": {}, - "output_type": "execute_result" - } - ], - "source": [ - "chatllm([\n", - "SystemMessage(content=\"Yor are a comedian AI assitant\"),\n", - "HumanMessage(content=\"Please provide some comedy punchlines on AI\")\n", - "])" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "### Prompt Template + LLM +Output Parsers" - ] - }, - { - "cell_type": "code", - "execution_count": 46, - "metadata": {}, - "outputs": [], - "source": [ - "from langchain.chat_models import ChatOpenAI\n", - "from langchain.prompts.chat import ChatPromptTemplate\n", - "from langchain.schema import BaseOutputParser" - ] - }, - { - "cell_type": "code", - "execution_count": 47, - "metadata": {}, - "outputs": [], - "source": [ - "class Commaseperatedoutput(BaseOutputParser):\n", - " def parse(self,text:str):\n", - " return text.strip().split(\",\")" - ] - }, - { - "cell_type": "code", - "execution_count": 48, - "metadata": {}, - "outputs": [], - "source": [ - "template=\"Your are a helpful assistant. When the use given any input , you should generate 5 words synonyms in a comma seperated list\"\n", - "human_template=\"{text}\"\n", - "chatprompt=ChatPromptTemplate.from_messages([\n", - " (\"system\",template),\n", - " (\"human\",human_template)\n", - "\n", - "\n", - "])" - ] - }, - { - "cell_type": "code", - "execution_count": 54, - "metadata": {}, - "outputs": [], - "source": [ - "chain=chatprompt|chatllm|Commaseperatedoutput()" - ] - }, - { - "cell_type": "code", - "execution_count": 55, - "metadata": {}, - "outputs": [ - { - "data": { - "text/plain": [ - "['smart', ' clever', ' brilliant', ' sharp', ' astute']" - ] - }, - "execution_count": 55, - "metadata": {}, - "output_type": "execute_result" - } - ], - "source": [ - "chain.invoke({\"text\":\"intelligent\"})" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [] - } - ], - "metadata": { - "kernelspec": { - "display_name": "Python 3", - "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.0" - } - }, - "nbformat": 4, - "nbformat_minor": 2 -} diff --git a/Q&A Chatbot USing LLM/requirements.txt b/Q&A Chatbot USing LLM/requirements.txt deleted file mode 100644 index 7c5e2432..00000000 --- a/Q&A Chatbot USing LLM/requirements.txt +++ /dev/null @@ -1,5 +0,0 @@ -langchain -openai -huggingface_hub -python-dotenv -streamlit \ No newline at end of file diff --git a/calorieshealth/app.py b/calorieshealth/app.py deleted file mode 100644 index e16e7b32..00000000 --- a/calorieshealth/app.py +++ /dev/null @@ -1,78 +0,0 @@ -# Q&A Chatbot -#from langchain.llms import OpenAI - -from dotenv import load_dotenv - -load_dotenv() # take environment variables from .env. - -import streamlit as st -import os -import pathlib -import textwrap -from PIL import Image - - -import google.generativeai as genai - - -os.getenv("GOOGLE_API_KEY") -genai.configure(api_key=os.getenv("GOOGLE_API_KEY")) - -## Function to load OpenAI model and get respones - -def get_gemini_response(input,image,prompt): - model = genai.GenerativeModel('gemini-pro-vision') - response = model.generate_content([input,image[0],prompt]) - return response.text - - -def input_image_setup(uploaded_file): - # Check if a file has been uploaded - if uploaded_file is not None: - # Read the file into bytes - bytes_data = uploaded_file.getvalue() - - image_parts = [ - { - "mime_type": uploaded_file.type, # Get the mime type of the uploaded file - "data": bytes_data - } - ] - return image_parts - else: - raise FileNotFoundError("No file uploaded") - - -##initialize our streamlit app - -st.set_page_config(page_title="Gemini Image Demo") - -st.header("Gemini Application") -input=st.text_input("Input Prompt: ",key="input") -uploaded_file = st.file_uploader("Choose an image...", type=["jpg", "jpeg", "png"]) -image="" -if uploaded_file is not None: - image = Image.open(uploaded_file) - st.image(image, caption="Uploaded Image.", use_column_width=True) - - -submit=st.button("Tell me about the image") - -input_prompt = """ - You are an expert in nutritionist where you need to see the food items from the image - and calculate the total calories, also provide the details of every food items with calories intake - is below format - - 1. Item 1 - no of calories - 2. Item 2 - no of calories - ---- - ---- - """ - -## If ask button is clicked - -if submit: - image_data = input_image_setup(uploaded_file) - response=get_gemini_response(input_prompt,image_data,input) - st.subheader("The Response is") - st.write(response) \ No newline at end of file diff --git a/calorieshealth/requirements.txt b/calorieshealth/requirements.txt deleted file mode 100644 index 5e923ddd..00000000 --- a/calorieshealth/requirements.txt +++ /dev/null @@ -1,8 +0,0 @@ -streamlit -google-generativeai -python-dotenv -langchain -PyPDF2 -chromadb -faiss-cpu -pdf2image \ No newline at end of file diff --git a/calorieshealth/sqlllm/requirements.txt b/calorieshealth/sqlllm/requirements.txt deleted file mode 100644 index c5c42fcf..00000000 --- a/calorieshealth/sqlllm/requirements.txt +++ /dev/null @@ -1,9 +0,0 @@ -streamlit -google-generativeai -python-dotenv -langchain -PyPDF2 -chromadb -faiss-cpu -pdf2image -sqlite3 \ No newline at end of file diff --git a/calorieshealth/sqlllm/sql.py b/calorieshealth/sqlllm/sql.py deleted file mode 100644 index bbcc5af0..00000000 --- a/calorieshealth/sqlllm/sql.py +++ /dev/null @@ -1,62 +0,0 @@ -from dotenv import load_dotenv - -load_dotenv() # take environment variables from .env. - -import streamlit as st -import os -import pathlib -import textwrap -import sqlite3 - -import google.generativeai as genai - -os.getenv("GOOGLE_API_KEY") -genai.configure(api_key=os.getenv("GOOGLE_API_KEY")) - -## Function to load OpenAI model and get respones - -def get_gemini_response(question,prompt): - model = genai.GenerativeModel('gemini-pro') - response = model.generate_content([prompt[0],question]) - print(response.text) - output = read_sql_query(response.text, "test.db") - print(output) - return output - -def read_sql_query(sql, db): - conn = sqlite3.connect(db) - cur = conn.cursor() - cur.execute(sql) - rows = cur.fetchall() - for row in rows: - print(row) - return rows - -##initialize our streamlit app -prompt = [ - """You are an expert in converting English questions to SQL code! - The SQL database has the name STUDENT and has the following columns - NAME, CLASS, - SECTION \n\nFor example,\nExample 1 - How many entries of records are present?, - the SQL command will be something like this SELECT COUNT(*) FROM STUDENT ; - also the sql code should not have ``` in beginning or end and sql word in output - """ -] - -st.set_page_config(page_title="I can Retireve Any SQL query") - -st.header("Gemini Application") - -questions=st.text_input("Input: ",key="input") - - -submit=st.button("Ask the question") - -## If ask button is clicked - -if submit: - - response=get_gemini_response(questions,prompt) - st.subheader("The Response is") - for row in response: - print(row) - st.subheader(row) \ No newline at end of file diff --git a/calorieshealth/sqlllm/sqlite.py b/calorieshealth/sqlllm/sqlite.py deleted file mode 100644 index 72b47d54..00000000 --- a/calorieshealth/sqlllm/sqlite.py +++ /dev/null @@ -1,31 +0,0 @@ -# Import module -import sqlite3 - -# Connecting to sqlite -conn = sqlite3.connect('test.db') - -# Creating a cursor object using the -# cursor() method -cursor = conn.cursor() - -# Creating table -table ="""CREATE TABLE STUDENT(NAME VARCHAR(255), CLASS VARCHAR(255), -SECTION VARCHAR(255));""" -cursor.execute(table) - -# Queries to INSERT records. -cursor.execute('''INSERT INTO STUDENT VALUES ('Raju', '7th', 'A')''') -cursor.execute('''INSERT INTO STUDENT VALUES ('Shyam', '8th', 'B')''') -cursor.execute('''INSERT INTO STUDENT VALUES ('Baburao', '9th', 'C')''') - -# Display data inserted -print("Data Inserted in the table: ") -data=cursor.execute('''SELECT * FROM STUDENT''') -for row in data: - print(row) - -# Commit your changes in the database -conn.commit() - -# Closing the connection -conn.close() \ No newline at end of file diff --git a/chatmultipledocuments/chatpdf1.py b/chatmultipledocuments/chatpdf1.py deleted file mode 100644 index 255bb9e2..00000000 --- a/chatmultipledocuments/chatpdf1.py +++ /dev/null @@ -1,106 +0,0 @@ -import streamlit as st -from PyPDF2 import PdfReader -from langchain.text_splitter import RecursiveCharacterTextSplitter -import os -from langchain_google_genai import GoogleGenerativeAIEmbeddings -import google.generativeai as genai -from langchain.vectorstores import FAISS -from langchain_google_genai import ChatGoogleGenerativeAI -from langchain.chains.question_answering import load_qa_chain -from langchain.prompts import PromptTemplate -from dotenv import load_dotenv - -load_dotenv() -os.getenv("GOOGLE_API_KEY") -genai.configure(api_key=os.getenv("GOOGLE_API_KEY")) - - - - - - -def get_pdf_text(pdf_docs): - text="" - for pdf in pdf_docs: - pdf_reader= PdfReader(pdf) - for page in pdf_reader.pages: - text+= page.extract_text() - return text - - - -def get_text_chunks(text): - text_splitter = RecursiveCharacterTextSplitter(chunk_size=10000, chunk_overlap=1000) - chunks = text_splitter.split_text(text) - return chunks - - -def get_vector_store(text_chunks): - embeddings = GoogleGenerativeAIEmbeddings(model = "models/embedding-001") - vector_store = FAISS.from_texts(text_chunks, embedding=embeddings) - vector_store.save_local("faiss_index") - - -def get_conversational_chain(): - - prompt_template = """ - Answer the question as detailed as possible from the provided context, make sure to provide all the details, if the answer is not in - provided context just say, "answer is not available in the context", don't provide the wrong answer\n\n - Context:\n {context}?\n - Question: \n{question}\n - - Answer: - """ - - model = ChatGoogleGenerativeAI(model="gemini-pro", - temperature=0.3) - - prompt = PromptTemplate(template = prompt_template, input_variables = ["context", "question"]) - chain = load_qa_chain(model, chain_type="stuff", prompt=prompt) - - return chain - - - -def user_input(user_question): - embeddings = GoogleGenerativeAIEmbeddings(model = "models/embedding-001") - - new_db = FAISS.load_local("faiss_index", embeddings) - docs = new_db.similarity_search(user_question) - - chain = get_conversational_chain() - - - response = chain( - {"input_documents":docs, "question": user_question} - , return_only_outputs=True) - - print(response) - st.write("Reply: ", response["output_text"]) - - - - -def main(): - st.set_page_config("Chat PDF") - st.header("Chat with PDF using Gemini💁") - - user_question = st.text_input("Ask a Question from the PDF Files") - - if user_question: - user_input(user_question) - - with st.sidebar: - st.title("Menu:") - pdf_docs = st.file_uploader("Upload your PDF Files and Click on the Submit & Process Button", accept_multiple_files=True) - if st.button("Submit & Process"): - with st.spinner("Processing..."): - raw_text = get_pdf_text(pdf_docs) - text_chunks = get_text_chunks(raw_text) - get_vector_store(text_chunks) - st.success("Done") - - - -if __name__ == "__main__": - main() diff --git a/chatmultipledocuments/requirements.txt b/chatmultipledocuments/requirements.txt deleted file mode 100644 index 8cf25758..00000000 --- a/chatmultipledocuments/requirements.txt +++ /dev/null @@ -1,8 +0,0 @@ -streamlit -google-generativeai -python-dotenv -langchain -PyPDF2 -chromadb -faiss-cpu -langchain_google_genai