curry tang
commited on
Commit
·
bc1aa2f
1
Parent(s):
193c02b
update
Browse files
app.py
CHANGED
@@ -30,6 +30,7 @@ def get_default_chat():
|
|
30 |
def predict(message, history, chat):
|
31 |
print('!!!!!', message, history, chat)
|
32 |
history_len = len(history)
|
|
|
33 |
if chat is None:
|
34 |
chat = get_default_chat()
|
35 |
history_messages = []
|
@@ -40,18 +41,19 @@ def predict(message, history, chat):
|
|
40 |
|
41 |
if history_len == 0:
|
42 |
history_messages.append(SystemMessage(content=web_prompt))
|
43 |
-
|
44 |
-
|
45 |
-
|
46 |
-
|
47 |
-
|
48 |
-
|
49 |
-
|
50 |
-
|
51 |
-
|
52 |
-
|
53 |
-
|
54 |
-
|
|
|
55 |
|
56 |
response_message = ''
|
57 |
for chunk in chat.stream(history_messages):
|
|
|
30 |
def predict(message, history, chat):
|
31 |
print('!!!!!', message, history, chat)
|
32 |
history_len = len(history)
|
33 |
+
files_len = len(message.files)
|
34 |
if chat is None:
|
35 |
chat = get_default_chat()
|
36 |
history_messages = []
|
|
|
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):
|