YoungjaeDev commited on
Commit
ae6b31c
·
verified ·
1 Parent(s): a9eed14

Upload folder using huggingface_hub

Browse files
Files changed (3) hide show
  1. __pycache__/app.cpython-311.pyc +0 -0
  2. app.py +6 -12
  3. requirements.txt +0 -3
__pycache__/app.cpython-311.pyc ADDED
Binary file (35.6 kB). View file
 
app.py CHANGED
@@ -7,7 +7,6 @@ from pathlib import Path
7
  from typing import TYPE_CHECKING, Iterable
8
 
9
  import gradio as gr
10
- import spaces
11
  from gradio.themes import Soft
12
  from gradio.themes.utils import colors, fonts, sizes
13
  from PIL import Image as PILImage
@@ -516,9 +515,8 @@ def L(key: str, lang: str = "en") -> str:
516
  return LABELS.get(lang, LABELS["en"]).get(key, key)
517
 
518
 
519
- @spaces.GPU
520
  def get_search_engine() -> MultimodalSearch:
521
- """Get or create the search engine (lazy loading with GPU).
522
 
523
  Returns:
524
  MultimodalSearch instance.
@@ -530,10 +528,10 @@ def get_search_engine() -> MultimodalSearch:
530
  from core.index import FaissIndex
531
  from core.search import MultimodalSearch
532
 
533
- # Initialize embedding model with GPU
534
- embedding_model = EmbeddingModel(device="cuda")
535
 
536
- # Load FAISS index (CPU - faiss-cpu doesn't support GPU)
537
  index = FaissIndex(device="cpu")
538
  index_path = EMBEDDINGS_DIR / "image_index"
539
  index.load(index_path)
@@ -615,9 +613,8 @@ def format_results(results: list[dict]) -> list[tuple[PILImage.Image | str, str]
615
  return formatted
616
 
617
 
618
- @spaces.GPU
619
  def search_by_text_handler(query: str, top_k: int) -> list[tuple[str, str]]:
620
- """Handle text search requests with GPU acceleration.
621
 
622
  Args:
623
  query: Text query string.
@@ -637,11 +634,10 @@ def search_by_text_handler(query: str, top_k: int) -> list[tuple[str, str]]:
637
  raise gr.Error(f"Search failed: {e}")
638
 
639
 
640
- @spaces.GPU
641
  def search_by_image_handler(
642
  image: PILImage.Image | None, top_k: int
643
  ) -> list[tuple[str, str]]:
644
- """Handle image search requests with GPU acceleration.
645
 
646
  Args:
647
  image: Query image (PIL Image).
@@ -661,7 +657,6 @@ def search_by_image_handler(
661
  raise gr.Error(f"Search failed: {e}")
662
 
663
 
664
- @spaces.GPU
665
  def search_composed_handler(
666
  image: PILImage.Image | None,
667
  modification_text: str,
@@ -743,7 +738,6 @@ def get_random_samples(top_k: int = 10) -> list[tuple[PILImage.Image | str, str]
743
  return []
744
 
745
 
746
- @spaces.GPU
747
  def unified_search_handler(
748
  text_query: str,
749
  image: PILImage.Image | None,
 
7
  from typing import TYPE_CHECKING, Iterable
8
 
9
  import gradio as gr
 
10
  from gradio.themes import Soft
11
  from gradio.themes.utils import colors, fonts, sizes
12
  from PIL import Image as PILImage
 
515
  return LABELS.get(lang, LABELS["en"]).get(key, key)
516
 
517
 
 
518
  def get_search_engine() -> MultimodalSearch:
519
+ """Get or create the search engine (lazy loading).
520
 
521
  Returns:
522
  MultimodalSearch instance.
 
528
  from core.index import FaissIndex
529
  from core.search import MultimodalSearch
530
 
531
+ # Initialize embedding model (CPU for stability)
532
+ embedding_model = EmbeddingModel(device="cpu")
533
 
534
+ # Load FAISS index (CPU)
535
  index = FaissIndex(device="cpu")
536
  index_path = EMBEDDINGS_DIR / "image_index"
537
  index.load(index_path)
 
613
  return formatted
614
 
615
 
 
616
  def search_by_text_handler(query: str, top_k: int) -> list[tuple[str, str]]:
617
+ """Handle text search requests.
618
 
619
  Args:
620
  query: Text query string.
 
634
  raise gr.Error(f"Search failed: {e}")
635
 
636
 
 
637
  def search_by_image_handler(
638
  image: PILImage.Image | None, top_k: int
639
  ) -> list[tuple[str, str]]:
640
+ """Handle image search requests.
641
 
642
  Args:
643
  image: Query image (PIL Image).
 
657
  raise gr.Error(f"Search failed: {e}")
658
 
659
 
 
660
  def search_composed_handler(
661
  image: PILImage.Image | None,
662
  modification_text: str,
 
738
  return []
739
 
740
 
 
741
  def unified_search_handler(
742
  text_query: str,
743
  image: PILImage.Image | None,
requirements.txt CHANGED
@@ -8,6 +8,3 @@ numpy>=1.24
8
  datasets>=2.14,<4.0
9
  huggingface-hub>=0.20
10
  tqdm>=4.65
11
-
12
- # HF Spaces ZeroGPU
13
- spaces
 
8
  datasets>=2.14,<4.0
9
  huggingface-hub>=0.20
10
  tqdm>=4.65