Axiz commited on
Commit
9fb1d73
·
verified ·
1 Parent(s): 29c5b07

Upload 4 files

Browse files
.gitattributes CHANGED
@@ -33,3 +33,4 @@ saved_model/**/* filter=lfs diff=lfs merge=lfs -text
33
  *.zip filter=lfs diff=lfs merge=lfs -text
34
  *.zst filter=lfs diff=lfs merge=lfs -text
35
  *tfevents* filter=lfs diff=lfs merge=lfs -text
 
 
33
  *.zip filter=lfs diff=lfs merge=lfs -text
34
  *.zst filter=lfs diff=lfs merge=lfs -text
35
  *tfevents* filter=lfs diff=lfs merge=lfs -text
36
+ vecteezy_loading-bar-animation_26651030.mp4 filter=lfs diff=lfs merge=lfs -text
Bouncer_v2.py ADDED
@@ -0,0 +1,160 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import streamlit as st
2
+ import requests
3
+ import json
4
+ import time
5
+ import base64
6
+ from PIL import Image
7
+ from io import BytesIO
8
+ from transformers import pipeline
9
+ from concurrent.futures import ThreadPoolExecutor
10
+
11
+ # --- 1. CONFIGURATION & SECRETS ---
12
+ # Add your key to Streamlit/HuggingFace Secrets as 'SERPER_API_KEY' for safety
13
+ try:
14
+ SERPER_API_KEY = st.secrets["SERPER_API_KEY"]
15
+ except:
16
+ # Fallback for local testing
17
+ SERPER_API_KEY = "827d931e4257327f4bcc9a35b2995001a68635d0"
18
+
19
+ SERPER_URL = "https://google.serper.dev/images"
20
+ BG_IMAGE = "vecteezy_abstract-background-design-background-texture-design-with_18752866-1.jpg"
21
+ LOADING_VIDEO = "vecteezy_loading-bar-animation_26651030.mp4"
22
+
23
+ # --- Page Config & Browser Icon ---
24
+ st.set_page_config(
25
+ page_title="HumanLens | AI Image Filter",
26
+ page_icon=BG_IMAGE, # Sets your custom background as the browser tab icon
27
+ layout="wide"
28
+ )
29
+
30
+ # --- 2. CUSTOM BACKGROUND STYLING ---
31
+ def add_custom_style(image_file):
32
+ with open(image_file, "rb") as image:
33
+ encoded_string = base64.b64encode(image.read()).decode()
34
+ st.markdown(
35
+ f"""
36
+ <style>
37
+ .stApp {{
38
+ background-image: url("data:image/jpg;base64,{encoded_string}");
39
+ background-attachment: fixed;
40
+ background-size: cover;
41
+ }}
42
+ /* Sidebar Glassmorphism effect */
43
+ [data-testid="stSidebar"] {{
44
+ background-color: rgba(255, 255, 255, 0.05) !important;
45
+ backdrop-filter: blur(15px);
46
+ border-right: 1px solid rgba(255, 255, 255, 0.1);
47
+ }}
48
+ /* Title shadows for readability */
49
+ h1 {{ color: white !important; text-shadow: 2px 2px 8px #000000; }}
50
+ </style>
51
+ """,
52
+ unsafe_allow_html=True
53
+ )
54
+
55
+ try:
56
+ add_custom_style(BG_IMAGE)
57
+ except:
58
+ st.warning("Background image not found. Ensure the filename is correct.")
59
+
60
+ # --- 3. AI MODELS ---
61
+ @st.cache_resource
62
+ def load_models():
63
+ style_pipe = pipeline("zero-shot-image-classification", model="google/siglip-base-patch16-224", device=-1)
64
+ anime_ai_pipe = pipeline("image-classification", model="legekka/AI-Anime-Image-Detector-ViT", device=-1)
65
+ photo_ai_pipe = pipeline("image-classification", model="Ateeqq/ai-vs-human-image-detector", device=-1)
66
+ return style_pipe, anime_ai_pipe, photo_ai_pipe
67
+
68
+ style_classifier, anime_ai_detector, photo_ai_detector = load_models()
69
+
70
+ # --- 4. PROCESSING LOGIC ---
71
+ def get_score(preds, target_labels):
72
+ for p in preds:
73
+ if p['label'].lower() in target_labels: return p['score']
74
+ return 0.0
75
+
76
+ def download_and_process(item, tolerance):
77
+ url = item.get("imageUrl")
78
+ try:
79
+ response = requests.get(url, timeout=5)
80
+ # Robust opening to handle transparency
81
+ raw_img = Image.open(BytesIO(response.content))
82
+ img = raw_img.convert("RGBA").convert("RGB")
83
+ img_small = img.resize((224, 224))
84
+
85
+ style_results = style_classifier(img_small, candidate_labels=["anime illustration", "real photo"])
86
+ top_style = style_results[0]['label']
87
+
88
+ if top_style == "anime illustration":
89
+ preds = anime_ai_detector(img_small)
90
+ # Model uses 'natural' for human art
91
+ human_score = get_score(preds, ['natural', 'human', 'real'])
92
+ else:
93
+ preds = photo_ai_detector(img_small)
94
+ human_score = get_score(preds, ['human', 'real', 'natural'])
95
+
96
+ if human_score >= tolerance:
97
+ return {"img": img, "score": human_score, "url": url, "style": top_style}
98
+ except: return None
99
+
100
+ # --- 5. SIDEBAR CONTROLS ---
101
+ with st.sidebar:
102
+ st.title("⚙️ Search Controls")
103
+ query = st.text_input("What are you looking for?", "Concept Art")
104
+
105
+ # Target Count with Help
106
+ c1, c2 = st.columns([4, 1])
107
+ target_count = c1.slider("Results", 1, 20, 6)
108
+ if c2.button("❓", key="h_count"):
109
+ st.info("The number of human-made images you want to see.")
110
+
111
+ # Strictness with Help
112
+ s1, s2 = st.columns([4, 1])
113
+ tolerance = s1.slider("Strictness", 0.0, 1.0, 0.5)
114
+ if s2.button("❓", key="h_strict"):
115
+ st.info("How sure the AI must be. 0.8+ is strict; 0.2 is loose.")
116
+
117
+ # Threads with Help
118
+ t1, t2 = st.columns([4, 1])
119
+ workers = t1.slider("Threads", 2, 16, 8)
120
+ if t2.button("❓", key="h_thread"):
121
+ st.info("Processing speed. Higher is faster but heavier on memory.")
122
+
123
+ start_search = st.button("🚀 Start Search", use_container_width=True)
124
+
125
+ # --- 6. MAIN DISPLAY & LOADING BAR ---
126
+ st.markdown("# 📸 HumanLens")
127
+ st.write("Verifying human creativity on the web.")
128
+
129
+ if start_search and query:
130
+ start_time = time.time()
131
+
132
+ # Custom Video Loading Bar
133
+ loading_placeholder = st.empty()
134
+ with loading_placeholder.container():
135
+ st.video(LOADING_VIDEO, autoplay=True, loop=True, muted=True)
136
+ st.write("### 🤖 AI is analyzing images...")
137
+
138
+ # Fetch and process
139
+ payload = json.dumps({"q": query, "num": target_count * 3})
140
+ headers = {'X-API-KEY': SERPER_API_KEY, 'Content-Type': 'application/json'}
141
+ response = requests.post(SERPER_URL, headers=headers, data=payload)
142
+ raw_results = response.json().get("images", [])
143
+
144
+ if raw_results:
145
+ with ThreadPoolExecutor(max_workers=workers) as executor:
146
+ results = list(executor.map(lambda r: download_and_process(r, tolerance), raw_results))
147
+ final_images = [r for r in results if r is not None][:target_count]
148
+
149
+ # Remove the loading video once finished
150
+ loading_placeholder.empty()
151
+
152
+ if final_images:
153
+ st.success(f"Verified {len(final_images)} images in {time.time() - start_time:.1f}s")
154
+ cols = st.columns(3)
155
+ for i, item in enumerate(final_images):
156
+ with cols[i % 3]:
157
+ st.image(item["img"], use_container_width=True)
158
+ st.caption(f"Human Confidence: {item['score']:.0%}")
159
+ else:
160
+ st.warning("No images passed the AI filter. Try lowering 'Strictness'.")
requirments.txt ADDED
@@ -0,0 +1,5 @@
 
 
 
 
 
 
1
+ streamlit
2
+ requests
3
+ Pillow
4
+ transformers
5
+ torch
vecteezy_abstract-background-design-background-texture-design-with_18752866-1.jpg ADDED
vecteezy_loading-bar-animation_26651030.mp4 ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:9684b3a29a0ce9756e85937f30876220adcd252d64d62f4cbcf00c1331a280a2
3
+ size 2271472