瀏覽代碼

Upload files to 'Supportgpt'

SadhulaSaiKumar 1 年之前
父節點
當前提交
2e35cfddc1
共有 3 個檔案被更改,包括 1625 行新增0 行删除
  1. 110
    0
      Supportgpt/app.py
  2. 127
    0
      Supportgpt/requirement.txt
  3. 1388
    0
      Supportgpt/supportqa.csv

+ 110
- 0
Supportgpt/app.py 查看文件

@@ -0,0 +1,110 @@
1
+from flask import Flask, request, render_template
2
+# Import the relevant modules and functions from your code
3
+from langchain.llms import GooglePalm
4
+from langchain.llms import LlamaCpp
5
+from transformers import pipeline
6
+from langchain.llms import HuggingFacePipeline
7
+from langchain.embeddings import GooglePalmEmbeddings
8
+from langchain.document_loaders.csv_loader import CSVLoader
9
+from langchain.embeddings import HuggingFaceInstructEmbeddings
10
+from langchain.vectorstores import FAISS
11
+from langchain.prompts import PromptTemplate
12
+from langchain.chains import RetrievalQA
13
+from langchain.text_splitter import RecursiveCharacterTextSplitter
14
+import torch
15
+
16
+
17
+app = Flask(__name__)
18
+
19
+# Initialize Langchain components (put this code outside the app route)
20
+#api_key = 'AIzaSyCZwsYvr3ht7ctxcrOLWvfppySP33ducmE'
21
+#llm = GooglePalm(google_api_key=api_key, temperature=0.1)
22
+
23
+from langchain.llms import CTransformers
24
+
25
+llm = CTransformers(model=r"C:\Aiproject\mainmodel\llama-2-7b-chat.ggmlv3.q8_0.bin",model_type="llama",temperature=0.1,gpu_layers=50,do_sample=True)
26
+
27
+# llm = CTransformers(
28
+#         model = r"C:\Aiproject\mistral\Mistral-7B-v0.1",
29
+#         model_type="mistral",
30
+#         max_new_tokens = 1048,
31
+#         temperature = 0.1,gpu_layers=50
32
+#     )
33
+
34
+
35
+# device=torch.device('cpu')
36
+# from transformers import AutoTokenizer, AutoModelForSeq2SeqLM 
37
+
38
+# checkpoint = "MBZUAI/LaMini-T5-738M"
39
+# tokenizer = AutoTokenizer.from_pretrained(checkpoint)
40
+# base_model = AutoModelForSeq2SeqLM.from_pretrained(
41
+#     checkpoint,
42
+#     device_map=device,
43
+#     torch_dtype=torch.float32
44
+# )
45
+
46
+
47
+# pipe = pipeline(
48
+#         'text2text-generation',
49
+#         model = base_model,
50
+#         tokenizer = tokenizer,
51
+#         max_length = 256,
52
+#         do_sample = True,
53
+#         temperature = 0.1,
54
+#         top_p= 0.95
55
+#     )
56
+# llm = HuggingFacePipeline(pipeline=pipe)
57
+
58
+
59
+
60
+
61
+
62
+# Initialize instructor embeddings using the Hugging Face model
63
+instructor_embeddings = HuggingFaceInstructEmbeddings(model_name=r"C:\Aiproject\SupportGpt\model")
64
+
65
+# Load the data from CSV
66
+loader = CSVLoader(file_path=r"C:\Aiproject\codebasics_faqs.csv", encoding='iso-8859-1', source_column="Question")
67
+data = loader.load()
68
+text_splitter=RecursiveCharacterTextSplitter(chunk_size=500,chunk_overlap=50)
69
+texts=text_splitter.split_documents(data)
70
+
71
+
72
+# Create a FAISS instance for vector database
73
+vectordb = FAISS.from_documents(documents=texts, embedding=instructor_embeddings)
74
+
75
+# Create a retriever for querying the vector database
76
+retriever = vectordb.as_retriever(score_threshold=0.7)
77
+
78
+# Define the prompt template
79
+# prompt_template = """Use the following pieces of information to answer the user's question,dont give additional answers.
80
+# If you don't know the answer, just say that you don't know, don't try to make up an answer.
81
+
82
+prompt_template="""Use the following peices of information to answer the user's question and do not give any additional or extra answers that do not exist in the given information.If the answer doesn't exist in the given information, say "I dont know". If the answer exists in the information, give the exact answer as it exists in the given information.Users may use different keywords or synonyms, so use at least 10 keywords or synonyms from the user's question to identify exactly what the user wants to know from given information.Please refrain from making your own answers or modifying the answers.
83
+CONTEXT: {context}
84
+
85
+QUESTION: {question}"""
86
+
87
+# Create a prompt template
88
+PROMPT = PromptTemplate(template=prompt_template, input_variables=["context", "question"])
89
+chain_type_kwargs = {"prompt": PROMPT}
90
+
91
+# Create the Langchain RetrievalQA chain
92
+chain = RetrievalQA.from_chain_type(llm=llm, chain_type="stuff", retriever=retriever, input_key="query",
93
+                                   return_source_documents=True, chain_type_kwargs=chain_type_kwargs)
94
+
95
+
96
+
97
+@app.route('/', methods=['GET', 'POST'])
98
+def index():
99
+    if request.method == 'POST':
100
+        question = request.form['question']
101
+        if question:
102
+            result = chain(question)['result']
103
+        else:
104
+            result = None
105
+        return render_template('index1.html', question=question, result=result)
106
+    return render_template('index1.html', question='', result=None)
107
+
108
+
109
+if __name__ == '__main__':
110
+    app.run(host="0.0.0.0",debug=False)

