Marwan-Tamer commited on
Commit
f4612a5
·
1 Parent(s): 123562b

Optimize Hugging Face Space build

Browse files
Dockerfile CHANGED
@@ -12,9 +12,9 @@ RUN apt-get update \
12
  && apt-get install -y --no-install-recommends build-essential \
13
  && rm -rf /var/lib/apt/lists/*
14
 
15
- COPY requirements.txt .
16
  RUN pip install --upgrade pip \
17
- && pip install -r requirements.txt
18
 
19
  COPY . .
20
 
 
12
  && apt-get install -y --no-install-recommends build-essential \
13
  && rm -rf /var/lib/apt/lists/*
14
 
15
+ COPY requirements-space.txt .
16
  RUN pip install --upgrade pip \
17
+ && pip install -r requirements-space.txt
18
 
19
  COPY . .
20
 
requirements-space.txt ADDED
@@ -0,0 +1,10 @@
 
 
 
 
 
 
 
 
 
 
 
1
+ fastapi
2
+ uvicorn
3
+ qdrant-client==1.18.0
4
+ groq==1.4.0
5
+ huggingface_hub
6
+ transformers
7
+ torch
8
+ scikit-learn==1.9.0
9
+ joblib==1.5.3
10
+ numpy
src/models/language_classifier.py CHANGED
@@ -6,9 +6,7 @@ import sys
6
  from pathlib import Path
7
  from typing import Any
8
  import joblib
9
- import pandas as pd
10
  from sklearn.feature_extraction.text import TfidfVectorizer
11
- from sklearn.metrics import accuracy_score, classification_report, confusion_matrix
12
  from sklearn.naive_bayes import MultinomialNB
13
  from sklearn.pipeline import Pipeline
14
 
@@ -74,7 +72,9 @@ class LanguageDetector:
74
  )
75
 
76
  @staticmethod
77
- def _load_dataset(path: str | Path) -> pd.DataFrame:
 
 
78
  df = pd.read_csv(path)
79
  required_columns = {"text", "labels"}
80
  missing_columns = required_columns.difference(df.columns)
@@ -112,7 +112,9 @@ class LanguageDetector:
112
  "model_path": str(self.model_path),
113
  }
114
 
115
- def evaluate(self, df: pd.DataFrame, split_name: str) -> dict[str, Any]:
 
 
116
  predictions = self.pipeline.predict(df["text"])
117
  labels = sorted(df["labels"].unique())
118
  report_dict = classification_report(
@@ -148,6 +150,8 @@ class LanguageDetector:
148
  print(f"Saved model to {self.model_path}")
149
 
150
  def save_reports(self, validation_metrics: dict[str, Any], test_metrics: dict[str, Any]) -> None:
 
 
151
  REPORTS_DIR.mkdir(parents=True, exist_ok=True)
152
 
153
  summary = {
 
6
  from pathlib import Path
7
  from typing import Any
8
  import joblib
 
9
  from sklearn.feature_extraction.text import TfidfVectorizer
 
10
  from sklearn.naive_bayes import MultinomialNB
11
  from sklearn.pipeline import Pipeline
12
 
 
72
  )
73
 
74
  @staticmethod
75
+ def _load_dataset(path: str | Path) -> Any:
76
+ import pandas as pd
77
+
78
  df = pd.read_csv(path)
79
  required_columns = {"text", "labels"}
80
  missing_columns = required_columns.difference(df.columns)
 
112
  "model_path": str(self.model_path),
113
  }
114
 
115
+ def evaluate(self, df: Any, split_name: str) -> dict[str, Any]:
116
+ from sklearn.metrics import accuracy_score, classification_report, confusion_matrix
117
+
118
  predictions = self.pipeline.predict(df["text"])
119
  labels = sorted(df["labels"].unique())
120
  report_dict = classification_report(
 
150
  print(f"Saved model to {self.model_path}")
151
 
152
  def save_reports(self, validation_metrics: dict[str, Any], test_metrics: dict[str, Any]) -> None:
153
+ import pandas as pd
154
+
155
  REPORTS_DIR.mkdir(parents=True, exist_ok=True)
156
 
157
  summary = {