Spaces:
Sleeping
Sleeping
Create app.py
Browse files
app.py
ADDED
|
@@ -0,0 +1,96 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import streamlit as st
|
| 2 |
+
import pandas as pd
|
| 3 |
+
import os
|
| 4 |
+
|
| 5 |
+
# ==========================================
|
| 6 |
+
# 1. PAGE CONFIGURATION
|
| 7 |
+
# ==========================================
|
| 8 |
+
st.set_page_config(page_title="Horror Reference Library", layout="wide")
|
| 9 |
+
|
| 10 |
+
st.title("📽️ Horror Reference Library")
|
| 11 |
+
st.markdown("### Search 11,500+ Cinematic AI-Tagged Comic Panels")
|
| 12 |
+
|
| 13 |
+
# ==========================================
|
| 14 |
+
# 2. DATA LOADING
|
| 15 |
+
# ==========================================
|
| 16 |
+
@st.cache_data
|
| 17 |
+
def load_data():
|
| 18 |
+
# This loads the CSV "Map" you uploaded to the Space
|
| 19 |
+
df = pd.read_csv("horror_shot_database.csv")
|
| 20 |
+
return df
|
| 21 |
+
|
| 22 |
+
try:
|
| 23 |
+
df = load_data()
|
| 24 |
+
except Exception as e:
|
| 25 |
+
st.error(f"Error loading database: {e}")
|
| 26 |
+
st.stop()
|
| 27 |
+
|
| 28 |
+
# ==========================================
|
| 29 |
+
# 3. SIDEBAR FILTERS
|
| 30 |
+
# ==========================================
|
| 31 |
+
st.sidebar.header("Filter Shots")
|
| 32 |
+
|
| 33 |
+
all_angles = ["Any"] + sorted(df['camera_angle'].dropna().unique().tolist())
|
| 34 |
+
selected_angle = st.sidebar.selectbox("Camera Angle", all_angles)
|
| 35 |
+
|
| 36 |
+
all_moods = ["Any"] + sorted(df['mood'].dropna().unique().tolist())
|
| 37 |
+
selected_mood = st.sidebar.selectbox("Mood/Lighting", all_moods)
|
| 38 |
+
|
| 39 |
+
all_emotions = ["Any"] + sorted(df['emotion'].dropna().unique().tolist())
|
| 40 |
+
selected_emotion = st.sidebar.selectbox("Character Emotion", all_emotions)
|
| 41 |
+
|
| 42 |
+
# ==========================================
|
| 43 |
+
# 4. FILTERING LOGIC (Connecting to Dataset)
|
| 44 |
+
# ==========================================
|
| 45 |
+
results = df
|
| 46 |
+
if selected_angle != "Any":
|
| 47 |
+
results = results[results['camera_angle'] == selected_angle]
|
| 48 |
+
if selected_mood != "Any":
|
| 49 |
+
results = results[results['mood'] == selected_mood]
|
| 50 |
+
if selected_emotion != "Any":
|
| 51 |
+
results = results[results['emotion'] == selected_emotion]
|
| 52 |
+
|
| 53 |
+
# --- CHANGE 'YourUsername' TO YOUR ACTUAL HF USERNAME ---
|
| 54 |
+
base_url = "https://huggingface.co/datasets/Roshanurs/Horror-Reference-Data/resolve/main/Upload_Temp/Panels_Out"
|
| 55 |
+
|
| 56 |
+
valid_images = []
|
| 57 |
+
for idx, row in results.iterrows():
|
| 58 |
+
# This constructs the direct link to the image in your 24 batch folders
|
| 59 |
+
img_url = f"{base_url}/{row['filename']}"
|
| 60 |
+
valid_images.append({
|
| 61 |
+
"url": img_url,
|
| 62 |
+
"filename": row['filename'],
|
| 63 |
+
"desc": row['description']
|
| 64 |
+
})
|
| 65 |
+
|
| 66 |
+
st.markdown(f"**Found {len(valid_images)} matching shots**")
|
| 67 |
+
st.write("---")
|
| 68 |
+
|
| 69 |
+
# ==========================================
|
| 70 |
+
# 5. THE MASONRY GALLERY
|
| 71 |
+
# ==========================================
|
| 72 |
+
if len(valid_images) > 0:
|
| 73 |
+
# We show the first 100 results to keep the page fast
|
| 74 |
+
display_limit = 100
|
| 75 |
+
display_list = valid_images[:display_limit]
|
| 76 |
+
|
| 77 |
+
cols = st.columns(4)
|
| 78 |
+
|
| 79 |
+
for index, img_data in enumerate(display_list):
|
| 80 |
+
with cols[index % 4]:
|
| 81 |
+
# Streamlit fetches the image directly from the Dataset URL
|
| 82 |
+
st.image(img_data["url"], use_container_width=True)
|
| 83 |
+
|
| 84 |
+
# Download button that opens the raw image in a new tab
|
| 85 |
+
st.markdown(
|
| 86 |
+
f'<a href="{img_data["url"]}" target="_blank">'
|
| 87 |
+
f'<button style="width:100%; padding:8px; border-radius:4px; border:1px solid #444; background:#222; color:white; cursor:pointer;">'
|
| 88 |
+
f'View Full Size</button></a>',
|
| 89 |
+
unsafe_allow_html=True
|
| 90 |
+
)
|
| 91 |
+
st.write("")
|
| 92 |
+
|
| 93 |
+
if len(valid_images) > display_limit:
|
| 94 |
+
st.info(f"Showing first {display_limit} results. Refine your filters to see more specific shots.")
|
| 95 |
+
else:
|
| 96 |
+
st.warning("No shots found matching those exact parameters. Try widening your search!")
|