enadewan commited on
Commit
6ace879
0 Parent(s):

Duplicate from enadewan/ASK_FREDDY_BY_CL

Browse files
.gitattributes ADDED
@@ -0,0 +1,35 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ *.7z filter=lfs diff=lfs merge=lfs -text
2
+ *.arrow filter=lfs diff=lfs merge=lfs -text
3
+ *.bin filter=lfs diff=lfs merge=lfs -text
4
+ *.bz2 filter=lfs diff=lfs merge=lfs -text
5
+ *.ckpt filter=lfs diff=lfs merge=lfs -text
6
+ *.ftz filter=lfs diff=lfs merge=lfs -text
7
+ *.gz filter=lfs diff=lfs merge=lfs -text
8
+ *.h5 filter=lfs diff=lfs merge=lfs -text
9
+ *.joblib filter=lfs diff=lfs merge=lfs -text
10
+ *.lfs.* filter=lfs diff=lfs merge=lfs -text
11
+ *.mlmodel filter=lfs diff=lfs merge=lfs -text
12
+ *.model filter=lfs diff=lfs merge=lfs -text
13
+ *.msgpack filter=lfs diff=lfs merge=lfs -text
14
+ *.npy filter=lfs diff=lfs merge=lfs -text
15
+ *.npz filter=lfs diff=lfs merge=lfs -text
16
+ *.onnx filter=lfs diff=lfs merge=lfs -text
17
+ *.ot filter=lfs diff=lfs merge=lfs -text
18
+ *.parquet filter=lfs diff=lfs merge=lfs -text
19
+ *.pb filter=lfs diff=lfs merge=lfs -text
20
+ *.pickle filter=lfs diff=lfs merge=lfs -text
21
+ *.pkl filter=lfs diff=lfs merge=lfs -text
22
+ *.pt filter=lfs diff=lfs merge=lfs -text
23
+ *.pth filter=lfs diff=lfs merge=lfs -text
24
+ *.rar filter=lfs diff=lfs merge=lfs -text
25
+ *.safetensors filter=lfs diff=lfs merge=lfs -text
26
+ saved_model/**/* filter=lfs diff=lfs merge=lfs -text
27
+ *.tar.* filter=lfs diff=lfs merge=lfs -text
28
+ *.tar filter=lfs diff=lfs merge=lfs -text
29
+ *.tflite filter=lfs diff=lfs merge=lfs -text
30
+ *.tgz filter=lfs diff=lfs merge=lfs -text
31
+ *.wasm filter=lfs diff=lfs merge=lfs -text
32
+ *.xz filter=lfs diff=lfs merge=lfs -text
33
+ *.zip filter=lfs diff=lfs merge=lfs -text
34
+ *.zst filter=lfs diff=lfs merge=lfs -text
35
+ *tfevents* filter=lfs diff=lfs merge=lfs -text
README.md ADDED
@@ -0,0 +1,13 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ ---
2
+ title: ASK FREDDY
3
+ emoji: 🚀
4
+ colorFrom: red
5
+ colorTo: gray
6
+ sdk: gradio
7
+ sdk_version: 3.38.0
8
+ app_file: app.py
9
+ pinned: false
10
+ duplicated_from: enadewan/ASK_FREDDY_BY_CL
11
+ ---
12
+
13
+ Check out the configuration reference at https://huggingface.co/docs/hub/spaces-config-reference
app.py ADDED
@@ -0,0 +1,43 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+
2
+
3
+ from langchain.memory import ConversationBufferMemory
4
+ from langchain.vectorstores.faiss import FAISS
5
+ import os
6
+ from langchain.memory import ConversationBufferMemory
7
+ from langchain.chains import ConversationalRetrievalChain
8
+ import pandas as pd
9
+ import numpy as np
10
+ from langchain.embeddings import HuggingFaceEmbeddings
11
+ from langchain import HuggingFaceHub
12
+ from typing import Any, Dict, List
13
+ from InstructorEmbedding import INSTRUCTOR
14
+ from langchain.embeddings import HuggingFaceInstructEmbeddings
15
+ instructor_embeddings = HuggingFaceInstructEmbeddings(model_name="hkunlp/instructor-xl")
16
+ HUGGINGFACEHUB_API_TOKEN='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'
17
+ new_vectorstore = FAISS.load_local("./faiss_docs_xl_index", instructor_embeddings )
18
+ llm = HuggingFaceHub(repo_id="declare-lab/flan-alpaca-large", model_kwargs={"temperature": 0.1, "max_length": 512},huggingfacehub_api_token= "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")
19
+
20
+
21
+ # Front end web app
22
+ import gradio as gr
23
+ with gr.Blocks() as demo:
24
+
25
+ chatbot = gr.Chatbot()
26
+ msg = gr.Textbox("Ask Freddy")
27
+ clear = gr.Button("Clear")
28
+ chat_history = []
29
+
30
+ def user(user_message, history):
31
+ # Get response from QA chain
32
+ memory = ConversationBufferMemory(memory_key='chat_history', return_messages=True, output_key='answer')
33
+ qa=ConversationalRetrievalChain.from_llm( llm=llm ,retriever=new_vectorstore.as_retriever(search_kwargs={"k":1, "include_metadata": True}),chain_type="refine",memory=memory,return_source_documents=True)
34
+ result = qa({"question": user_message,"chat_history": chat_history})
35
+ myresponse=result['answer']
36
+ # Append user message and response to chat history
37
+ chat_history.append((user_message, myresponse))
38
+ return gr.update(value=""), chat_history
39
+ msg.submit(user, [msg, chatbot], [msg, chatbot], queue=False)
40
+ clear.click(lambda: None, None, chatbot, queue=False)
41
+
42
+ if __name__ == "__main__":
43
+ demo.launch(debug=True,share=False)
faiss_docs_index/index.faiss ADDED
Binary file (608 kB). View file
 
faiss_docs_index/index.pkl ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:f30d6613a8e831374d304c440a3f7b4f78fd20f27ff208b6faa3ac9d802ea055
3
+ size 205087
faiss_docs_xl_index/index.faiss ADDED
Binary file (608 kB). View file
 
faiss_docs_xl_index/index.pkl ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:b64f6df6d35f3118be58ab75c60bf39487885c9cefa752e21d3216bb03c599bc
3
+ size 205087
requirements.txt ADDED
@@ -0,0 +1,7 @@
 
 
 
 
 
 
 
 
1
+ langchain
2
+ pandas
3
+ faiss-cpu
4
+ huggingface_hub
5
+ sentence-transformers
6
+ InstructorEmbedding
7
+ gradio