peinan
commited on
Commit
•
7635174
0
Parent(s):
add basic UI and simple bot response
Browse files- .gitignore +13 -0
- .python-version +1 -0
- README.md +3 -0
- data/sample.pdf +0 -0
- data/sample.txt +1 -0
- pyproject.toml +34 -0
- requirements-dev.lock +278 -0
- requirements.lock +243 -0
- src/pdfchat/app.py +114 -0
.gitignore
ADDED
@@ -0,0 +1,13 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
# python generated files
|
2 |
+
__pycache__/
|
3 |
+
*.py[oc]
|
4 |
+
build/
|
5 |
+
dist/
|
6 |
+
wheels/
|
7 |
+
*.egg-info
|
8 |
+
|
9 |
+
# venv
|
10 |
+
.venv
|
11 |
+
|
12 |
+
.DS_Store
|
13 |
+
gradio_cached_examples
|
.python-version
ADDED
@@ -0,0 +1 @@
|
|
|
|
|
1 |
+
3.12.1
|
README.md
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
# pdfchat
|
2 |
+
|
3 |
+
Describe your project here.
|
data/sample.pdf
ADDED
Binary file (204 kB). View file
|
|
data/sample.txt
ADDED
@@ -0,0 +1 @@
|
|
|
|
|
1 |
+
hello
|
pyproject.toml
ADDED
@@ -0,0 +1,34 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
[project]
|
2 |
+
name = "pdfchat"
|
3 |
+
version = "0.1.0"
|
4 |
+
description = "Add your description here"
|
5 |
+
authors = [
|
6 |
+
{ name = "Peinan Zhang", email = "[email protected]" }
|
7 |
+
]
|
8 |
+
dependencies = [
|
9 |
+
"gradio>=4.19.2",
|
10 |
+
"langchain>=0.1.9",
|
11 |
+
"gradio-pdf>=0.0.5",
|
12 |
+
]
|
13 |
+
readme = "README.md"
|
14 |
+
requires-python = ">= 3.8"
|
15 |
+
|
16 |
+
[build-system]
|
17 |
+
requires = ["hatchling"]
|
18 |
+
build-backend = "hatchling.build"
|
19 |
+
|
20 |
+
[tool.rye]
|
21 |
+
managed = true
|
22 |
+
dev-dependencies = [
|
23 |
+
"icecream>=2.1.3",
|
24 |
+
"ipython>=8.22.1",
|
25 |
+
]
|
26 |
+
|
27 |
+
[tool.rye.scripts]
|
28 |
+
server = "python src/pdfchat/app.py"
|
29 |
+
|
30 |
+
[tool.hatch.metadata]
|
31 |
+
allow-direct-references = true
|
32 |
+
|
33 |
+
[tool.hatch.build.targets.wheel]
|
34 |
+
packages = ["src/pdfchat"]
|
requirements-dev.lock
ADDED
@@ -0,0 +1,278 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
# generated by rye
|
2 |
+
# use `rye lock` or `rye sync` to update this lockfile
|
3 |
+
#
|
4 |
+
# last locked with the following flags:
|
5 |
+
# pre: false
|
6 |
+
# features: []
|
7 |
+
# all-features: false
|
8 |
+
# with-sources: false
|
9 |
+
|
10 |
+
-e file:.
|
11 |
+
aiofiles==23.2.1
|
12 |
+
# via gradio
|
13 |
+
aiohttp==3.9.3
|
14 |
+
# via langchain
|
15 |
+
# via langchain-community
|
16 |
+
aiosignal==1.3.1
|
17 |
+
# via aiohttp
|
18 |
+
altair==5.2.0
|
19 |
+
# via gradio
|
20 |
+
annotated-types==0.6.0
|
21 |
+
# via pydantic
|
22 |
+
anyio==4.3.0
|
23 |
+
# via httpx
|
24 |
+
# via langchain-core
|
25 |
+
# via starlette
|
26 |
+
asttokens==2.4.1
|
27 |
+
# via icecream
|
28 |
+
# via stack-data
|
29 |
+
attrs==23.2.0
|
30 |
+
# via aiohttp
|
31 |
+
# via jsonschema
|
32 |
+
# via referencing
|
33 |
+
certifi==2024.2.2
|
34 |
+
# via httpcore
|
35 |
+
# via httpx
|
36 |
+
# via requests
|
37 |
+
charset-normalizer==3.3.2
|
38 |
+
# via requests
|
39 |
+
click==8.1.7
|
40 |
+
# via typer
|
41 |
+
# via uvicorn
|
42 |
+
colorama==0.4.6
|
43 |
+
# via icecream
|
44 |
+
# via typer
|
45 |
+
contourpy==1.2.0
|
46 |
+
# via matplotlib
|
47 |
+
cycler==0.12.1
|
48 |
+
# via matplotlib
|
49 |
+
dataclasses-json==0.6.4
|
50 |
+
# via langchain
|
51 |
+
# via langchain-community
|
52 |
+
decorator==5.1.1
|
53 |
+
# via ipython
|
54 |
+
executing==2.0.1
|
55 |
+
# via icecream
|
56 |
+
# via stack-data
|
57 |
+
fastapi==0.110.0
|
58 |
+
# via gradio
|
59 |
+
ffmpy==0.3.2
|
60 |
+
# via gradio
|
61 |
+
filelock==3.13.1
|
62 |
+
# via huggingface-hub
|
63 |
+
fonttools==4.49.0
|
64 |
+
# via matplotlib
|
65 |
+
frozenlist==1.4.1
|
66 |
+
# via aiohttp
|
67 |
+
# via aiosignal
|
68 |
+
fsspec==2024.2.0
|
69 |
+
# via gradio-client
|
70 |
+
# via huggingface-hub
|
71 |
+
gradio==4.19.2
|
72 |
+
# via gradio-pdf
|
73 |
+
# via pdfchat
|
74 |
+
gradio-client==0.10.1
|
75 |
+
# via gradio
|
76 |
+
gradio-pdf==0.0.5
|
77 |
+
# via pdfchat
|
78 |
+
h11==0.14.0
|
79 |
+
# via httpcore
|
80 |
+
# via uvicorn
|
81 |
+
httpcore==1.0.4
|
82 |
+
# via httpx
|
83 |
+
httpx==0.27.0
|
84 |
+
# via gradio
|
85 |
+
# via gradio-client
|
86 |
+
huggingface-hub==0.20.3
|
87 |
+
# via gradio
|
88 |
+
# via gradio-client
|
89 |
+
icecream==2.1.3
|
90 |
+
idna==3.6
|
91 |
+
# via anyio
|
92 |
+
# via httpx
|
93 |
+
# via requests
|
94 |
+
# via yarl
|
95 |
+
importlib-resources==6.1.1
|
96 |
+
# via gradio
|
97 |
+
ipython==8.22.1
|
98 |
+
jedi==0.19.1
|
99 |
+
# via ipython
|
100 |
+
jinja2==3.1.3
|
101 |
+
# via altair
|
102 |
+
# via gradio
|
103 |
+
jsonpatch==1.33
|
104 |
+
# via langchain
|
105 |
+
# via langchain-core
|
106 |
+
jsonpointer==2.4
|
107 |
+
# via jsonpatch
|
108 |
+
jsonschema==4.21.1
|
109 |
+
# via altair
|
110 |
+
jsonschema-specifications==2023.12.1
|
111 |
+
# via jsonschema
|
112 |
+
kiwisolver==1.4.5
|
113 |
+
# via matplotlib
|
114 |
+
langchain==0.1.9
|
115 |
+
# via pdfchat
|
116 |
+
langchain-community==0.0.24
|
117 |
+
# via langchain
|
118 |
+
langchain-core==0.1.26
|
119 |
+
# via langchain
|
120 |
+
# via langchain-community
|
121 |
+
langsmith==0.1.8
|
122 |
+
# via langchain
|
123 |
+
# via langchain-community
|
124 |
+
# via langchain-core
|
125 |
+
markdown-it-py==3.0.0
|
126 |
+
# via rich
|
127 |
+
markupsafe==2.1.5
|
128 |
+
# via gradio
|
129 |
+
# via jinja2
|
130 |
+
marshmallow==3.20.2
|
131 |
+
# via dataclasses-json
|
132 |
+
matplotlib==3.8.3
|
133 |
+
# via gradio
|
134 |
+
matplotlib-inline==0.1.6
|
135 |
+
# via ipython
|
136 |
+
mdurl==0.1.2
|
137 |
+
# via markdown-it-py
|
138 |
+
multidict==6.0.5
|
139 |
+
# via aiohttp
|
140 |
+
# via yarl
|
141 |
+
mypy-extensions==1.0.0
|
142 |
+
# via typing-inspect
|
143 |
+
numpy==1.26.4
|
144 |
+
# via altair
|
145 |
+
# via contourpy
|
146 |
+
# via gradio
|
147 |
+
# via langchain
|
148 |
+
# via langchain-community
|
149 |
+
# via matplotlib
|
150 |
+
# via pandas
|
151 |
+
orjson==3.9.15
|
152 |
+
# via gradio
|
153 |
+
# via langsmith
|
154 |
+
packaging==23.2
|
155 |
+
# via altair
|
156 |
+
# via gradio
|
157 |
+
# via gradio-client
|
158 |
+
# via huggingface-hub
|
159 |
+
# via langchain-core
|
160 |
+
# via marshmallow
|
161 |
+
# via matplotlib
|
162 |
+
pandas==2.2.1
|
163 |
+
# via altair
|
164 |
+
# via gradio
|
165 |
+
parso==0.8.3
|
166 |
+
# via jedi
|
167 |
+
pexpect==4.9.0
|
168 |
+
# via ipython
|
169 |
+
pillow==10.2.0
|
170 |
+
# via gradio
|
171 |
+
# via matplotlib
|
172 |
+
prompt-toolkit==3.0.43
|
173 |
+
# via ipython
|
174 |
+
ptyprocess==0.7.0
|
175 |
+
# via pexpect
|
176 |
+
pure-eval==0.2.2
|
177 |
+
# via stack-data
|
178 |
+
pydantic==2.6.2
|
179 |
+
# via fastapi
|
180 |
+
# via gradio
|
181 |
+
# via langchain
|
182 |
+
# via langchain-core
|
183 |
+
# via langsmith
|
184 |
+
pydantic-core==2.16.3
|
185 |
+
# via pydantic
|
186 |
+
pydub==0.25.1
|
187 |
+
# via gradio
|
188 |
+
pygments==2.17.2
|
189 |
+
# via icecream
|
190 |
+
# via ipython
|
191 |
+
# via rich
|
192 |
+
pyparsing==3.1.1
|
193 |
+
# via matplotlib
|
194 |
+
python-dateutil==2.8.2
|
195 |
+
# via matplotlib
|
196 |
+
# via pandas
|
197 |
+
python-multipart==0.0.9
|
198 |
+
# via gradio
|
199 |
+
pytz==2024.1
|
200 |
+
# via pandas
|
201 |
+
pyyaml==6.0.1
|
202 |
+
# via gradio
|
203 |
+
# via huggingface-hub
|
204 |
+
# via langchain
|
205 |
+
# via langchain-community
|
206 |
+
# via langchain-core
|
207 |
+
referencing==0.33.0
|
208 |
+
# via jsonschema
|
209 |
+
# via jsonschema-specifications
|
210 |
+
requests==2.31.0
|
211 |
+
# via huggingface-hub
|
212 |
+
# via langchain
|
213 |
+
# via langchain-community
|
214 |
+
# via langchain-core
|
215 |
+
# via langsmith
|
216 |
+
rich==13.7.0
|
217 |
+
# via typer
|
218 |
+
rpds-py==0.18.0
|
219 |
+
# via jsonschema
|
220 |
+
# via referencing
|
221 |
+
ruff==0.2.2
|
222 |
+
# via gradio
|
223 |
+
semantic-version==2.10.0
|
224 |
+
# via gradio
|
225 |
+
shellingham==1.5.4
|
226 |
+
# via typer
|
227 |
+
six==1.16.0
|
228 |
+
# via asttokens
|
229 |
+
# via python-dateutil
|
230 |
+
sniffio==1.3.0
|
231 |
+
# via anyio
|
232 |
+
# via httpx
|
233 |
+
sqlalchemy==2.0.27
|
234 |
+
# via langchain
|
235 |
+
# via langchain-community
|
236 |
+
stack-data==0.6.3
|
237 |
+
# via ipython
|
238 |
+
starlette==0.36.3
|
239 |
+
# via fastapi
|
240 |
+
tenacity==8.2.3
|
241 |
+
# via langchain
|
242 |
+
# via langchain-community
|
243 |
+
# via langchain-core
|
244 |
+
tomlkit==0.12.0
|
245 |
+
# via gradio
|
246 |
+
toolz==0.12.1
|
247 |
+
# via altair
|
248 |
+
tqdm==4.66.2
|
249 |
+
# via huggingface-hub
|
250 |
+
traitlets==5.14.1
|
251 |
+
# via ipython
|
252 |
+
# via matplotlib-inline
|
253 |
+
typer==0.9.0
|
254 |
+
# via gradio
|
255 |
+
typing-extensions==4.9.0
|
256 |
+
# via fastapi
|
257 |
+
# via gradio
|
258 |
+
# via gradio-client
|
259 |
+
# via huggingface-hub
|
260 |
+
# via pydantic
|
261 |
+
# via pydantic-core
|
262 |
+
# via sqlalchemy
|
263 |
+
# via typer
|
264 |
+
# via typing-inspect
|
265 |
+
typing-inspect==0.9.0
|
266 |
+
# via dataclasses-json
|
267 |
+
tzdata==2024.1
|
268 |
+
# via pandas
|
269 |
+
urllib3==2.2.1
|
270 |
+
# via requests
|
271 |
+
uvicorn==0.27.1
|
272 |
+
# via gradio
|
273 |
+
wcwidth==0.2.13
|
274 |
+
# via prompt-toolkit
|
275 |
+
websockets==11.0.3
|
276 |
+
# via gradio-client
|
277 |
+
yarl==1.9.4
|
278 |
+
# via aiohttp
|
requirements.lock
ADDED
@@ -0,0 +1,243 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
# generated by rye
|
2 |
+
# use `rye lock` or `rye sync` to update this lockfile
|
3 |
+
#
|
4 |
+
# last locked with the following flags:
|
5 |
+
# pre: false
|
6 |
+
# features: []
|
7 |
+
# all-features: false
|
8 |
+
# with-sources: false
|
9 |
+
|
10 |
+
-e file:.
|
11 |
+
aiofiles==23.2.1
|
12 |
+
# via gradio
|
13 |
+
aiohttp==3.9.3
|
14 |
+
# via langchain
|
15 |
+
# via langchain-community
|
16 |
+
aiosignal==1.3.1
|
17 |
+
# via aiohttp
|
18 |
+
altair==5.2.0
|
19 |
+
# via gradio
|
20 |
+
annotated-types==0.6.0
|
21 |
+
# via pydantic
|
22 |
+
anyio==4.3.0
|
23 |
+
# via httpx
|
24 |
+
# via langchain-core
|
25 |
+
# via starlette
|
26 |
+
attrs==23.2.0
|
27 |
+
# via aiohttp
|
28 |
+
# via jsonschema
|
29 |
+
# via referencing
|
30 |
+
certifi==2024.2.2
|
31 |
+
# via httpcore
|
32 |
+
# via httpx
|
33 |
+
# via requests
|
34 |
+
charset-normalizer==3.3.2
|
35 |
+
# via requests
|
36 |
+
click==8.1.7
|
37 |
+
# via typer
|
38 |
+
# via uvicorn
|
39 |
+
colorama==0.4.6
|
40 |
+
# via typer
|
41 |
+
contourpy==1.2.0
|
42 |
+
# via matplotlib
|
43 |
+
cycler==0.12.1
|
44 |
+
# via matplotlib
|
45 |
+
dataclasses-json==0.6.4
|
46 |
+
# via langchain
|
47 |
+
# via langchain-community
|
48 |
+
fastapi==0.110.0
|
49 |
+
# via gradio
|
50 |
+
ffmpy==0.3.2
|
51 |
+
# via gradio
|
52 |
+
filelock==3.13.1
|
53 |
+
# via huggingface-hub
|
54 |
+
fonttools==4.49.0
|
55 |
+
# via matplotlib
|
56 |
+
frozenlist==1.4.1
|
57 |
+
# via aiohttp
|
58 |
+
# via aiosignal
|
59 |
+
fsspec==2024.2.0
|
60 |
+
# via gradio-client
|
61 |
+
# via huggingface-hub
|
62 |
+
gradio==4.19.2
|
63 |
+
# via gradio-pdf
|
64 |
+
# via pdfchat
|
65 |
+
gradio-client==0.10.1
|
66 |
+
# via gradio
|
67 |
+
gradio-pdf==0.0.5
|
68 |
+
# via pdfchat
|
69 |
+
h11==0.14.0
|
70 |
+
# via httpcore
|
71 |
+
# via uvicorn
|
72 |
+
httpcore==1.0.4
|
73 |
+
# via httpx
|
74 |
+
httpx==0.27.0
|
75 |
+
# via gradio
|
76 |
+
# via gradio-client
|
77 |
+
huggingface-hub==0.20.3
|
78 |
+
# via gradio
|
79 |
+
# via gradio-client
|
80 |
+
idna==3.6
|
81 |
+
# via anyio
|
82 |
+
# via httpx
|
83 |
+
# via requests
|
84 |
+
# via yarl
|
85 |
+
importlib-resources==6.1.1
|
86 |
+
# via gradio
|
87 |
+
jinja2==3.1.3
|
88 |
+
# via altair
|
89 |
+
# via gradio
|
90 |
+
jsonpatch==1.33
|
91 |
+
# via langchain
|
92 |
+
# via langchain-core
|
93 |
+
jsonpointer==2.4
|
94 |
+
# via jsonpatch
|
95 |
+
jsonschema==4.21.1
|
96 |
+
# via altair
|
97 |
+
jsonschema-specifications==2023.12.1
|
98 |
+
# via jsonschema
|
99 |
+
kiwisolver==1.4.5
|
100 |
+
# via matplotlib
|
101 |
+
langchain==0.1.9
|
102 |
+
# via pdfchat
|
103 |
+
langchain-community==0.0.24
|
104 |
+
# via langchain
|
105 |
+
langchain-core==0.1.26
|
106 |
+
# via langchain
|
107 |
+
# via langchain-community
|
108 |
+
langsmith==0.1.8
|
109 |
+
# via langchain
|
110 |
+
# via langchain-community
|
111 |
+
# via langchain-core
|
112 |
+
markdown-it-py==3.0.0
|
113 |
+
# via rich
|
114 |
+
markupsafe==2.1.5
|
115 |
+
# via gradio
|
116 |
+
# via jinja2
|
117 |
+
marshmallow==3.20.2
|
118 |
+
# via dataclasses-json
|
119 |
+
matplotlib==3.8.3
|
120 |
+
# via gradio
|
121 |
+
mdurl==0.1.2
|
122 |
+
# via markdown-it-py
|
123 |
+
multidict==6.0.5
|
124 |
+
# via aiohttp
|
125 |
+
# via yarl
|
126 |
+
mypy-extensions==1.0.0
|
127 |
+
# via typing-inspect
|
128 |
+
numpy==1.26.4
|
129 |
+
# via altair
|
130 |
+
# via contourpy
|
131 |
+
# via gradio
|
132 |
+
# via langchain
|
133 |
+
# via langchain-community
|
134 |
+
# via matplotlib
|
135 |
+
# via pandas
|
136 |
+
orjson==3.9.15
|
137 |
+
# via gradio
|
138 |
+
# via langsmith
|
139 |
+
packaging==23.2
|
140 |
+
# via altair
|
141 |
+
# via gradio
|
142 |
+
# via gradio-client
|
143 |
+
# via huggingface-hub
|
144 |
+
# via langchain-core
|
145 |
+
# via marshmallow
|
146 |
+
# via matplotlib
|
147 |
+
pandas==2.2.1
|
148 |
+
# via altair
|
149 |
+
# via gradio
|
150 |
+
pillow==10.2.0
|
151 |
+
# via gradio
|
152 |
+
# via matplotlib
|
153 |
+
pydantic==2.6.2
|
154 |
+
# via fastapi
|
155 |
+
# via gradio
|
156 |
+
# via langchain
|
157 |
+
# via langchain-core
|
158 |
+
# via langsmith
|
159 |
+
pydantic-core==2.16.3
|
160 |
+
# via pydantic
|
161 |
+
pydub==0.25.1
|
162 |
+
# via gradio
|
163 |
+
pygments==2.17.2
|
164 |
+
# via rich
|
165 |
+
pyparsing==3.1.1
|
166 |
+
# via matplotlib
|
167 |
+
python-dateutil==2.8.2
|
168 |
+
# via matplotlib
|
169 |
+
# via pandas
|
170 |
+
python-multipart==0.0.9
|
171 |
+
# via gradio
|
172 |
+
pytz==2024.1
|
173 |
+
# via pandas
|
174 |
+
pyyaml==6.0.1
|
175 |
+
# via gradio
|
176 |
+
# via huggingface-hub
|
177 |
+
# via langchain
|
178 |
+
# via langchain-community
|
179 |
+
# via langchain-core
|
180 |
+
referencing==0.33.0
|
181 |
+
# via jsonschema
|
182 |
+
# via jsonschema-specifications
|
183 |
+
requests==2.31.0
|
184 |
+
# via huggingface-hub
|
185 |
+
# via langchain
|
186 |
+
# via langchain-community
|
187 |
+
# via langchain-core
|
188 |
+
# via langsmith
|
189 |
+
rich==13.7.0
|
190 |
+
# via typer
|
191 |
+
rpds-py==0.18.0
|
192 |
+
# via jsonschema
|
193 |
+
# via referencing
|
194 |
+
ruff==0.2.2
|
195 |
+
# via gradio
|
196 |
+
semantic-version==2.10.0
|
197 |
+
# via gradio
|
198 |
+
shellingham==1.5.4
|
199 |
+
# via typer
|
200 |
+
six==1.16.0
|
201 |
+
# via python-dateutil
|
202 |
+
sniffio==1.3.0
|
203 |
+
# via anyio
|
204 |
+
# via httpx
|
205 |
+
sqlalchemy==2.0.27
|
206 |
+
# via langchain
|
207 |
+
# via langchain-community
|
208 |
+
starlette==0.36.3
|
209 |
+
# via fastapi
|
210 |
+
tenacity==8.2.3
|
211 |
+
# via langchain
|
212 |
+
# via langchain-community
|
213 |
+
# via langchain-core
|
214 |
+
tomlkit==0.12.0
|
215 |
+
# via gradio
|
216 |
+
toolz==0.12.1
|
217 |
+
# via altair
|
218 |
+
tqdm==4.66.2
|
219 |
+
# via huggingface-hub
|
220 |
+
typer==0.9.0
|
221 |
+
# via gradio
|
222 |
+
typing-extensions==4.9.0
|
223 |
+
# via fastapi
|
224 |
+
# via gradio
|
225 |
+
# via gradio-client
|
226 |
+
# via huggingface-hub
|
227 |
+
# via pydantic
|
228 |
+
# via pydantic-core
|
229 |
+
# via sqlalchemy
|
230 |
+
# via typer
|
231 |
+
# via typing-inspect
|
232 |
+
typing-inspect==0.9.0
|
233 |
+
# via dataclasses-json
|
234 |
+
tzdata==2024.1
|
235 |
+
# via pandas
|
236 |
+
urllib3==2.2.1
|
237 |
+
# via requests
|
238 |
+
uvicorn==0.27.1
|
239 |
+
# via gradio
|
240 |
+
websockets==11.0.3
|
241 |
+
# via gradio-client
|
242 |
+
yarl==1.9.4
|
243 |
+
# via aiohttp
|
src/pdfchat/app.py
ADDED
@@ -0,0 +1,114 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import time
|
2 |
+
from dataclasses import dataclass
|
3 |
+
from pathlib import Path
|
4 |
+
|
5 |
+
import gradio as gr
|
6 |
+
from icecream import ic
|
7 |
+
|
8 |
+
MODEL_CALM2 = "cyberagent/calm2"
|
9 |
+
|
10 |
+
|
11 |
+
@dataclass
|
12 |
+
class Chat:
|
13 |
+
query: str
|
14 |
+
response: str | None
|
15 |
+
|
16 |
+
def to_list(self) -> list[str, str]:
|
17 |
+
return [self.query, self.response]
|
18 |
+
|
19 |
+
|
20 |
+
@dataclass
|
21 |
+
class ChatHistory:
|
22 |
+
history: list[Chat]
|
23 |
+
|
24 |
+
def __init__(self, history: list[tuple[str, str] | list[str, str]] | None = None):
|
25 |
+
if history is None:
|
26 |
+
self.history = []
|
27 |
+
else:
|
28 |
+
self.history = [Chat(*chat) for chat in history]
|
29 |
+
|
30 |
+
def __iter__(self):
|
31 |
+
return iter([chat.to_list() for chat in self.history])
|
32 |
+
|
33 |
+
def __getitem__(self, index: int) -> Chat:
|
34 |
+
return self.history[index]
|
35 |
+
|
36 |
+
def add_chat(self, chat: Chat):
|
37 |
+
self.history.append(chat)
|
38 |
+
|
39 |
+
|
40 |
+
def open_file(file_path: str) -> str:
|
41 |
+
file_path = Path(file_path)
|
42 |
+
if file_path.suffix == ".txt":
|
43 |
+
text = file_path.read_text()
|
44 |
+
elif file_path.suffix == ".pdf":
|
45 |
+
text = "WARNING: PDF file is not supported yet."
|
46 |
+
else:
|
47 |
+
gr.exit("Unsupported file type.")
|
48 |
+
|
49 |
+
return text
|
50 |
+
|
51 |
+
|
52 |
+
def bot(history: ChatHistory, query: str, file_path: str) -> ChatHistory:
|
53 |
+
history = ChatHistory(history)
|
54 |
+
if not file_path:
|
55 |
+
history.add_chat(Chat(query=query, response=None))
|
56 |
+
return history
|
57 |
+
document = open_file(file_path)
|
58 |
+
history.add_chat(Chat(query=query, response=document))
|
59 |
+
ic(history)
|
60 |
+
|
61 |
+
# TODO: use streaming inference
|
62 |
+
return history
|
63 |
+
|
64 |
+
|
65 |
+
with gr.Blocks() as app:
|
66 |
+
with gr.Row():
|
67 |
+
with gr.Column(scale=0.4):
|
68 |
+
model_name = gr.Dropdown(
|
69 |
+
choices=[MODEL_CALM2],
|
70 |
+
value=MODEL_CALM2,
|
71 |
+
label="Model",
|
72 |
+
)
|
73 |
+
file_box = gr.File(
|
74 |
+
label="Document",
|
75 |
+
file_types=[".pdf", ".txt"],
|
76 |
+
file_count="single",
|
77 |
+
container=False,
|
78 |
+
)
|
79 |
+
gr.Examples(
|
80 |
+
examples=[["data/sample.txt"], ["data/sample.pdf"]],
|
81 |
+
inputs=[file_box],
|
82 |
+
outputs=[],
|
83 |
+
fn=lambda model_name, document: None,
|
84 |
+
)
|
85 |
+
with gr.Accordion("Parameters", open=False):
|
86 |
+
temperature_slider = gr.Slider(
|
87 |
+
minimum=0.1, maximum=1.0, value=0.5, label="Temperature"
|
88 |
+
)
|
89 |
+
temperature_slider.change(lambda x: x, [temperature_slider])
|
90 |
+
top_p_slider = gr.Slider(
|
91 |
+
minimum=0.1, maximum=1.0, value=0.5, label="Top P"
|
92 |
+
)
|
93 |
+
top_p_slider.change(lambda x: x, [top_p_slider])
|
94 |
+
with gr.Column(scale=0.6):
|
95 |
+
chatbot = gr.Chatbot(
|
96 |
+
bubble_full_width=False,
|
97 |
+
height=650,
|
98 |
+
)
|
99 |
+
ic(chatbot)
|
100 |
+
with gr.Row():
|
101 |
+
text_box = gr.Textbox(
|
102 |
+
scale=0.9,
|
103 |
+
show_label=False,
|
104 |
+
placeholder="Type your message here",
|
105 |
+
container=False,
|
106 |
+
)
|
107 |
+
submit_button = gr.Button("Submit", scale=0.1, variant="primary")
|
108 |
+
submit = submit_button.click(
|
109 |
+
fn=bot,
|
110 |
+
inputs=[chatbot, text_box, file_box],
|
111 |
+
outputs=chatbot,
|
112 |
+
)
|
113 |
+
|
114 |
+
app.queue().launch(debug=True)
|