File size: 3,248 Bytes
643ee53
 
 
 
 
94ab8cb
643ee53
 
 
 
 
 
731c733
643ee53
 
 
 
 
 
 
 
d0e74d7
643ee53
 
 
 
 
 
809097b
960a1cf
 
731c733
643ee53
c2832af
643ee53
 
c2832af
 
 
 
 
 
643ee53
 
94ab8cb
 
 
 
 
643ee53
94ab8cb
643ee53
 
94ab8cb
731c733
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
65
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"]["Model"],item["meta"]["sampler"], item["meta"]["steps"], item["meta"]["cfgScale"], item["meta"].get("Size", "missing"), item["meta"].get("width", "missing"), item["meta"].get("height", "missing"), 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"**Model:** {row['Model']}")
                st.markdown(f"**Sampler:** {row['sampler']}    |    **Steps:** {row['steps']}")
                st.markdown(f"**Config Scale:** {row['cfgScale']}")
                st.markdown(f"**Image Size:** {row['Size']} (W x H)   OR  {row['width']} x {row['height']} (W x H))")
def main():
    st.title('Civitai Posts - Prompt Summary')

    st.markdown("""
    Sample Stable Diffusion posts on Civitai - as of 2024-02-29 
    - post id 1576676 for [Stable Cascade](https://civitai.com/posts/1576676) - People prompts
    - post id 1593777 for [Stable Cascade](https://civitai.com/posts/1593777) - YAML based art prompts
    - post id 1593788 for [Stable Cascade](https://civitai.com/posts/1593788) - YAML based life sciences prompts
    - post id 1496616 for [DreamShaper Lightning](https://civitai.com/posts/1496616) - Lykon's model showcase
    - post id 1515491 for [Juggernaut Lightning](https://civitai.com/posts/1515491) - KandooAI's model showcase
    """)

    # 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", "Model", "sampler", "steps", "cfgScale", "Size", "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()