curry tang commited on
Commit
1528aed
·
1 Parent(s): bc1aa2f
Files changed (5) hide show
  1. app.py +16 -13
  2. pyproject.toml +3 -4
  3. requirements-dev.lock +6 -31
  4. requirements.lock +6 -31
  5. requirements.txt +6 -31
app.py CHANGED
@@ -41,19 +41,21 @@ def predict(message, history, chat):
41
 
42
  if history_len == 0:
43
  history_messages.append(SystemMessage(content=web_prompt))
44
- if files_len == 0:
45
- history_messages.append(HumanMessage(content=message.text))
46
- else:
47
- file = message.files[0]
48
- with Image.open(file.path) as img:
49
- buffer = io.BytesIO()
50
- img = img.convert('RGB')
51
- img.save(buffer, format="JPEG")
52
- image_data = base64.b64encode(buffer.getvalue()).decode("utf-8")
53
- history_messages.append(HumanMessage(content=[
54
- {"type": "text", "text": message.text},
55
- {"type": "image_url", "image_url": {"url": f"data:image/jpeg;base64,{image_data}"}}
56
- ]))
 
 
57
 
58
  response_message = ''
59
  for chunk in chat.stream(history_messages):
@@ -201,6 +203,7 @@ with gr.Blocks() as app:
201
  predict,
202
  multimodal=True,
203
  chatbot=gr.Chatbot(elem_id="chatbot", height=600, show_share_button=False),
 
204
  additional_inputs=[chat_engine],
205
  )
206
  with gr.Column(scale=1, min_width=300):
 
41
 
42
  if history_len == 0:
43
  history_messages.append(SystemMessage(content=web_prompt))
44
+
45
+ history_messages.append(HumanMessage(content=message.text))
46
+ # if files_len == 0:
47
+ # history_messages.append(HumanMessage(content=message.text))
48
+ # else:
49
+ # file = message.files[0]
50
+ # with Image.open(file.path) as img:
51
+ # buffer = io.BytesIO()
52
+ # img = img.convert('RGB')
53
+ # img.save(buffer, format="JPEG")
54
+ # image_data = base64.b64encode(buffer.getvalue()).decode("utf-8")
55
+ # history_messages.append(HumanMessage(content=[
56
+ # {"type": "text", "text": message.text},
57
+ # {"type": "image_url", "image_url": {"url": f"data:image/jpeg;base64,{image_data}"}}
58
+ # ]))
59
 
60
  response_message = ''
61
  for chunk in chat.stream(history_messages):
 
203
  predict,
204
  multimodal=True,
205
  chatbot=gr.Chatbot(elem_id="chatbot", height=600, show_share_button=False),
206
+ textbox=gr.MultimodalTextbox(interactive=True, file_types=["image"]),
207
  additional_inputs=[chat_engine],
208
  )
209
  with gr.Column(scale=1, min_width=300):
pyproject.toml CHANGED
@@ -6,12 +6,11 @@ authors = [
6
  { name = "twn39", email = "[email protected]" }
7
  ]
8
  dependencies = [
9
- "gradio>=4.38.1",
10
- "langchain>=0.2.7",
11
  "pydantic>=2.8.2",
12
  "pydantic-settings>=2.3.4",
13
- "langchain-openai>=0.1.16",
14
- "dashscope>=1.20.1",
15
  "setuptools==69.5.1",
16
  ]
17
  readme = "README.md"
 
6
  { name = "twn39", email = "[email protected]" }
7
  ]
8
  dependencies = [
9
+ "gradio>=4.39.0",
10
+ "langchain>=0.2.11",
11
  "pydantic>=2.8.2",
12
  "pydantic-settings>=2.3.4",
13
+ "langchain-openai>=0.1.17",
 
14
  "setuptools==69.5.1",
15
  ]
16
  readme = "README.md"
requirements-dev.lock CHANGED
@@ -12,23 +12,19 @@
12
  aiofiles==23.2.1
13
  # via gradio
14
  aiohttp==3.9.5
15
- # via dashscope
16
  # via langchain
17
  aiosignal==1.3.1
18
  # via aiohttp
19
- altair==5.3.0
20
- # via gradio
21
  annotated-types==0.7.0
22
  # via pydantic
23
  anyio==4.4.0
 
24
  # via httpx
