Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fails to download preview when the first "sample image" is animated (mp4/webm) #127

Open
joshyy1312 opened this issue Dec 22, 2023 · 2 comments

Comments

@joshyy1312
Copy link

joshyy1312 commented Dec 22, 2023

When the first preview image set by the model author is an animation, the extension fails to download a preview image.

What it should do: download the first preview image that is not an animation.

Example Lora where this happens: https://civitai.com/models/214538

For most of my Lora/Checkpoints it works as intended.

Many thanks for this extension as it makes browsing large local model stores a lot easier :)

-- update 10.59

Let me rephrase that, the extension downloads the mp4 but renames it to .png, which can't be displayed by gradio.

It should still download the first available png :)

@joshyy1312
Copy link
Author

joshyy1312 commented Dec 24, 2023

If it helps someone else, I've made a quick correction to the python script so it works in most cases (it takes the second image).

It's dirty, there are better ways to do it but I don't use python and I don't know the civitai framework, so it will do until someone more knowledgeable saves the day.

In scripts/preview.py

change the line:
image_url = images[0]['url']

into:
if (images[0]['type'] != "image"):
image_url = images[1]['url']
else:
image_url = images[0]['url']

@Symbiomatrix
Copy link

Symbiomatrix commented Jan 12, 2024

A minor annoyance is that the api returns inaccurate urls for images - everything is .jpeg. The type property check is the correct approach (except for animated gif, not sure what it does there), would only check the whole list instead of just the second element, multiple animations happen. A list comprehension will do that neatly.

# Remove this line: if (len(images) == 0): continue
image_urls = [image['url'] for image in images if image['type'] == "image"]
if len(image_urls) == 0: continue
image_url = image_urls[0]
# Etc.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants