new
Browse files
app.py
CHANGED
|
@@ -7,8 +7,11 @@ from transformers import AutoProcessor, CLIPModel
|
|
| 7 |
import numpy as np
|
| 8 |
import torch
|
| 9 |
|
|
|
|
|
|
|
|
|
|
| 10 |
# β
Initialize Pinecone
|
| 11 |
-
pc = Pinecone(api_key="
|
| 12 |
index_name = "unsplash-index"
|
| 13 |
unsplash_index = pc.Index(index_name)
|
| 14 |
|
|
@@ -21,6 +24,11 @@ def load_clip_model():
|
|
| 21 |
|
| 22 |
model, processor = load_clip_model()
|
| 23 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 24 |
# β
Function to Generate Embedding from Text
|
| 25 |
def get_text_embedding(text):
|
| 26 |
inputs = processor(text=[text], return_tensors="pt", padding=True, truncation=True)
|
|
@@ -45,14 +53,6 @@ def search_similar_images(embedding, top_k=10):
|
|
| 45 |
)
|
| 46 |
return results.get("matches", [])
|
| 47 |
|
| 48 |
-
# β
Sidebar for Customization
|
| 49 |
-
st.sidebar.title("βοΈ Settings")
|
| 50 |
-
top_k = st.sidebar.slider("π’ Number of Similar Images", 1, 20, 10)
|
| 51 |
-
theme = st.sidebar.radio("π¨ Theme", ["Light Mode", "Dark Mode"], index=0)
|
| 52 |
-
|
| 53 |
-
# Apply Theme
|
| 54 |
-
st.set_page_config(page_title="Image Search App", layout="wide", initial_sidebar_state="expanded")
|
| 55 |
-
|
| 56 |
# β
Streamlit UI
|
| 57 |
st.title("π Image & Text Search with CLIP & Pinecone")
|
| 58 |
st.write("Search for images using text or upload an image to find similar ones!")
|
|
@@ -136,14 +136,4 @@ st.markdown(
|
|
| 136 |
"""
|
| 137 |
)
|
| 138 |
|
| 139 |
-
|
| 140 |
-
if theme == "Dark Mode":
|
| 141 |
-
st.markdown(
|
| 142 |
-
"""
|
| 143 |
-
<style>
|
| 144 |
-
body { background-color: #121212; color: white; }
|
| 145 |
-
.stTextInput, .stFileUploader, .stButton { background-color: #333; color: white; }
|
| 146 |
-
</style>
|
| 147 |
-
""",
|
| 148 |
-
unsafe_allow_html=True,
|
| 149 |
-
)
|
|
|
|
| 7 |
import numpy as np
|
| 8 |
import torch
|
| 9 |
|
| 10 |
+
# β
Set Page Config (Must be the first Streamlit command)
|
| 11 |
+
st.set_page_config(page_title="Image Search App", layout="wide", initial_sidebar_state="expanded")
|
| 12 |
+
|
| 13 |
# β
Initialize Pinecone
|
| 14 |
+
pc = Pinecone(api_key="your-pinecone-api-key") # Replace with your Pinecone API key
|
| 15 |
index_name = "unsplash-index"
|
| 16 |
unsplash_index = pc.Index(index_name)
|
| 17 |
|
|
|
|
| 24 |
|
| 25 |
model, processor = load_clip_model()
|
| 26 |
|
| 27 |
+
# β
Sidebar for Customization
|
| 28 |
+
st.sidebar.title("βοΈ Settings")
|
| 29 |
+
top_k = st.sidebar.slider("π’ Number of Similar Images", 1, 20, 10)
|
| 30 |
+
theme = st.sidebar.radio("π¨ Theme", ["Light Mode", "Dark Mode"], index=0)
|
| 31 |
+
|
| 32 |
# β
Function to Generate Embedding from Text
|
| 33 |
def get_text_embedding(text):
|
| 34 |
inputs = processor(text=[text], return_tensors="pt", padding=True, truncation=True)
|
|
|
|
| 53 |
)
|
| 54 |
return results.get("matches", [])
|
| 55 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 56 |
# β
Streamlit UI
|
| 57 |
st.title("π Image & Text Search with CLIP & Pinecone")
|
| 58 |
st.write("Search for images using text or upload an image to find similar ones!")
|
|
|
|
| 136 |
"""
|
| 137 |
)
|
| 138 |
|
| 139 |
+
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|