25
  # via openai
26
  # via starlette
27
  # via watchfiles
28
  attrs==23.2.0
29
  # via aiohttp
30
- # via jsonschema
31
- # via referencing
32
  certifi==2024.7.4
33
  # via httpcore
34
  # via httpx
@@ -42,8 +38,6 @@ contourpy==1.2.1
42
  # via matplotlib
43
  cycler==0.12.1
44
  # via matplotlib
45
- dashscope==1.20.1
46
- # via startship
47
  distro==1.9.0
48
  # via openai
49
  dnspython==2.6.1
@@ -66,9 +60,9 @@ frozenlist==1.4.1
66
  fsspec==2024.2.0
67
  # via gradio-client
68
  # via huggingface-hub
69
- gradio==4.38.1
70
  # via startship
71
- gradio-client==1.1.0
72
  # via gradio
73
  h11==0.14.0
74
  # via httpcore
@@ -94,26 +88,21 @@ idna==3.7
94
  importlib-resources==6.4.0
95
  # via gradio
96
  jinja2==3.1.4
97
- # via altair
98
  # via fastapi
99
  # via gradio
100
  jsonpatch==1.33
101
  # via langchain-core
102
  jsonpointer==3.0.0
103
  # via jsonpatch
104
- jsonschema==4.23.0
105
- # via altair
106
- jsonschema-specifications==2023.12.1
107
- # via jsonschema
108
  kiwisolver==1.4.5
109
  # via matplotlib
110
- langchain==0.2.7
111
  # via startship
112
- langchain-core==0.2.18
113
  # via langchain
114
  # via langchain-openai
115
  # via langchain-text-splitters
116
- langchain-openai==0.1.16
117
  # via startship
118
  langchain-text-splitters==0.2.2
119
  # via langchain
@@ -133,7 +122,6 @@ multidict==6.0.5
133
  # via aiohttp
134
  # via yarl
135
  numpy==1.26.4
136
- # via altair
137
  # via contourpy
138
  # via gradio
139
  # via langchain
@@ -146,14 +134,12 @@ orjson==3.10.6
146
  # via gradio
147
  # via langsmith
148
  packaging==24.1
149
- # via altair
150
  # via gradio
151
  # via gradio-client
152
  # via huggingface-hub
153
  # via langchain-core
154
  # via matplotlib
155
  pandas==2.2.2
156
- # via altair
157
  # via gradio
158
  pillow==10.4.0
159
  # via gradio
@@ -194,22 +180,15 @@ pyyaml==6.0.1
194
  # via langchain
195
  # via langchain-core
196
  # via uvicorn
197
- referencing==0.35.1
198
- # via jsonschema
199
- # via jsonschema-specifications
200
  regex==2024.5.15
201
  # via tiktoken
202
  requests==2.32.3
203
- # via dashscope
204
  # via huggingface-hub
205
  # via langchain
206
  # via langsmith
207
  # via tiktoken
208
  rich==13.7.1
209
  # via typer
210
- rpds-py==0.19.0
211
- # via jsonschema
212
- # via referencing
213
  ruff==0.5.1
214
  # via gradio
215
  semantic-version==2.10.0
@@ -235,8 +214,6 @@ tiktoken==0.7.0
235
  # via langchain-openai
236
  tomlkit==0.12.0
237
  # via gradio
238
- toolz==0.12.1
239
- # via altair
240
  tqdm==4.66.4
241
  # via huggingface-hub
242
  # via openai
@@ -267,8 +244,6 @@ uvloop==0.19.0
267
  # via uvicorn
268
  watchfiles==0.22.0
269
  # via uvicorn
270
- websocket-client==1.8.0
271
- # via dashscope
272
  websockets==11.0.3
273
  # via gradio-client
274
  # via uvicorn
 
12
  aiofiles==23.2.1
13
  # via gradio
14
  aiohttp==3.9.5
 
15
  # via langchain
16
  aiosignal==1.3.1
17
  # via aiohttp
 
 
18
  annotated-types==0.7.0
19
  # via pydantic
20
  anyio==4.4.0
21
+ # via gradio
22
  # via httpx
23
  # via openai
24
  # via starlette
25
  # via watchfiles
26
  attrs==23.2.0
27
  # via aiohttp
 
 
28
  certifi==2024.7.4
29
  # via httpcore
30
  # via httpx
 
38
  # via matplotlib
39
  cycler==0.12.1
40
  # via matplotlib
 
 
41
  distro==1.9.0
42
  # via openai
43
  dnspython==2.6.1
 
60
  fsspec==2024.2.0
61
  # via gradio-client
62
  # via huggingface-hub
63
+ gradio==4.39.0
64
  # via startship
65
+ gradio-client==1.1.1
66
  # via gradio
67
  h11==0.14.0
68
  # via httpcore
 
88
  importlib-resources==6.4.0
89
  # via gradio
90
  jinja2==3.1.4
 
91
  # via fastapi
92
  # via gradio
93
  jsonpatch==1.33
94
  # via langchain-core
95
  jsonpointer==3.0.0
96
  # via jsonpatch
 
 
 
 
97
  kiwisolver==1.4.5
98
  # via matplotlib
99
+ langchain==0.2.11
100
  # via startship
101
+ langchain-core==0.2.23
102
  # via langchain
103
  # via langchain-openai
104
  # via langchain-text-splitters
105
+ langchain-openai==0.1.17
106
  # via startship
107
  langchain-text-splitters==0.2.2
108
  # via langchain
 
122
  # via aiohttp
123
  # via yarl
124
  numpy==1.26.4
 
125
  # via contourpy
126
  # via gradio
127
  # via langchain
 
134
  # via gradio
135
  # via langsmith
136
  packaging==24.1
 
137
  # via gradio
138
  # via gradio-client
139
  # via huggingface-hub
140
  # via langchain-core
141
  # via matplotlib
142
  pandas==2.2.2
 
143
  # via gradio
144
  pillow==10.4.0
145
  # via gradio
 
180
  # via langchain
181
  # via langchain-core
182
  # via uvicorn
 
 
 
183
  regex==2024.5.15
184
  # via tiktoken
185
  requests==2.32.3
 
186
  # via huggingface-hub
187
  # via langchain
188
  # via langsmith
189
  # via tiktoken
190
  rich==13.7.1
191
  # via typer
 
 
 
192
  ruff==0.5.1
193
  # via gradio
194
  semantic-version==2.10.0
 
214
  # via langchain-openai
215
  tomlkit==0.12.0
216
  # via gradio
 
 
217
  tqdm==4.66.4
218
  # via huggingface-hub
219
  # via openai
 
244
  # via uvicorn
245
  watchfiles==0.22.0
246
  # via uvicorn
 
 
247
  websockets==11.0.3
248
  # via gradio-client
249
  # via uvicorn
requirements.lock CHANGED
@@ -12,23 +12,19 @@
12
  aiofiles==23.2.1
13
  # via gradio
14
  aiohttp==3.9.5
15
- # via dashscope
16
  # via langchain
17
  aiosignal==1.3.1
18
  # via aiohttp
19
- altair==5.3.0
20
- # via gradio
21
  annotated-types==0.7.0
22
  # via pydantic
23
  anyio==4.4.0
 
24
  # via httpx
25
  # via openai
26
  # via starlette
27
  # via watchfiles
28
  attrs==23.2.0
29
  # via aiohttp
30
- # via jsonschema
31
- # via referencing
32
  certifi==2024.7.4
33
  # via httpcore
34
  # via httpx
@@ -42,8 +38,6 @@ contourpy==1.2.1
42
  # via matplotlib
43
  cycler==0.12.1
44
  # via matplotlib
45
- dashscope==1.20.1
46
- # via startship
47
  distro==1.9.0
48
  # via openai
49
  dnspython==2.6.1
@@ -66,9 +60,9 @@ frozenlist==1.4.1
66
  fsspec==2024.2.0
67
  # via gradio-client
68
  # via huggingface-hub
69
- gradio==4.38.1
70
  # via startship
71
- gradio-client==1.1.0
72
  # via gradio
73
  h11==0.14.0
74
  # via httpcore
@@ -94,26 +88,21 @@ idna==3.7
94
  importlib-resources==6.4.0
95
  # via gradio
96
  jinja2==3.1.4
97
- # via altair
98
  # via fastapi
99
  # via gradio
100
  jsonpatch==1.33
101
  # via langchain-core
102
  jsonpointer==3.0.0
103
  # via jsonpatch
104
- jsonschema==4.23.0
105
- # via altair
106
- jsonschema-specifications==2023.12.1
107
- # via jsonschema
108
  kiwisolver==1.4.5
109
  # via matplotlib
110
- langchain==0.2.7
111
  # via startship
112
- langchain-core==0.2.18
113
  # via langchain
114
  # via langchain-openai
115
  # via langchain-text-splitters
116
- langchain-openai==0.1.16
117
  # via startship
118
  langchain-text-splitters==0.2.2
119
  # via langchain
@@ -133,7 +122,6 @@ multidict==6.0.5
133
  # via aiohttp
134
  # via yarl
135
  numpy==1.26.4
136
- # via altair
137
  # via contourpy
138
  # via gradio
139
  # via langchain
@@ -146,14 +134,12 @@ orjson==3.10.6
146
  # via gradio
147
  # via langsmith
148
  packaging==24.1
149
- # via altair
150
  # via gradio
151
  # via gradio-client
152
  # via huggingface-hub
153
  # via langchain-core
154
  # via matplotlib
155
  pandas==2.2.2
156
- # via altair
157
  # via gradio
158
  pillow==10.4.0
159
  # via gradio
@@ -194,22 +180,15 @@ pyyaml==6.0.1
194
  # via langchain
195
  # via langchain-core
196
  # via uvicorn
197
- referencing==0.35.1
198
- # via jsonschema
199
- # via jsonschema-specifications
200
  regex==2024.5.15
201
  # via tiktoken
202
  requests==2.32.3
203
- # via dashscope
204
  # via huggingface-hub
205
  # via langchain
206
  # via langsmith
207
  # via tiktoken
208
  rich==13.7.1
209
  # via typer
210
- rpds-py==0.19.0
211
- # via jsonschema
212
- # via referencing
213
  ruff==0.5.1
214
  # via gradio
215
  semantic-version==2.10.0
@@ -235,8 +214,6 @@ tiktoken==0.7.0
235
  # via langchain-openai
236
  tomlkit==0.12.0
237
  # via gradio
238
- toolz==0.12.1
239
- # via altair
240
  tqdm==4.66.4
241
  # via huggingface-hub
242
  # via openai
@@ -267,8 +244,6 @@ uvloop==0.19.0
267
  # via uvicorn
268
  watchfiles==0.22.0
269
  # via uvicorn
270
- websocket-client==1.8.0
271
- # via dashscope
272
  websockets==11.0.3
273
  # via gradio-client
274
  # via uvicorn
 
12
  aiofiles==23.2.1
13
  # via gradio
14
  aiohttp==3.9.5
 
15
  # via langchain
16
  aiosignal==1.3.1
17
  # via aiohttp
 
 
18
  annotated-types==0.7.0
19
  # via pydantic
20
  anyio==4.4.0
21
+ # via gradio
22
  # via httpx
23
  # via openai
24
  # via starlette
25
  # via watchfiles
26
  attrs==23.2.0
27
  # via aiohttp
 
 
28
  certifi==2024.7.4
29
  # via httpcore
30
  # via httpx
 
38
  # via matplotlib
39
  cycler==0.12.1
40
  # via matplotlib
 
 
41
  distro==1.9.0
42
  # via openai
43
  dnspython==2.6.1
 
60
  fsspec==2024.2.0
61
  # via gradio-client
62
  # via huggingface-hub
63
+ gradio==4.39.0
64
  # via startship
65
+ gradio-client==1.1.1
66
  # via gradio
67
  h11==0.14.0
68
  # via httpcore
 
88
  importlib-resources==6.4.0
89
  # via gradio
90
  jinja2==3.1.4
 
91
  # via fastapi
92
  # via gradio
93
  jsonpatch==1.33
94
  # via langchain-core
95
  jsonpointer==3.0.0
96
  # via jsonpatch
 
 
 
 
97
  kiwisolver==1.4.5
98
  # via matplotlib
99
+ langchain==0.2.11
100
  # via startship
101
+ langchain-core==0.2.23
102
  # via langchain
103
  # via langchain-openai
104
  # via langchain-text-splitters
105
+ langchain-openai==0.1.17
106
  # via startship
107
  langchain-text-splitters==0.2.2
108
  # via langchain
 
122
  # via aiohttp
123
  # via yarl
124
  numpy==1.26.4
 
125
  # via contourpy
126
  # via gradio
127
  # via langchain
 
134
  # via gradio
135
  # via langsmith
136
  packaging==24.1
 
137
  # via gradio
138
  # via gradio-client
139
  # via huggingface-hub
140
  # via langchain-core
141
  # via matplotlib
142
  pandas==2.2.2
 
143
  # via gradio
144
  pillow==10.4.0
145
  # via gradio
 
180
  # via langchain
181
  # via langchain-core
182
  # via uvicorn
 
 
 
183
  regex==2024.5.15
184
  # via tiktoken
185
  requests==2.32.3
 
186
  # via huggingface-hub
187
  # via langchain
188
  # via langsmith
189
  # via tiktoken
190
  rich==13.7.1
191
  # via typer
 
 
 
192
  ruff==0.5.1
193
  # via gradio
194
  semantic-version==2.10.0
 
214
  # via langchain-openai
215
  tomlkit==0.12.0
216
  # via gradio
 
 
217
  tqdm==4.66.4
218
  # via huggingface-hub
219
  # via openai
 
244
  # via uvicorn
245
  watchfiles==0.22.0
246
  # via uvicorn
 
 
247
  websockets==11.0.3
248
  # via gradio-client
249
  # via uvicorn
requirements.txt CHANGED
@@ -11,23 +11,19 @@
11
  aiofiles==23.2.1
12
  # via gradio
13
  aiohttp==3.9.5
14
- # via dashscope
15
  # via langchain
16
  aiosignal==1.3.1
17
  # via aiohttp
18
- altair==5.3.0
19
- # via gradio
20
  annotated-types==0.7.0
21
  # via pydantic
22
  anyio==4.4.0
 
23
  # via httpx
24
  # via openai
25
  # via starlette
26
  # via watchfiles
27
  attrs==23.2.0
28
  # via aiohttp
29
- # via jsonschema
30
- # via referencing
31
  certifi==2024.7.4
32
  # via httpcore
33
  # via httpx
@@ -41,8 +37,6 @@ contourpy==1.2.1
41
  # via matplotlib
42
  cycler==0.12.1
43
  # via matplotlib
44
- dashscope==1.20.1
45
- # via startship
46
  distro==1.9.0
47
  # via openai
48
  dnspython==2.6.1
@@ -65,9 +59,9 @@ frozenlist==1.4.1
65
  fsspec==2024.2.0
66
  # via gradio-client
67
  # via huggingface-hub
68
- gradio==4.38.1
69
  # via startship
70
- gradio-client==1.1.0
71
  # via gradio
72
  h11==0.14.0
73
  # via httpcore
@@ -93,26 +87,21 @@ idna==3.7
93
  importlib-resources==6.4.0
94
  # via gradio
95
  jinja2==3.1.4
96
- # via altair
97
  # via fastapi
98
  # via gradio
99
  jsonpatch==1.33
100
  # via langchain-core
101
  jsonpointer==3.0.0
102
  # via jsonpatch
103
- jsonschema==4.23.0
104
- # via altair
105
- jsonschema-specifications==2023.12.1
106
- # via jsonschema
107
  kiwisolver==1.4.5
108
  # via matplotlib
109
- langchain==0.2.7
110
  # via startship
111
- langchain-core==0.2.18
112
  # via langchain
113
  # via langchain-openai
114
  # via langchain-text-splitters
115
- langchain-openai==0.1.16
116
  # via startship
117
  langchain-text-splitters==0.2.2
118
  # via langchain
@@ -132,7 +121,6 @@ multidict==6.0.5
132
  # via aiohttp
133
  # via yarl
134
  numpy==1.26.4
135
- # via altair
136
  # via contourpy
137
  # via gradio
138
  # via langchain
@@ -145,14 +133,12 @@ orjson==3.10.6
145
  # via gradio
146
  # via langsmith
147
  packaging==24.1
148
- # via altair
149
  # via gradio
150
  # via gradio-client
151
  # via huggingface-hub
152
  # via langchain-core
153
  # via matplotlib
154
  pandas==2.2.2
155
- # via altair
156
  # via gradio
157
  pillow==10.4.0
158
  # via gradio
@@ -193,22 +179,15 @@ pyyaml==6.0.1
193
  # via langchain
194
  # via langchain-core
195
  # via uvicorn
196
- referencing==0.35.1
197
- # via jsonschema
198
- # via jsonschema-specifications
199
  regex==2024.5.15
200
  # via tiktoken
201
  requests==2.32.3
202
- # via dashscope
203
  # via huggingface-hub
204
  # via langchain
205
  # via langsmith
206
  # via tiktoken
207
  rich==13.7.1
208
  # via typer
209
- rpds-py==0.19.0
210
- # via jsonschema
211
- # via referencing
212
  ruff==0.5.1
213
  # via gradio
214
  semantic-version==2.10.0
@@ -234,8 +213,6 @@ tiktoken==0.7.0
234
  # via langchain-openai
235
  tomlkit==0.12.0
236
  # via gradio
237
- toolz==0.12.1
238
- # via altair
239
  tqdm==4.66.4
240
  # via huggingface-hub
241
  # via openai
@@ -266,8 +243,6 @@ uvloop==0.19.0
266
  # via uvicorn
267
  watchfiles==0.22.0
268
  # via uvicorn
269
- websocket-client==1.8.0
270
- # via dashscope
271
  websockets==11.0.3
272
  # via gradio-client
273
  # via uvicorn
 
11
  aiofiles==23.2.1
12
  # via gradio
13
  aiohttp==3.9.5
 
14
  # via langchain
15
  aiosignal==1.3.1
16
  # via aiohttp
 
 
17
  annotated-types==0.7.0
18
  # via pydantic
19
  anyio==4.4.0
20
+ # via gradio
21
  # via httpx
22
  # via openai
23
  # via starlette
24
  # via watchfiles
25
  attrs==23.2.0
26
  # via aiohttp
 
 
27
  certifi==2024.7.4
28
  # via httpcore
29
  # via httpx
 
37
  # via matplotlib
38
  cycler==0.12.1
39
  # via matplotlib
 
 
40
  distro==1.9.0
41
  # via openai
42
  dnspython==2.6.1
 
59
  fsspec==2024.2.0
60
  # via gradio-client
61
  # via huggingface-hub
62
+ gradio==4.39.0
63
  # via startship
64
+ gradio-client==1.1.1
65
  # via gradio
66
  h11==0.14.0
67
  # via httpcore
 
87
  importlib-resources==6.4.0
88
  # via gradio
89
  jinja2==3.1.4
 
90
  # via fastapi
91
  # via gradio
92
  jsonpatch==1.33
93
  # via langchain-core
94
  jsonpointer==3.0.0
95
  # via jsonpatch
 
 
 
 
96
  kiwisolver==1.4.5
97
  # via matplotlib
98
+ langchain==0.2.11
99
  # via startship
100
+ langchain-core==0.2.23
101
  # via langchain
102
  # via langchain-openai
103
  # via langchain-text-splitters
104
+ langchain-openai==0.1.17
105
  # via startship
106
  langchain-text-splitters==0.2.2
107
  # via langchain
 
121
  # via aiohttp
122
  # via yarl
123
  numpy==1.26.4
 
124
  # via contourpy
125
  # via gradio
126
  # via langchain
 
133
  # via gradio
134
  # via langsmith
135
  packaging==24.1
 
136
  # via gradio
137
  # via gradio-client
138
  # via huggingface-hub
139
  # via langchain-core
140
  # via matplotlib
141
  pandas==2.2.2
 
142
  # via gradio
143
  pillow==10.4.0
144
  # via gradio
 
179
  # via langchain
180
  # via langchain-core
181
  # via uvicorn
 
 
 
182
  regex==2024.5.15
183
  # via tiktoken
184
  requests==2.32.3
 
185
  # via huggingface-hub
186
  # via langchain
187
  # via langsmith
188
  # via tiktoken
189
  rich==13.7.1
190
  # via typer
 
 
 
191
  ruff==0.5.1
192
  # via gradio
193
  semantic-version==2.10.0
 
213
  # via langchain-openai
214
  tomlkit==0.12.0
215
  # via gradio
 
 
216
  tqdm==4.66.4
217
  # via huggingface-hub
218
  # via openai
 
243
  # via uvicorn
244
  watchfiles==0.22.0
245
  # via uvicorn
 
 
246
  websockets==11.0.3
247
  # via gradio-client
248
  # via uvicorn