sitammeur commited on
Commit
f1ca14c
·
verified ·
1 Parent(s): 238cf7c

Delete src/app

Browse files
Files changed (2) hide show
  1. src/app/__init__.py +0 -0
  2. src/app/predict.py +0 -55
src/app/__init__.py DELETED
File without changes
src/app/predict.py DELETED
@@ -1,55 +0,0 @@
1
- # Necessary imports
2
- import sys
3
- from typing import Dict
4
- from src.logger import logging
5
- from src.exception import CustomExceptionHandling
6
- from transformers import pipeline
7
-
8
-
9
- # Load the zero-shot classification model
10
- classifier = pipeline(
11
- "zero-shot-classification", model="MoritzLaurer/ModernBERT-large-zeroshot-v2.0",
12
- )
13
-
14
-
15
- def ZeroShotTextClassification(
16
- text_input: str, candidate_labels: str, multi_label: bool
17
- ) -> Dict[str, float]:
18
- """
19
- Performs zero-shot classification on the given text input.
20
-
21
- Args:
22
- - text_input: The input text to classify.
23
- - candidate_labels: A comma-separated string of candidate labels.
24
- - multi_label: A boolean indicating whether to allow the model to choose multiple classes.
25
-
26
- Returns:
27
- Dictionary containing label-score pairs.
28
- """
29
- try:
30
- # Split and clean the candidate labels
31
- labels = [label.strip() for label in candidate_labels.split(",")]
32
-
33
- # Log the classification attempt
34
- logging.info(f"Attempting classification with {len(labels)} labels")
35
-
36
- # Perform zero-shot classification
37
- hypothesis_template = "This text is about {}"
38
- prediction = classifier(
39
- text_input,
40
- labels,
41
- hypothesis_template=hypothesis_template,
42
- multi_label=multi_label,
43
- )
44
-
45
- # Return the classification results
46
- logging.info("Classification completed successfully")
47
- return {
48
- prediction["labels"][i]: prediction["scores"][i]
49
- for i in range(len(prediction["labels"]))
50
- }
51
-
52
- # Handle exceptions that may occur during the process
53
- except Exception as e:
54
- # Custom exception handling
55
- raise CustomExceptionHandling(e, sys) from e