|
import streamlit as st |
|
import pandas as pd |
|
import requests |
|
|
|
|
|
@st.cache_data |
|
def fetch_images(postID): |
|
try: |
|
response = requests.get(f'https://civitai.com/api/v1/images?postId={postID}') |
|
response.raise_for_status() |
|
data = response.json() |
|
items = data["items"] |
|
table_data = [[item["id"], item["meta"]["prompt"], item["meta"].get("negativePrompt", "N/A"), item["meta"]["sampler"], item["meta"]["steps"], item["meta"]["cfgScale"], item["url"]] for item in items] |
|
return table_data |
|
except requests.RequestException as e: |
|
st.error(f"Failed to fetch images: {e}") |
|
return [] |
|
|
|
def display_images(df): |
|
if not df.empty: |
|
for _, row in df.iterrows(): |
|
st.markdown("---") |
|
col1, col2 = st.columns([1, 2]) |
|
with col1: |
|
st.image(row['url'], use_column_width=True) |
|
with col2: |
|
st.markdown(f"**Prompt:** {row['prompt']}") |
|
st.markdown(f"**Negative Prompt:** {row['negativePrompt']}") |
|
st.markdown(f"**Sampler:** {row['sampler']}") |
|
st.markdown(f"**Steps:** {row['steps']}") |
|
st.markdown(f"**Config Scale:** {row['cfgScale']}") |
|
|
|
def main(): |
|
st.title('Civitai Model Showcase Prompts') |
|
|
|
st.markdown(""" |
|
Created to retrieve prompt info for posts created to showcase a model. |
|
|
|
Sample Stable Diffusion model posts - as of 2024-02-29 |
|
- post id 1496616 for [DreamShaper Lightning](https://civitai.com/posts/1496616) |
|
- post id 1515491 for [Juggernaut Lightning](https://civitai.com/posts/1515491) |
|
- post id 1576676 for [Stable Cascade](https://civitai.com/posts/1576676) - I was impressed with the diversity and inclusivity of the prompts / images |
|
""") |
|
|
|
postID = st.text_input('Enter Post ID:', '') |
|
|
|
if postID: |
|
|
|
try: |
|
postID_int = int(postID) |
|
df = pd.DataFrame(fetch_images(postID_int), columns=["id", "prompt", "negativePrompt", "sampler", "steps", "cfgScale", "url"]) |
|
if not df.empty: |
|
display_images(df) |
|
else: |
|
st.write("No images found for the given Post ID.") |
|
except ValueError: |
|
st.error("Please enter a valid Post ID.") |
|
|
|
if __name__ == "__main__": |
|
main() |
|
|