anas.mkh
commited on
Commit
·
f97cf59
0
Parent(s):
"second commit"
Browse files- .idea/.gitignore +3 -0
- .idea/chabi.iml +10 -0
- .idea/inspectionProfiles/Project_Default.xml +12 -0
- .idea/inspectionProfiles/profiles_settings.xml +6 -0
- .idea/misc.xml +7 -0
- .idea/modules.xml +8 -0
- .idea/vcs.xml +7 -0
- README.md +6 -0
- info.txt +4 -0
- main.py +54 -0
.idea/.gitignore
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
# Default ignored files
|
2 |
+
/shelf/
|
3 |
+
/workspace.xml
|
.idea/chabi.iml
ADDED
@@ -0,0 +1,10 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?xml version="1.0" encoding="UTF-8"?>
|
2 |
+
<module type="PYTHON_MODULE" version="4">
|
3 |
+
<component name="NewModuleRootManager">
|
4 |
+
<content url="file://$MODULE_DIR$">
|
5 |
+
<excludeFolder url="file://$MODULE_DIR$/venv" />
|
6 |
+
</content>
|
7 |
+
<orderEntry type="inheritedJdk" />
|
8 |
+
<orderEntry type="sourceFolder" forTests="false" />
|
9 |
+
</component>
|
10 |
+
</module>
|
.idea/inspectionProfiles/Project_Default.xml
ADDED
@@ -0,0 +1,12 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<component name="InspectionProjectProfileManager">
|
2 |
+
<profile version="1.0">
|
3 |
+
<option name="myName" value="Project Default" />
|
4 |
+
<inspection_tool class="PyPep8NamingInspection" enabled="true" level="WEAK WARNING" enabled_by_default="true">
|
5 |
+
<option name="ignoredErrors">
|
6 |
+
<list>
|
7 |
+
<option value="N802" />
|
8 |
+
</list>
|
9 |
+
</option>
|
10 |
+
</inspection_tool>
|
11 |
+
</profile>
|
12 |
+
</component>
|
.idea/inspectionProfiles/profiles_settings.xml
ADDED
@@ -0,0 +1,6 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<component name="InspectionProjectProfileManager">
|
2 |
+
<settings>
|
3 |
+
<option name="USE_PROJECT_PROFILE" value="false" />
|
4 |
+
<version value="1.0" />
|
5 |
+
</settings>
|
6 |
+
</component>
|
.idea/misc.xml
ADDED
@@ -0,0 +1,7 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?xml version="1.0" encoding="UTF-8"?>
|
2 |
+
<project version="4">
|
3 |
+
<component name="Black">
|
4 |
+
<option name="sdkName" value="Python 3.10 (chabi)" />
|
5 |
+
</component>
|
6 |
+
<component name="ProjectRootManager" version="2" project-jdk-name="Python 3.10 (chabi)" project-jdk-type="Python SDK" />
|
7 |
+
</project>
|
.idea/modules.xml
ADDED
@@ -0,0 +1,8 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?xml version="1.0" encoding="UTF-8"?>
|
2 |
+
<project version="4">
|
3 |
+
<component name="ProjectModuleManager">
|
4 |
+
<modules>
|
5 |
+
<module fileurl="file://$PROJECT_DIR$/.idea/chabi.iml" filepath="$PROJECT_DIR$/.idea/chabi.iml" />
|
6 |
+
</modules>
|
7 |
+
</component>
|
8 |
+
</project>
|
.idea/vcs.xml
ADDED
@@ -0,0 +1,7 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?xml version="1.0" encoding="UTF-8"?>
|
2 |
+
<project version="4">
|
3 |
+
<component name="VcsDirectoryMappings">
|
4 |
+
<mapping directory="$PROJECT_DIR$" vcs="Git" />
|
5 |
+
<mapping directory="$PROJECT_DIR$/chabi" vcs="Git" />
|
6 |
+
</component>
|
7 |
+
</project>
|
README.md
ADDED
@@ -0,0 +1,6 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
---
|
2 |
+
title: chabi
|
3 |
+
app_file: main.py
|
4 |
+
sdk: gradio
|
5 |
+
sdk_version: 4.12.0
|
6 |
+
---
|
info.txt
ADDED
@@ -0,0 +1,4 @@
|
|
|
|
|
|
|
|
|
|
|
1 |
+
this is a trial file to add some lines
|
2 |
+
the main purpose of this file is testing our own chatbot
|
3 |
+
this bot isn't for answering general questions
|
4 |
+
here in computer and automation engineering we are learning about large language model
|
main.py
ADDED
@@ -0,0 +1,54 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
from langchain.chains import RetrievalQA, ConversationalRetrievalChain
|
2 |
+
from langchain.vectorstores import Chroma
|
3 |
+
from langchain.text_splitter import CharacterTextSplitter
|
4 |
+
from langchain.document_loaders import DirectoryLoader, TextLoader
|
5 |
+
from transformers import pipeline
|
6 |
+
from langchain.llms import HuggingFacePipeline
|
7 |
+
from langchain.embeddings import HuggingFaceInstructEmbeddings
|
8 |
+
import gradio as gr
|
9 |
+
from InstructorEmbedding import INSTRUCTOR
|
10 |
+
import torch
|
11 |
+
from transformers import AutoTokenizer, AutoModelForSeq2SeqLM
|
12 |
+
|
13 |
+
tokenizer = AutoTokenizer.from_pretrained("google/flan-t5-base")
|
14 |
+
|
15 |
+
model = AutoModelForSeq2SeqLM.from_pretrained("google/flan-t5-base")
|
16 |
+
pipe = pipeline(
|
17 |
+
"text2text-generation",
|
18 |
+
model=model,
|
19 |
+
tokenizer=tokenizer,
|
20 |
+
max_length=512,
|
21 |
+
temperature=0.5,
|
22 |
+
top_p=0.95,
|
23 |
+
repetition_penalty=1.15
|
24 |
+
)
|
25 |
+
|
26 |
+
local_llm = HuggingFacePipeline(pipeline=pipe)
|
27 |
+
print(local_llm('What is the capital of Syria?'))
|
28 |
+
|
29 |
+
loader = TextLoader('info.txt')
|
30 |
+
document = loader.load()
|
31 |
+
text_spliter = CharacterTextSplitter(chunk_size=1000, chunk_overlap=0)
|
32 |
+
texts = text_spliter.split_documents(document)
|
33 |
+
embedding = HuggingFaceInstructEmbeddings()
|
34 |
+
docsearch = Chroma.from_documents(texts, embedding, persist_directory='db')
|
35 |
+
|
36 |
+
retriever = docsearch.as_retriever(search_kwargs={"k": 3})
|
37 |
+
qa_chain = RetrievalQA.from_chain_type(llm=local_llm,
|
38 |
+
chain_type="map_reduce",
|
39 |
+
retriever=retriever,
|
40 |
+
return_source_documents=True)
|
41 |
+
|
42 |
+
question = input('prompt: ')
|
43 |
+
result = qa_chain({'query': question})
|
44 |
+
print('result: ', result['result'])
|
45 |
+
|
46 |
+
def gradinterface(query):
|
47 |
+
result = qa_chain({'query': query})
|
48 |
+
return result['result']
|
49 |
+
|
50 |
+
|
51 |
+
demo = gr.ChatInterface(fn=gradinterface, title='OUR_OWN_BOT')
|
52 |
+
|
53 |
+
if __name__ == "__main__":
|
54 |
+
demo.launch(show_api=False, share=True)
|