tharu22 commited on
Commit
b2eb187
Β·
1 Parent(s): 4a9137e
Files changed (1) hide show
  1. app.py +10 -20
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="pcsk_6r4DPn_4P9LckhZak3PhebvSebnEBKQZuzYFeJL2X93LtLxZVBxyJ93inBAktefa8usvJC") # Replace with your 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
- # βœ… Apply Dark Mode if selected
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
+