Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
chenpangpang
open-webui
Commits
482f010d
Commit
482f010d
authored
May 02, 2024
by
Timothy J. Baek
Browse files
fix: image gen
parent
1f98c091
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
9 additions
and
9 deletions
+9
-9
backend/apps/images/main.py
backend/apps/images/main.py
+9
-9
No files found.
backend/apps/images/main.py
View file @
482f010d
...
...
@@ -348,18 +348,20 @@ def save_url_image(url):
if
not
image_format
:
raise
ValueError
(
"Could not determine image type from MIME type"
)
file_path
=
IMAGE_CACHE_DIR
.
joinpath
(
f
"
{
image_id
}{
image_format
}
"
)
image_filename
=
f
"
{
image_id
}{
image_format
}
"
file_path
=
IMAGE_CACHE_DIR
.
joinpath
(
f
"
{
image_filename
}
"
)
with
open
(
file_path
,
"wb"
)
as
image_file
:
for
chunk
in
r
.
iter_content
(
chunk_size
=
8192
):
image_file
.
write
(
chunk
)
return
image_
id
,
image_format
return
image_
filename
else
:
log
.
error
(
f
"Url does not point to an image."
)
return
None
,
None
return
None
except
Exception
as
e
:
log
.
exception
(
f
"Error saving image:
{
e
}
"
)
return
None
,
None
return
None
@
app
.
post
(
"/generations"
)
...
...
@@ -435,11 +437,9 @@ def generate_image(
images
=
[]
for
image
in
res
[
"data"
]:
image_id
,
image_format
=
save_url_image
(
image
[
"url"
])
images
.
append
(
{
"url"
:
f
"/cache/image/generations/
{
image_id
}{
image_format
}
"
}
)
file_body_path
=
IMAGE_CACHE_DIR
.
joinpath
(
f
"
{
image_id
}
.json"
)
image_filename
=
save_url_image
(
image
[
"url"
])
images
.
append
({
"url"
:
f
"/cache/image/generations/
{
image_filename
}
"
})
file_body_path
=
IMAGE_CACHE_DIR
.
joinpath
(
f
"
{
image_filename
}
.json"
)
with
open
(
file_body_path
,
"w"
)
as
f
:
json
.
dump
(
data
.
model_dump
(
exclude_none
=
True
),
f
)
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment