AhmedEwis commited on
Commit
63bb9d4
1 Parent(s): f6bca1e

Update langchain_qa_warba.py

Browse files
Files changed (1) hide show
  1. langchain_qa_warba.py +4 -87
langchain_qa_warba.py CHANGED
@@ -1,15 +1,8 @@
1
- # -*- coding: utf-8 -*-
2
- """LangChain QA WARBA
3
 
4
- Automatically generated by Colaboratory.
5
 
6
- Original file is located at
7
- https://colab.research.google.com/drive/1FlN_580MckH1k15F73gvsxLSg-O5WUIO
8
- """
9
 
10
- !pip install openai langchain faiss-cpu
11
-
12
- !pip install tiktoken
13
 
14
  #@title State of Union Text
15
  state_of_the_union = """ I am an AI Bota and my name is Shegardi and I am an employee of Warba Bank, located in Kuwait and I have been created to answer certain questions about warba bank.
@@ -603,87 +596,11 @@ Warba Bank is a modern banking solution that provides a wide range of financial
603
 
604
 
605
 
606
- """
607
-
608
- #@title Environment Vars
609
- openai_api_key = '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'
610
-
611
- import os
612
- os.environ["OPENAI_API_KEY"] = openai_api_key
613
-
614
- from langchain.embeddings.openai import OpenAIEmbeddings
615
- from langchain.vectorstores.faiss import FAISS
616
- from langchain.text_splitter import RecursiveCharacterTextSplitter
617
- from langchain import OpenAI, VectorDBQA
618
-
619
-
620
- text_splitter = RecursiveCharacterTextSplitter(chunk_size=1000, chunk_overlap=0)
621
- texts = text_splitter.split_text(state_of_the_union)
622
-
623
- embeddings = OpenAIEmbeddings()
624
- vectorstore = FAISS.from_texts(texts, embeddings)
625
-
626
- qa = VectorDBQA.from_chain_type(llm=OpenAI(), chain_type="stuff", vectorstore=vectorstore)
627
-
628
- query = "What is warba bank?"
629
- qa.run(query)
630
-
631
- llm = OpenAI()
632
- llm(query)
633
-
634
- from langchain.chains import load_chain
635
-
636
- chain = load_chain("lc://chains/vector-db-qa/stuff/chain.json", vectorstore=vectorstore)
637
-
638
- query = "I am w segment and my spends are 3000 international and 1000 local, calculate my cashback"
639
- chain.run(query)
640
-
641
- query = "I am w segment and my spends are 3000 international and 1000 local, calculate my cashback"
642
- chain.run(query)
643
-
644
- !pip install streamlit
645
-
646
- import streamlit as st
647
-
648
- # State of Union Text
649
- #state_of_the_union = """ data"""
650
-
651
- # Environment Vars
652
- openai_api_key = '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'
653
- import os
654
- os.environ["OPENAI_API_KEY"] = openai_api_key
655
-
656
- from langchain.embeddings.openai import OpenAIEmbeddings
657
- from langchain.vectorstores.faiss import FAISS
658
- from langchain.text_splitter import RecursiveCharacterTextSplitter
659
- from langchain import OpenAI, VectorDBQA
660
-
661
-
662
- text_splitter = RecursiveCharacterTextSplitter(chunk_size=1000, chunk_overlap=0)
663
- texts = text_splitter.split_text(state_of_the_union)
664
-
665
- embeddings = OpenAIEmbeddings()
666
- vectorstore = FAISS.from_texts(texts, embeddings)
667
- qa = VectorDBQA.from_chain_type(llm=OpenAI(), chain_type="stuff", vectorstore=vectorstore)
668
-
669
- from langchain.chains import load_chain
670
-
671
- chain = load_chain("lc://chains/vector-db-qa/stuff/chain.json", vectorstore=vectorstore)
672
-
673
- def run_chain(query):
674
- return chain.run(query)
675
-
676
- st.title("Vector-based DBQA with OpenAI and Langchain")
677
- query = st.text_input("Enter your query:")
678
- if st.button("Ask"):
679
- answer = run_chain(query)
680
- st.write("Answer:", answer)
681
-
682
  !pip install gradio
683
 
684
  import gradio as gr
685
 
686
- # State of Union Text
687
  #state_of_the_union = """ data"""
688
 
689
  # Environment Vars
@@ -720,7 +637,7 @@ def run_app(input):
720
 
721
  gr.Interface(fn=run_app, inputs=inputs, outputs=outputs, title="The following is a conversation with a human called Shegardi. Shegardi is helpful, precise, truthful, and very friendly. Also, Shegardi is an employee of Warba Bank, located in Kuwait. Shegardi will only use the information provided to him.").launch(share=True)
722
 
723
- query
724
 
725
 
726
 
 
 
 
1
 
 
2
 
3
+ #!pip install openai langchain faiss-cpu
 
 
4
 
5
+ #!pip install tiktoken
 
 
6
 
7
  #@title State of Union Text
8
  state_of_the_union = """ I am an AI Bota and my name is Shegardi and I am an employee of Warba Bank, located in Kuwait and I have been created to answer certain questions about warba bank.
 
596
 
597
 
598
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
599
  !pip install gradio
600
 
601
  import gradio as gr
602
 
603
+ #State of Union Text
604
  #state_of_the_union = """ data"""
605
 
606
  # Environment Vars
 
637
 
638
  gr.Interface(fn=run_app, inputs=inputs, outputs=outputs, title="The following is a conversation with a human called Shegardi. Shegardi is helpful, precise, truthful, and very friendly. Also, Shegardi is an employee of Warba Bank, located in Kuwait. Shegardi will only use the information provided to him.").launch(share=True)
639
 
640
+
641
 
642
 
643