Spaces:
Running
Running
powerwarez
commited on
Commit
•
10c58c6
1
Parent(s):
f5e0028
Upload 7 files
Browse files- .gitattributes +1 -0
- app.py +65 -0
- db/1421bd68-8c9c-43d7-88da-a21aaec7146e/data_level0.bin +3 -0
- db/1421bd68-8c9c-43d7-88da-a21aaec7146e/header.bin +3 -0
- db/1421bd68-8c9c-43d7-88da-a21aaec7146e/length.bin +3 -0
- db/1421bd68-8c9c-43d7-88da-a21aaec7146e/link_lists.bin +3 -0
- db/chroma.sqlite3 +3 -0
- requirements.txt +136 -0
.gitattributes
CHANGED
@@ -33,3 +33,4 @@ 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 |
+
db/chroma.sqlite3 filter=lfs diff=lfs merge=lfs -text
|
app.py
ADDED
@@ -0,0 +1,65 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
from langchain_openai import OpenAIEmbeddings
|
2 |
+
from langchain_chroma import Chroma
|
3 |
+
from langchain_openai import ChatOpenAI
|
4 |
+
from langchain.chains import RetrievalQAWithSourcesChain
|
5 |
+
import gradio as gr
|
6 |
+
import os
|
7 |
+
from dotenv import load_dotenv
|
8 |
+
|
9 |
+
load_dotenv()
|
10 |
+
|
11 |
+
|
12 |
+
openai_api_key = os.getenv("OPENAI_API_KEY")
|
13 |
+
|
14 |
+
persist_directory = "db"
|
15 |
+
|
16 |
+
embeddings = OpenAIEmbeddings()
|
17 |
+
|
18 |
+
vector_store = Chroma(
|
19 |
+
persist_directory=persist_directory,
|
20 |
+
embedding_function=embeddings
|
21 |
+
)
|
22 |
+
retriever = vector_store.as_retriever(search_kwargs={"k": 3})
|
23 |
+
|
24 |
+
llm = ChatOpenAI(model_name="gpt-4o", temperature=0.1) # Modify model_name if you have access to GPT-4
|
25 |
+
|
26 |
+
chain = RetrievalQAWithSourcesChain.from_chain_type(
|
27 |
+
llm=llm,
|
28 |
+
chain_type="stuff",
|
29 |
+
retriever = retriever,
|
30 |
+
return_source_documents=True)
|
31 |
+
|
32 |
+
def respond(message, chat_history): # 채팅봇의 응답을 처리하는 함수를 정의합니다.
|
33 |
+
result = chain.invoke(message)
|
34 |
+
|
35 |
+
bot_message = '<strong>' + result['answer'] + '</strong><br><br>'
|
36 |
+
|
37 |
+
for i, doc in enumerate(result['source_documents']):
|
38 |
+
text = doc.page_content[0:500].replace('\n', ' ')
|
39 |
+
page = str(doc.metadata['page'])
|
40 |
+
bot_message += '[' + '관련내용:' + doc.page_content[0:500].replace('\n', ' ') + '...' + '] '
|
41 |
+
|
42 |
+
# 빨간색 스타일 적용
|
43 |
+
bot_message += '<span style="color:red;">' + doc.metadata['source'] + '</span>'
|
44 |
+
|
45 |
+
# 파란색 스타일 적용
|
46 |
+
bot_message += '<span style="color:blue;">' + '(' + page + '쪽)</span> '
|
47 |
+
|
48 |
+
chat_history.append((message, bot_message)) # 채팅 기록에 사용자의 메시지와 봇의 응답을 추가합니다.
|
49 |
+
|
50 |
+
return "", chat_history
|
51 |
+
|
52 |
+
with gr.Blocks() as demo: # gr.Blocks()를 사용하여 인터페이스를 생성합니다.
|
53 |
+
gr.Markdown("<div style='font-size: 30px; font-weight: bold;'>2023 유치원 생활기록부 QnA chatbot</div>")
|
54 |
+
chatbot = gr.Chatbot(label="채팅창") # '채팅창'이라는 레이블을 가진 채팅봇 컴포넌트를 생성합니다.
|
55 |
+
msg = gr.Textbox(label="입력") # '입력'이라는 레이블을 가진 텍스트박스를 생성합니다.
|
56 |
+
clear = gr.Button("초기화") # '초기화'라는 레이블을 가진 버튼을 생성합니다.
|
57 |
+
|
58 |
+
msg.submit(respond, [msg, chatbot], [msg, chatbot]) # 텍스트박스에 메시지를 입력하고 제출하면 respond 함수가 호출되도록 합니다.
|
59 |
+
clear.click(lambda: None, None, chatbot, queue=False) # '초기화' 버튼을 클릭하면 채팅 기록을 초기화합니다.
|
60 |
+
gr.Markdown("2023 유치원 생활기록부 기재요령 <a href='https://www.moe.go.kr/sn3hcv/doc.html?fn=65fcc64258de266d005f7156e03f04f2&rs=/upload/synap/202407/'>미리보기</a>")
|
61 |
+
gr.Markdown("2023 유치원 생활기록부 기재요령 다운로드 <a href='https://www.moe.go.kr/boardCnts/viewRenew.do?boardID=312&boardSeq=97281&lev=0&searchType=null&statusYN=W&page=1&s=moe&m=0301&opType=N'>이동하기</a>")
|
62 |
+
gr.Markdown("정확한 내용은 원본을 꼭 확인하시기 바랍니다.")
|
63 |
+
gr.Markdown('제작: 교사 서동성')
|
64 |
+
|
65 |
+
demo.launch() # 인터페이스를 실행합니다. 실행하면 사용자는 '입력' 텍스트박스에 메시지를 작성하고 제출할 수 있으며, '초기화' 버튼을 통해 채팅 기록을 초기화 할 수 있습니다.
|
db/1421bd68-8c9c-43d7-88da-a21aaec7146e/data_level0.bin
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:f18abd8c514282db82706e52b0a33ed659cd534e925a6f149deb7af9ce34bd8e
|
3 |
+
size 6284000
|
db/1421bd68-8c9c-43d7-88da-a21aaec7146e/header.bin
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:effaa959ce2b30070fdafc2fe82096fc46e4ee7561b75920dd3ce43d09679b21
|
3 |
+
size 100
|
db/1421bd68-8c9c-43d7-88da-a21aaec7146e/length.bin
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:fc19b1997119425765295aeab72d76faa6927d4f83985d328c26f20468d6cc76
|
3 |
+
size 4000
|
db/1421bd68-8c9c-43d7-88da-a21aaec7146e/link_lists.bin
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855
|
3 |
+
size 0
|
db/chroma.sqlite3
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:743b1d39ccd530beb250c80c98893b6bfd625bc6d3402b5bcdb75f2d05ced3ef
|
3 |
+
size 1941504
|
requirements.txt
ADDED
@@ -0,0 +1,136 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
aiofiles==23.2.1
|
2 |
+
aiohttp==3.9.5
|
3 |
+
aiosignal==1.3.1
|
4 |
+
annotated-types==0.7.0
|
5 |
+
anyio==4.4.0
|
6 |
+
asgiref==3.8.1
|
7 |
+
attrs==23.2.0
|
8 |
+
backoff==2.2.1
|
9 |
+
bcrypt==4.2.0
|
10 |
+
build==1.2.1
|
11 |
+
cachetools==5.4.0
|
12 |
+
certifi==2024.7.4
|
13 |
+
charset-normalizer==3.3.2
|
14 |
+
chroma-hnswlib==0.7.6
|
15 |
+
chromadb==0.5.5
|
16 |
+
click==8.1.7
|
17 |
+
coloredlogs==15.0.1
|
18 |
+
contourpy==1.2.1
|
19 |
+
cycler==0.12.1
|
20 |
+
dataclasses-json==0.6.7
|
21 |
+
Deprecated==1.2.14
|
22 |
+
distro==1.9.0
|
23 |
+
dnspython==2.6.1
|
24 |
+
email_validator==2.2.0
|
25 |
+
fastapi==0.111.1
|
26 |
+
fastapi-cli==0.0.4
|
27 |
+
ffmpy==0.3.2
|
28 |
+
filelock==3.15.4
|
29 |
+
flatbuffers==24.3.25
|
30 |
+
fonttools==4.53.1
|
31 |
+
frozenlist==1.4.1
|
32 |
+
fsspec==2024.6.1
|
33 |
+
google-auth==2.32.0
|
34 |
+
googleapis-common-protos==1.63.2
|
35 |
+
gradio==4.39.0
|
36 |
+
gradio_client==1.1.1
|
37 |
+
grpcio==1.65.1
|
38 |
+
h11==0.14.0
|
39 |
+
httpcore==1.0.5
|
40 |
+
httptools==0.6.1
|
41 |
+
httpx==0.27.0
|
42 |
+
huggingface-hub==0.24.2
|
43 |
+
humanfriendly==10.0
|
44 |
+
idna==3.7
|
45 |
+
importlib_metadata==8.0.0
|
46 |
+
importlib_resources==6.4.0
|
47 |
+
Jinja2==3.1.4
|
48 |
+
jsonpatch==1.33
|
49 |
+
jsonpointer==3.0.0
|
50 |
+
kiwisolver==1.4.5
|
51 |
+
kubernetes==30.1.0
|
52 |
+
langchain==0.2.11
|
53 |
+
langchain-chroma==0.1.2
|
54 |
+
langchain-community==0.2.10
|
55 |
+
langchain-core==0.2.23
|
56 |
+
langchain-openai==0.1.17
|
57 |
+
langchain-text-splitters==0.2.2
|
58 |
+
langsmith==0.1.93
|
59 |
+
markdown-it-py==3.0.0
|
60 |
+
MarkupSafe==2.1.5
|
61 |
+
marshmallow==3.21.3
|
62 |
+
matplotlib==3.9.1
|
63 |
+
mdurl==0.1.2
|
64 |
+
mmh3==4.1.0
|
65 |
+
monotonic==1.6
|
66 |
+
mpmath==1.3.0
|
67 |
+
multidict==6.0.5
|
68 |
+
mypy-extensions==1.0.0
|
69 |
+
numpy==1.26.4
|
70 |
+
oauthlib==3.2.2
|
71 |
+
onnxruntime==1.18.1
|
72 |
+
openai==1.37.0
|
73 |
+
opentelemetry-api==1.26.0
|
74 |
+
opentelemetry-exporter-otlp-proto-common==1.26.0
|
75 |
+
opentelemetry-exporter-otlp-proto-grpc==1.26.0
|
76 |
+
opentelemetry-instrumentation==0.47b0
|
77 |
+
opentelemetry-instrumentation-asgi==0.47b0
|
78 |
+
opentelemetry-instrumentation-fastapi==0.47b0
|
79 |
+
opentelemetry-proto==1.26.0
|
80 |
+
opentelemetry-sdk==1.26.0
|
81 |
+
opentelemetry-semantic-conventions==0.47b0
|
82 |
+
opentelemetry-util-http==0.47b0
|
83 |
+
orjson==3.10.6
|
84 |
+
overrides==7.7.0
|
85 |
+
packaging==24.1
|
86 |
+
pandas==2.2.2
|
87 |
+
pillow==10.4.0
|
88 |
+
posthog==3.5.0
|
89 |
+
protobuf==4.25.4
|
90 |
+
pyasn1==0.6.0
|
91 |
+
pyasn1_modules==0.4.0
|
92 |
+
pydantic==2.8.2
|
93 |
+
pydantic_core==2.20.1
|
94 |
+
pydub==0.25.1
|
95 |
+
Pygments==2.18.0
|
96 |
+
pyparsing==3.1.2
|
97 |
+
pypdf==4.3.1
|
98 |
+
PyPika==0.48.9
|
99 |
+
pyproject_hooks==1.1.0
|
100 |
+
python-dateutil==2.9.0.post0
|
101 |
+
python-dotenv==1.0.1
|
102 |
+
python-env==1.0.0
|
103 |
+
python-multipart==0.0.9
|
104 |
+
pytz==2024.1
|
105 |
+
PyYAML==6.0.1
|
106 |
+
regex==2024.7.24
|
107 |
+
requests==2.32.3
|
108 |
+
requests-oauthlib==2.0.0
|
109 |
+
rich==13.7.1
|
110 |
+
rsa==4.9
|
111 |
+
ruff==0.5.4
|
112 |
+
semantic-version==2.10.0
|
113 |
+
shellingham==1.5.4
|
114 |
+
six==1.16.0
|
115 |
+
sniffio==1.3.1
|
116 |
+
SQLAlchemy==2.0.31
|
117 |
+
starlette==0.37.2
|
118 |
+
sympy==1.13.1
|
119 |
+
tenacity==8.5.0
|
120 |
+
tiktoken==0.7.0
|
121 |
+
tokenizers==0.19.1
|
122 |
+
tomlkit==0.12.0
|
123 |
+
tqdm==4.66.4
|
124 |
+
typer==0.12.3
|
125 |
+
typing-inspect==0.9.0
|
126 |
+
typing_extensions==4.12.2
|
127 |
+
tzdata==2024.1
|
128 |
+
urllib3==2.2.2
|
129 |
+
uvicorn==0.30.3
|
130 |
+
uvloop==0.19.0
|
131 |
+
watchfiles==0.22.0
|
132 |
+
websocket-client==1.8.0
|
133 |
+
websockets==11.0.3
|
134 |
+
wrapt==1.16.0
|
135 |
+
yarl==1.9.4
|
136 |
+
zipp==3.19.2
|