|
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"]["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 [] |
|
|
|
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"**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 |
|
""") |
|
|
|
|
|
query_params = st.query_params |
|
postID = query_params.get('postID') |
|
|
|
postID_input = st.text_input('Enter Post ID:', value=postID) |
|
|
|
if postID_input: |
|
|
|
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() |
|
|