yosuke123456 commited on
Commit
8fc89a7
β€’
1 Parent(s): 3ec0b48

Add application file

Browse files
.gitattributes CHANGED
@@ -33,3 +33,7 @@ saved_model/**/* 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
 
 
 
 
 
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
+ ALV2_ALV3DTUζ“δ½œγƒžγƒ‹γƒ₯をルDTU-V3SET01.pdf filter=lfs diff=lfs merge=lfs -text
37
+ ALV3PCァーバ_γ‚½γƒ•γƒˆγ‚¦γ‚§γ‚’ζ“δ½œγƒžγƒ‹γƒ₯をル_η”»εƒγƒ•γ‚‘γ‚€γƒ«εδ»˜.pdf filter=lfs diff=lfs merge=lfs -text
38
+ ηΎŽε’Œγƒ­γƒƒγ‚―η·εˆγ‚«γ‚Ώγƒ­γ‚°η¬¬31η‰ˆ_後半.pdf filter=lfs diff=lfs merge=lfs -text
39
+ ηΎŽε’Œγƒ­γƒƒγ‚―η·εˆγ‚«γ‚Ώγƒ­γ‚°η¬¬31η‰ˆ_ε‰εŠ.pdf filter=lfs diff=lfs merge=lfs -text
ALV2_ALV3DTUζ“δ½œγƒžγƒ‹γƒ₯をルDTU-V3SET01.pdf ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:04320ba9416cd11d758c80ec22663f3d7f06270aa034cde26a978af2563e7879
3
+ size 5539267
ALV3PCァーバ_γ‚½γƒ•γƒˆγ‚¦γ‚§γ‚’ζ“δ½œγƒžγƒ‹γƒ₯をル_η”»εƒγƒ•γ‚‘γ‚€γƒ«εδ»˜.pdf ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:de1312a63aa1ab60a6353694bfb8d87d709a71e7ebd77e06f1292ec03c497497
3
+ size 30541345
app.py ADDED
@@ -0,0 +1,98 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # https://qiita.com/nekoniii3/items/5acf764af65212d9f04f
2
+
3
+ import gradio as gr
4
+ import random
5
+ import time
6
+
7
+ import os
8
+
9
+ from langchain_community.document_loaders import PyMuPDFLoader
10
+ from langchain.text_splitter import RecursiveCharacterTextSplitter
11
+ # from langchain_community.chat_models import ChatOpenAI
12
+ from langchain_openai import ChatOpenAI
13
+ from langchain_community.vectorstores import Chroma
14
+ from langchain.chains import RetrievalQA
15
+ from langchain_community.embeddings import OpenAIEmbeddings
16
+
17
+
18
+
19
+ os.environ["TOKENIZERS_PARALLELISM"] = "false"
20
+ os.environ["OPENAI_API_KEY"] = "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"
21
+
22
+ file_name1 = 'ALV2_ALV3DTUζ“δ½œγƒžγƒ‹γƒ₯をルDTU-V3SET01.pdf'
23
+ file_name2 = 'ALV3PCァーバ_γ‚½γƒ•γƒˆγ‚¦γ‚§γ‚’ζ“δ½œγƒžγƒ‹γƒ₯をル_η”»εƒγƒ•γ‚‘γ‚€γƒ«εδ»˜.pdf'
24
+ file_name3 = 'ηΎŽε’Œγƒ­γƒƒγ‚―η·εˆγ‚«γ‚Ώγƒ­γ‚°η¬¬31η‰ˆ_ε‰εŠ.pdf'
25
+ file_name4 = 'ηΎŽε’Œγƒ­γƒƒγ‚―η·εˆγ‚«γ‚Ώγƒ­γ‚°η¬¬31η‰ˆ_後半.pdf'
26
+
27
+ loader1 = PyMuPDFLoader(file_name1)
28
+ loader2 = PyMuPDFLoader(file_name2)
29
+ loader3 = PyMuPDFLoader(file_name3)
30
+ loader4 = PyMuPDFLoader(file_name4)
31
+
32
+ documents1 = loader1.load()
33
+ documents2 = loader2.load()
34
+ documents3 = loader3.load()
35
+ documents4 = loader4.load()
36
+
37
+ text_splitter = RecursiveCharacterTextSplitter(chunk_size=1000, chunk_overlap=0)
38
+
39
+ texts1 = text_splitter.split_documents(documents1)
40
+ texts2 = text_splitter.split_documents(documents2)
41
+ texts3 = text_splitter.split_documents(documents3)
42
+ texts4 = text_splitter.split_documents(documents4)
43
+ texts = texts1 + texts2 + texts3 + texts4
44
+
45
+ embeddings = OpenAIEmbeddings(model="text-embedding-ada-002")
46
+ vectordb = Chroma.from_documents(texts, embeddings)
47
+ llm = ChatOpenAI(model_name="gpt-3.5-turbo-16k", temperature=0.05)
48
+
49
+ qa = RetrievalQA.from_chain_type(
50
+ llm=llm,
51
+ chain_type="stuff",
52
+ retriever=vectordb.as_retriever(),
53
+ return_source_documents=True)
54
+
55
+ import shutil
56
+ def save_image_filepath(filepath: str):
57
+ print(filepath)
58
+ # γ‚€γƒ‘γƒΌγ‚Έγ‚’δΏε­˜
59
+ _, file_extension = os.path.splitext(filepath)
60
+ shutil.copy(filepath, './filepath{}'.format(file_extension))
61
+ pass
62
+
63
+ with gr.Blocks() as demo:
64
+ chatbot = gr.Chatbot()
65
+ # with gr.Row():
66
+ # with gr.Column():
67
+ # image_input_filepath = gr.Image(type='filepath')
68
+ # image_button_filepath = gr.Button("filepath")
69
+
70
+ # image_button_filepath.click(save_image_filepath, inputs=image_input_filepath)
71
+
72
+ msg = gr.Textbox()
73
+
74
+ def user(user_message, history):
75
+ reply2 = qa(user_message)
76
+ reply=reply2['result']
77
+
78
+ for sd in reply2["source_documents"]:
79
+ page_content = str(sd.page_content)
80
+ source = str(sd.metadata["source"])
81
+ page = str(sd.metadata["page"]+1).zfill(3)
82
+ print("PDF:" + source)
83
+ print("γƒšγƒΌγ‚ΈοΌš" + page)
84
+
85
+ reply = reply + '<a href="https://dcs.mediapress-net.com/iportal/cv.do?c=20958580000&pg=108&v=MIW10001&d=LINK_MIW">link</a>'
86
+
87
+ return "", history + [[user_message, reply]]
88
+
89
+ def bot(history):
90
+ yield history
91
+ # save_image_filepath("./IMG_yosuke2.jpg")
92
+
93
+ msg.submit(user, [msg, chatbot], [msg, chatbot], queue=True).then(
94
+ bot, chatbot, chatbot
95
+ )
96
+
97
+ demo.queue()
98
+ demo.launch(share=True)
requirements.txt ADDED
Binary file (6.49 kB). View file
 
ηΎŽε’Œγƒ­γƒƒγ‚―η·εˆγ‚«γ‚Ώγƒ­γ‚°η¬¬31η‰ˆ_ε‰εŠ.pdf ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:d80f5dc28cd581b4811c24de29b98524856292e196a430c7d360c511363c1889
3
+ size 168321766
ηΎŽε’Œγƒ­γƒƒγ‚―η·εˆγ‚«γ‚Ώγƒ­γ‚°η¬¬31η‰ˆ_後半.pdf ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:ebe14b6c3d2a83c3da76e85427b492678802549093442b78790174dcf42ae385
3
+ size 88753140