MohitG012 commited on
Commit
d94988a
Β·
verified Β·
1 Parent(s): 3e0fdaa

Update src/streamlit_app.py

Browse files
Files changed (1) hide show
  1. src/streamlit_app.py +10 -8
src/streamlit_app.py CHANGED
@@ -3,14 +3,14 @@ import streamlit as st
3
 
4
  # Fix permission errors by forcing writable directories
5
  os.environ["HF_HOME"] = "/tmp/hf_home"
6
- os.environ["TRANSFORMERS_CACHE"] = "/tmp/hf_cache"
7
  os.environ["SENTENCE_TRANSFORMERS_HOME"] = "/tmp/sbert"
8
  os.environ["XDG_CONFIG_HOME"] = "/tmp/.config"
9
  os.environ["STREAMLIT_HOME"] = "/tmp/.streamlit"
10
 
11
  # Make those folders if not already present
12
- for path in ["/tmp/hf_home", "/tmp/hf_cache", "/tmp/sbert", "/tmp/.config", "/tmp/.streamlit"]:
13
- os.makedirs(path, exist_ok=True)
14
 
15
  # HuggingFace login (requires HF_TOKEN to be added as secret in Hugging Face Spaces)
16
  from huggingface_hub import login
@@ -107,27 +107,29 @@ def summarize_user_preferences(user_id, top_k=3):
107
  return ", ".join(brands), ", ".join(styles), " ".join(descs[:top_k])
108
 
109
  # ========== APP STARTS ==========
 
 
 
 
110
  st.set_page_config("πŸ›οΈ Fashion Visual Search")
111
  st.title("πŸ‘— Fashion Visual Search & Outfit Assistant")
112
 
113
  image_embeddings, text_embeddings, ids, _, faiss_index, df, user_history, trend_string = load_assets()
114
 
 
115
  clip_model = CLIPModel.from_pretrained("openai/clip-vit-large-patch14", cache_dir="/tmp/hf_cache")
116
  clip_model.eval()
117
  clip_processor = CLIPProcessor.from_pretrained("openai/clip-vit-large-patch14", use_fast=True, cache_dir="/tmp/hf_cache")
118
 
119
  text_model = SentenceTransformer('sentence-transformers/all-MiniLM-L6-v2', cache_folder="/tmp/sbert")
120
 
121
- bnb_config = BitsAndBytesConfig(load_in_4bit=True)
122
  model_id = "google/gemma-3-4b-it"
123
  model = Gemma3ForConditionalGeneration.from_pretrained(
124
  model_id,
125
- torch_dtype=torch.float16,
126
  device_map="auto",
127
- quantization_config=bnb_config,
128
  cache_dir="/tmp/hf_cache"
129
- )
130
- model.eval()
131
  gemma_processor = AutoProcessor.from_pretrained(model_id, cache_dir="/tmp/hf_cache")
132
 
133
  username = st.text_input("πŸ‘€ Enter your username:")
 
3
 
4
  # Fix permission errors by forcing writable directories
5
  os.environ["HF_HOME"] = "/tmp/hf_home"
6
+ # os.environ["TRANSFORMERS_CACHE"] = "/tmp/hf_cache"
7
  os.environ["SENTENCE_TRANSFORMERS_HOME"] = "/tmp/sbert"
8
  os.environ["XDG_CONFIG_HOME"] = "/tmp/.config"
9
  os.environ["STREAMLIT_HOME"] = "/tmp/.streamlit"
10
 
11
  # Make those folders if not already present
12
+ # for path in ["/tmp/hf_home", "/tmp/hf_cache", "/tmp/sbert", "/tmp/.config", "/tmp/.streamlit"]:
13
+ # os.makedirs(path, exist_ok=True)
14
 
15
  # HuggingFace login (requires HF_TOKEN to be added as secret in Hugging Face Spaces)
16
  from huggingface_hub import login
 
107
  return ", ".join(brands), ", ".join(styles), " ".join(descs[:top_k])
108
 
109
  # ========== APP STARTS ==========
110
+ import streamlit.runtime.metrics_util
111
+ streamlit.runtime.metrics_util._config_file = "/tmp/.config/streamlit/config.toml"
112
+ # os.makedirs("/tmp/.config/streamlit", exist_ok=True)
113
+
114
  st.set_page_config("πŸ›οΈ Fashion Visual Search")
115
  st.title("πŸ‘— Fashion Visual Search & Outfit Assistant")
116
 
117
  image_embeddings, text_embeddings, ids, _, faiss_index, df, user_history, trend_string = load_assets()
118
 
119
+ # Load models
120
  clip_model = CLIPModel.from_pretrained("openai/clip-vit-large-patch14", cache_dir="/tmp/hf_cache")
121
  clip_model.eval()
122
  clip_processor = CLIPProcessor.from_pretrained("openai/clip-vit-large-patch14", use_fast=True, cache_dir="/tmp/hf_cache")
123
 
124
  text_model = SentenceTransformer('sentence-transformers/all-MiniLM-L6-v2', cache_folder="/tmp/sbert")
125
 
 
126
  model_id = "google/gemma-3-4b-it"
127
  model = Gemma3ForConditionalGeneration.from_pretrained(
128
  model_id,
129
+ torch_dtype=torch.float32,
130
  device_map="auto",
 
131
  cache_dir="/tmp/hf_cache"
132
+ ).eval()
 
133
  gemma_processor = AutoProcessor.from_pretrained(model_id, cache_dir="/tmp/hf_cache")
134
 
135
  username = st.text_input("πŸ‘€ Enter your username:")