fengtc
commited on
Commit
•
197f59d
0
Parent(s):
Duplicate from fengtc/langchain-text-local-glm-faiss
Browse files- .gitattributes +36 -0
- ANSYS_Fluent_Text_Command_List.pdf +3 -0
- README.md +14 -0
- app.py +62 -0
- output_1.txt +0 -0
- requirements.txt +7 -0
.gitattributes
ADDED
@@ -0,0 +1,36 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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
|
36 |
+
ANSYS_Fluent_Text_Command_List.pdf filter=lfs diff=lfs merge=lfs -text
|
ANSYS_Fluent_Text_Command_List.pdf
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:5dd5c52133e79300143e09f32410d9d0372ff27d0ef8371ea9800eb76fa5cb44
|
3 |
+
size 4218442
|
README.md
ADDED
@@ -0,0 +1,14 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
---
|
2 |
+
title: Langchain Pdf Openai Faiss
|
3 |
+
emoji: ⚡
|
4 |
+
colorFrom: indigo
|
5 |
+
colorTo: purple
|
6 |
+
sdk: gradio
|
7 |
+
sdk_version: 3.39.0
|
8 |
+
app_file: app.py
|
9 |
+
pinned: false
|
10 |
+
license: openrail
|
11 |
+
duplicated_from: fengtc/langchain-text-local-glm-faiss
|
12 |
+
---
|
13 |
+
|
14 |
+
Check out the configuration reference at https://huggingface.co/docs/hub/spaces-config-reference
|
app.py
ADDED
@@ -0,0 +1,62 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
from langchain.embeddings.openai import OpenAIEmbeddings
|
2 |
+
from langchain.embeddings import HuggingFaceEmbeddings
|
3 |
+
from langchain.text_splitter import CharacterTextSplitter
|
4 |
+
from langchain.vectorstores import FAISS
|
5 |
+
from langchain.chains.question_answering import load_qa_chain
|
6 |
+
from langchain.llms import OpenAI
|
7 |
+
from gradio import gradio as gr
|
8 |
+
from langchain.chat_models import ChatOpenAI
|
9 |
+
#from langchain.memory import ConversationBufferMemor
|
10 |
+
from langchain.schema import AIMessage, HumanMessage
|
11 |
+
from langchain import PromptTemplate, LLMChain
|
12 |
+
from langchain.llms import TextGen
|
13 |
+
|
14 |
+
|
15 |
+
|
16 |
+
import os
|
17 |
+
OPENAI_API_KEY=os.getenv('OPENAI_API_KEY')
|
18 |
+
|
19 |
+
#分割文档
|
20 |
+
text_splitter = CharacterTextSplitter(
|
21 |
+
separator="\n",
|
22 |
+
chunk_size=1000,
|
23 |
+
chunk_overlap=200,
|
24 |
+
length_function=len
|
25 |
+
)
|
26 |
+
|
27 |
+
texts = text_splitter.split_text("./output_1.txt")
|
28 |
+
|
29 |
+
# 嵌入模型
|
30 |
+
#embeddings = OpenAIEmbeddings()
|
31 |
+
embeddings = HuggingFaceEmbeddings(model_name="sentence-transformers/all-mpnet-base-v2")
|
32 |
+
|
33 |
+
# 加载数据
|
34 |
+
docsearch = FAISS.from_texts(texts, embeddings)
|
35 |
+
|
36 |
+
model_url = "http://36.103.234.50:5000"
|
37 |
+
|
38 |
+
llm = TextGen(model_url=model_url)
|
39 |
+
|
40 |
+
chain = load_qa_chain(llm)
|
41 |
+
|
42 |
+
def predict(message, history):
|
43 |
+
history_langchain_format = []
|
44 |
+
for human, ai in history:
|
45 |
+
history_langchain_format.append(HumanMessage(content=human))
|
46 |
+
history_langchain_format.append(AIMessage(content=ai))
|
47 |
+
history_langchain_format.append(HumanMessage(content=message))
|
48 |
+
docs = docsearch.similarity_search(message)
|
49 |
+
response = chain.run(input_documents=docs, question=message)
|
50 |
+
|
51 |
+
|
52 |
+
partial_message = ""
|
53 |
+
for chunk in response:
|
54 |
+
if len(chunk) != 0:
|
55 |
+
partial_message = partial_message + chunk
|
56 |
+
yield partial_message
|
57 |
+
|
58 |
+
|
59 |
+
return response
|
60 |
+
|
61 |
+
gr.ChatInterface(predict).queue().launch()
|
62 |
+
|
output_1.txt
ADDED
The diff for this file is too large to render.
See raw diff
|
|
requirements.txt
ADDED
@@ -0,0 +1,7 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
langchain
|
2 |
+
openai
|
3 |
+
docsearch
|
4 |
+
tiktoken
|
5 |
+
texts
|
6 |
+
faiss-cpu
|
7 |
+
sentence_transformers
|