File size: 2,858 Bytes
643ee53
 
 
 
 
94ab8cb
643ee53
 
 
 
 
 
94ab8cb
643ee53
 
 
 
 
 
 
 
d0e74d7
643ee53
 
 
 
 
 
960a1cf
 
94ab8cb
643ee53
 
 
 
 
 
b82a8b0
 
643ee53
508ba4a
643ee53
 
94ab8cb
 
 
 
 
643ee53
94ab8cb
643ee53
 
94ab8cb
 
643ee53
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
import streamlit as st
import pandas as pd
import requests

# Function to fetch images from the API
@st.cache_data
def fetch_images(postID):
    try:
        response = requests.get(f'https://civitai.com/api/v1/images?postId={postID}')
        response.raise_for_status()  # This will raise an exception for HTTP errors
        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["width"], item["height"], item["url"]] for item in items]
        return table_data
    except requests.RequestException as e:
        st.error(f"Failed to fetch images: {e}")
        return []  # Return an empty list in case of error

def display_images(df):
    if not df.empty:
        for _, row in df.iterrows():
            st.markdown("---")
            col1, col2 = st.columns([1, 2])  # Adjust the ratio as needed
            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']}    |    **Steps:** {row['steps']}")
                st.markdown(f"**Config Scale:** {row['cfgScale']}")
                st.markdown(f"**Image Size:** {row['height']} H x {row['width']} W")
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) - one of my own posts
    """)

    # Using st.query_params to access query parameters
    query_params = st.query_params
    postID = query_params.get('postID')# Access the 'postID' parameter

    postID_input = st.text_input('Enter Post ID:', value=postID)  # Prefill the input with the query parameter

    if postID_input: # only called if postID_input is not empty
        # Convert postID to integer if necessary
        try:
            postID_int = int(postID_input)
            df = pd.DataFrame(fetch_images(postID_int), columns=["id", "prompt", "negativePrompt", "sampler", "steps", "cfgScale", "width", "height", "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()