Spaces:
Running
on
Zero
Running
on
Zero
Update app.py
Browse files
app.py
CHANGED
|
@@ -27,22 +27,22 @@ def process_image(data):
|
|
| 27 |
def generate(message, history, model, system_prompt,
|
| 28 |
temperature=1.0, top_p=1.0, frequency_penalty=0.0, presence_penalty=0.0):
|
| 29 |
# history
|
| 30 |
-
history_openai_format
|
| 31 |
for user, assistant in history:
|
| 32 |
-
if isinstance(user, tuple): # there were
|
| 33 |
content = []
|
| 34 |
for filepath in user:
|
| 35 |
-
mime_type = get_mimetype(filepath)
|
| 36 |
-
if
|
| 37 |
-
|
| 38 |
-
|
| 39 |
-
|
| 40 |
-
|
| 41 |
-
|
| 42 |
-
|
| 43 |
-
|
| 44 |
-
|
| 45 |
-
|
| 46 |
else: # there was just text
|
| 47 |
history_openai_format.append({"role": "user", "content": user})
|
| 48 |
|
|
@@ -54,6 +54,9 @@ def generate(message, history, model, system_prompt,
|
|
| 54 |
"text": message['text']}]
|
| 55 |
|
| 56 |
for file in message['files']:
|
|
|
|
|
|
|
|
|
|
| 57 |
content.append({"type": "image_url",
|
| 58 |
"image_url": {"url": process_image(file)}})
|
| 59 |
|
|
|
|
| 27 |
def generate(message, history, model, system_prompt,
|
| 28 |
temperature=1.0, top_p=1.0, frequency_penalty=0.0, presence_penalty=0.0):
|
| 29 |
# history
|
| 30 |
+
history_openai_format=[{"role": "system", "content": system_prompt}]
|
| 31 |
for user, assistant in history:
|
| 32 |
+
if isinstance(user, tuple): # there were files
|
| 33 |
content = []
|
| 34 |
for filepath in user:
|
| 35 |
+
mime_type = get_mimetype(filepath) or ''
|
| 36 |
+
if mime_type.startswith("image/"):
|
| 37 |
+
content.append(
|
| 38 |
+
{"type": "image_url",
|
| 39 |
+
# for some reason you don't get the same image format in history as in message
|
| 40 |
+
"image_url": {"url": process_image({'path': filepath,
|
| 41 |
+
'mime_type': get_mimetype(filepath)})}}
|
| 42 |
+
)
|
| 43 |
+
if content:
|
| 44 |
+
history_openai_format.append(
|
| 45 |
+
{"role": "user", "content": content})
|
| 46 |
else: # there was just text
|
| 47 |
history_openai_format.append({"role": "user", "content": user})
|
| 48 |
|
|
|
|
| 54 |
"text": message['text']}]
|
| 55 |
|
| 56 |
for file in message['files']:
|
| 57 |
+
mime_type = get_mimetype(file['path']) or ''
|
| 58 |
+
if not mime_type.startswith('image/'):
|
| 59 |
+
raise gr.Error("Momenteel zijn alleen afbeeldingen ondersteund als bijlagen 💥!", duration=20)
|
| 60 |
content.append({"type": "image_url",
|
| 61 |
"image_url": {"url": process_image(file)}})
|
| 62 |
|