+ 127
- 0
Supportgpt/requirement.txt 查看文件

@@ -0,0 +1,127 @@
1
+accelerate==0.25.0
2
+aiohttp==3.9.1
3
+aiosignal==1.3.1
4
+altair==5.2.0
5
+annotated-types==0.6.0
6
+anyio==3.7.1
7
+APScheduler==3.10.4
8
+async-timeout==4.0.3
9
+attrs==23.1.0
10
+auto-gptq==0.5.1
11
+blinker==1.7.0
12
+cachetools==5.3.2
13
+certifi==2023.11.17
14
+charset-normalizer==3.3.2
15
+click==8.1.7
16
+colorama==0.4.6
17
+coloredlogs==15.0.1
18
+ctransformers==0.2.27
19
+dataclasses-json==0.6.3
20
+datasets==2.15.0
21
+dill==0.3.7
22
+diskcache==5.6.3
23
+exceptiongroup==1.2.0
24
+faiss-cpu==1.7.4
25
+filelock==3.13.1
26
+Flask==3.0.0
27
+frozenlist==1.4.0
28
+fsspec==2023.10.0
29
+gekko==1.0.6
30
+gitdb==4.0.11
31
+GitPython==3.1.40
32
+google-ai-generativelanguage==0.3.3
33
+google-api-core==2.14.0
34
+google-auth==2.24.0
35
+google-generativeai==0.2.2
36
+googleapis-common-protos==1.61.0
37
+greenlet==3.0.1
38
+grpcio==1.59.3
39
+grpcio-status==1.59.3
40
+huggingface-hub==0.19.4
41
+humanfriendly==10.0
42
+idna==3.6
43
+importlib-metadata==6.11.0
44
+InstructorEmbedding==1.0.1
45
+itsdangerous==2.1.2
46
+Jinja2==3.1.2
47
+joblib==1.3.2
48
+jsonpatch==1.33
49
+jsonpointer==2.4
50
+jsonschema==4.20.0
51
+jsonschema-specifications==2023.11.2
52
+langchain==0.0.345
53
+langchain-core==0.0.9
54
+langsmith==0.0.69
55
+llama_cpp_python==0.2.20
56
+markdown-it-py==3.0.0
57
+MarkupSafe==2.1.3
58
+marshmallow==3.20.1
59
+mdurl==0.1.2
60
+mpmath==1.3.0
61
+multidict==6.0.4
62
+multiprocess==0.70.15
63
+mypy-extensions==1.0.0
64
+networkx==3.2.1
65
+nltk==3.8.1
66
+numpy==1.26.2
67
+optimum==1.15.0
68
+packaging==23.2
69
+pandas==2.1.3
70
+peft==0.7.0
71
+Pillow==10.1.0
72
+proto-plus==1.22.3
73
+protobuf==4.25.1
74
+psutil==5.9.6
75
+py-cpuinfo==9.0.0
76
+pyarrow==14.0.1
77
+pyarrow-hotfix==0.6
78
+pyasn1==0.5.1
79
+pyasn1-modules==0.3.0
80
+pydantic==2.5.2
81
+pydantic_core==2.14.5
82
+pydeck==0.8.1b0
83
+Pygments==2.17.2
84
+pyreadline3==3.4.1
85
+python-dateutil==2.8.2
86
+pytz==2023.3.post1
87
+PyYAML==6.0.1
88
+referencing==0.31.1
89
+regex==2023.10.3
90
+requests==2.31.0
91
+rich==13.7.0
92
+rouge==1.0.1
93
+rpds-py==0.13.2
94
+rsa==4.9
95
+safetensors==0.4.1
96
+scikit-learn==1.3.2
97
+scipy==1.11.4
98
+sentence-transformers==2.2.2
99
+sentencepiece==0.1.99
100
+six==1.16.0
101
+smmap==5.0.1
102
+sniffio==1.3.0
103
+SQLAlchemy==2.0.23
104
+streamlit==1.29.0
105
+streamlit-chat==0.1.1
106
+sympy==1.12
107
+tenacity==8.2.3
108
+threadpoolctl==3.2.0
109
+tokenizers==0.15.0
110
+toml==0.10.2
111
+toolz==0.12.0
112
+torch==2.1.1
113
+torchvision==0.16.1
114
+tornado==6.4
115
+tqdm==4.66.1
116
+transformers==4.35.2
117
+typing-inspect==0.9.0
118
+typing_extensions==4.8.0
119
+tzdata==2023.3
120
+tzlocal==5.2
121
+urllib3==2.1.0
122
+validators==0.22.0
123
+watchdog==3.0.0
124
+Werkzeug==3.0.1
125
+xxhash==3.4.1
126
+yarl==1.9.3
127
+zipp==3.17.0

+ 1388
- 0
Supportgpt/supportqa.csv
文件差異過大導致無法顯示
查看文件


Loading…
取消
儲存