lawlevisan commited on
Commit
94cb6fe
·
verified ·
1 Parent(s): d7ddcdf

Update src/predict.py

Browse files
Files changed (1) hide show
  1. src/predict.py +8 -30
src/predict.py CHANGED
@@ -328,37 +328,15 @@ def test_predictions():
328
  actual = "DRUG" if label == 1 else "NON_DRUG"
329
  logger.info(f"Expected: {expected}, Got: {actual}, Probability: {prob:.4f}")
330
 
 
 
 
 
331
  if __name__ == "__main__":
332
- # Load model once when script is run directly
333
  load_model()
334
-
335
- # Run tests
336
  test_predictions()
337
 
338
- # Interactive testing
339
- print("\n" + "="*50)
340
- print("Interactive Drug Detection Testing")
341
- print("Enter text to classify (or 'quit' to exit)")
342
- print("="*50)
343
-
344
- while True:
345
- try:
346
- user_input = input("\nEnter text: ").strip()
347
- if user_input.lower() in ['quit', 'exit', 'q']:
348
- break
349
-
350
- if user_input:
351
- label, prob = predict(user_input)
352
- result = "🚨 DRUG" if label == 1 else "✅ NON_DRUG"
353
- confidence = max(prob, 1-prob)
354
- print(f"Result: {result}")
355
- print(f"Drug Probability: {prob*100:.2f}%")
356
- print(f"Confidence: {confidence*100:.2f}%")
357
- else:
358
- print("Please enter some text.")
359
-
360
- except KeyboardInterrupt:
361
- print("\nExiting...")
362
- break
363
- except Exception as e:
364
- print(f"Error: {e}")
 
328
  actual = "DRUG" if label == 1 else "NON_DRUG"
329
  logger.info(f"Expected: {expected}, Got: {actual}, Probability: {prob:.4f}")
330
 
331
+ # ===========================
332
+ # HF Spaces / Production Ready
333
+ # ===========================
334
+
335
  if __name__ == "__main__":
336
+ # Load model once
337
  load_model()
338
+
339
+ # Optional: run test predictions to verify setup
340
  test_predictions()
341
 
342
+ # No interactive input() calls here – compatible with Hugging Face Spaces