win2win commited on
Commit
60fda7b
·
verified ·
1 Parent(s): 5566679

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +13 -11
app.py CHANGED
@@ -5,6 +5,9 @@ from pydantic import BaseModel
5
  import os
6
  import numpy as np # Explicit numpy import
7
 
 
 
 
8
  # Fix numpy initialization
9
  np.zeros(1) # Force numpy load before model
10
 
@@ -24,23 +27,22 @@ os.makedirs(os.environ["TRANSFORMERS_CACHE"], exist_ok=True)
24
  def readiness_check():
25
  return {"status": "ready"}
26
 
 
27
 
28
- # Load model with error handling
29
  try:
30
- model = pipeline(
 
 
 
 
31
  "text-classification",
32
- model="win2win/3-epochs-classifier-ver2",
33
- device="cpu", # Force CPU for free tier
34
- device_map="auto",
35
- torch_dtype=torch.float32, # Avoid mixed precision
36
- offline_mode=False, # Force fresh download
37
- max_retries=3
38
  )
39
-
40
-
41
  print("Model loaded successfully!")
42
  except Exception as e:
43
- print(f"Model loading failed: {str(e)}")
44
  raise
45
 
46
  class Request(BaseModel):
 
5
  import os
6
  import numpy as np # Explicit numpy import
7
 
8
+ from transformers import AutoModelForSequenceClassification, AutoTokenizer, pipeline
9
+ import torch
10
+
11
  # Fix numpy initialization
12
  np.zeros(1) # Force numpy load before model
13
 
 
27
  def readiness_check():
28
  return {"status": "ready"}
29
 
30
+ model_name = "win2win/3-epochs-classifier-ver2"
31
 
 
32
  try:
33
+ model = AutoModelForSequenceClassification.from_pretrained(model_name)
34
+ tokenizer = AutoTokenizer.from_pretrained(model_name)
35
+
36
+ # Create pipeline with explicit classes
37
+ classifier = pipeline(
38
  "text-classification",
39
+ model=model,
40
+ tokenizer=tokenizer,
41
+ device="cuda" if torch.cuda.is_available() else "cpu"
 
 
 
42
  )
 
 
43
  print("Model loaded successfully!")
44
  except Exception as e:
45
+ print(f"Error loading model: {str(e)}")
46
  raise
47
 
48
  class Request(BaseModel):