siddheshrj commited on
Commit
1bedb07
·
verified ·
1 Parent(s): 5dcb04c

Clean app.py startup without spaces conflict

Browse files
Files changed (1) hide show
  1. app.py +6 -10
app.py CHANGED
@@ -17,16 +17,12 @@ from minirewrite.pipeline import MiniRewrite
17
 
18
  # Global model instance
19
  print("Initializing MiniRewrite model...")
20
- # Determine weights location: local folder or runs/rtx4060 fallback
21
- if (ROOT_DIR / "tokenizer.json").exists() and (ROOT_DIR / "best.pt").exists():
22
- MODEL_DIR = ROOT_DIR
23
- elif (ROOT_DIR / "runs" / "rtx4060" / "tokenizer.json").exists():
24
- MODEL_DIR = ROOT_DIR / "runs" / "rtx4060"
25
- else:
26
- MODEL_DIR = ROOT_DIR
27
-
28
- pipeline = MiniRewrite.from_pretrained(MODEL_DIR, checkpoint_name="best.pt", device="auto")
29
- print(f"Model loaded on {pipeline.device}!")
30
 
31
 
32
  def process_rewrite(text: str, task: str, tone: str, style: str):
 
17
 
18
  # Global model instance
19
  print("Initializing MiniRewrite model...")
20
+ MODEL_DIR = ROOT_DIR if (ROOT_DIR / "best.pt").exists() else (ROOT_DIR / "runs" / "rtx4060")
21
+
22
+ # CPU inference is extremely fast (~50ms) for this 7.6M model and requires zero GPU cold-start
23
+ device = "cuda" if torch.cuda.is_available() else "cpu"
24
+ pipeline = MiniRewrite.from_pretrained(MODEL_DIR, checkpoint_name="best.pt", device=device)
25
+ print(f"Model loaded successfully on {pipeline.device}!")
 
 
 
 
26
 
27
 
28
  def process_rewrite(text: str, task: str, tone: str, style: str):