jonathanagustin commited on
Commit
c40c386
·
verified ·
1 Parent(s): c93e941

Upload folder using huggingface_hub

Browse files
Files changed (1) hide show
  1. app.py +7 -7
app.py CHANGED
@@ -11,9 +11,12 @@ logging.basicConfig(
11
  )
12
  logger = logging.getLogger(__name__)
13
 
14
- # Get token from environment (set in HF Space secrets)
15
  HF_TOKEN = os.environ.get("HF_TOKEN", "")
 
 
16
  logger.info(f"HF_TOKEN configured: {bool(HF_TOKEN)}")
 
17
 
18
  client = InferenceClient(token=HF_TOKEN) if HF_TOKEN else InferenceClient()
19
  logger.info("InferenceClient initialized")
@@ -29,18 +32,15 @@ function() {
29
 
30
  def analyze(text: str) -> tuple[str, dict]:
31
  """Return emoji + label and confidence scores."""
32
- logger.info(f"analyze() called with text length: {len(text)}")
33
 
34
  if not text.strip():
35
  logger.warning("Empty text received")
36
  return "🤔 Enter some text!", {}
37
 
38
  try:
39
- logger.info("Calling text_classification API...")
40
- result = client.text_classification(
41
- text,
42
- model="distilbert/distilbert-base-uncased-finetuned-sst-2-english",
43
- )[0]
44
 
45
  label = result.label
46
  score = result.score
 
11
  )
12
  logger = logging.getLogger(__name__)
13
 
14
+ # Environment variables for configuration
15
  HF_TOKEN = os.environ.get("HF_TOKEN", "")
16
+ MODEL_ID = os.environ.get("MODEL_ID", "distilbert/distilbert-base-uncased-finetuned-sst-2-english")
17
+
18
  logger.info(f"HF_TOKEN configured: {bool(HF_TOKEN)}")
19
+ logger.info(f"MODEL_ID: {MODEL_ID}")
20
 
21
  client = InferenceClient(token=HF_TOKEN) if HF_TOKEN else InferenceClient()
22
  logger.info("InferenceClient initialized")
 
32
 
33
  def analyze(text: str) -> tuple[str, dict]:
34
  """Return emoji + label and confidence scores."""
35
+ logger.info(f"analyze() called | text_len={len(text)}")
36
 
37
  if not text.strip():
38
  logger.warning("Empty text received")
39
  return "🤔 Enter some text!", {}
40
 
41
  try:
42
+ logger.info(f"Calling text_classification | model={MODEL_ID}")
43
+ result = client.text_classification(text, model=MODEL_ID)[0]
 
 
 
44
 
45
  label = result.label
46
  score = result.score