Don B commited on
Commit
643ee53
·
1 Parent(s): 52a6de8

commit changes to huggingface

Browse files
Files changed (3) hide show
  1. .gitignore +1 -0
  2. app.py +59 -0
  3. requirements.txt +3 -0
.gitignore ADDED
@@ -0,0 +1 @@
 
 
1
+ .venv/
app.py ADDED
@@ -0,0 +1,59 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # created to retrieve prompt info for posts created to showcase a model
2
+ # tested using python 3.10.13, streamlit 1.31.1, pandas 2.2.1, requests 2.31.0
3
+ # if you're running on Windows python 3.10.11 should be fine
4
+ # run from the command line "streamlit run app.py"
5
+ import streamlit as st
6
+ import pandas as pd
7
+ import requests
8
+
9
+ # Function to fetch images from the API
10
+ @st.cache_data # Use the new caching mechanism
11
+ def fetch_images(postID):
12
+ try:
13
+ response = requests.get(f'https://civitai.com/api/v1/images?postId={postID}')
14
+ response.raise_for_status() # This will raise an exception for HTTP errors
15
+ data = response.json()
16
+ items = data["items"]
17
+ table_data = [[item["id"], item["meta"]["prompt"], item["meta"]["negativePrompt"], item["url"]] for item in items]
18
+ return table_data
19
+ except requests.RequestException as e:
20
+ st.error(f"Failed to fetch images: {e}")
21
+ return [] # Return an empty list in case of error
22
+
23
+ def display_images(df):
24
+ if not df.empty:
25
+ for _, row in df.iterrows():
26
+ col1, col2 = st.columns([1, 2]) # Adjust the ratio as needed
27
+ with col1:
28
+ st.image(row['url'], use_column_width=True)
29
+ with col2:
30
+ st.markdown(f"**Prompt:** {row['prompt']}")
31
+ st.markdown(f"**Negative Prompt:** {row['negativePrompt']}")
32
+
33
+ def main():
34
+ st.title('Civitai Model Showcase Prompts')
35
+
36
+ st.markdown("""
37
+ Created to retrieve prompt info for posts created to showcase a model.
38
+
39
+ Sample Stable Diffusion Lightning model posts - as of 2024-02-29
40
+ - post id 1496616 for [DreamShaper](https://civitai.com/posts/1496616)
41
+ - post id 1515491 for [Juggernaut Lightning](https://civitai.com/posts/1515491)
42
+ """)
43
+
44
+ postID = st.text_input('Enter Post ID:', '')
45
+
46
+ if postID:
47
+ # Convert postID to integer if necessary
48
+ try:
49
+ postID_int = int(postID)
50
+ df = pd.DataFrame(fetch_images(postID_int), columns=["id", "prompt", "negativePrompt", "url"])
51
+ if not df.empty:
52
+ display_images(df)
53
+ else:
54
+ st.write("No images found for the given Post ID.")
55
+ except ValueError:
56
+ st.error("Please enter a valid Post ID.")
57
+
58
+ if __name__ == "__main__":
59
+ main()
requirements.txt ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ streamlit
2
+ pandas
3
+ requests