geethareddy commited on
Commit
3db7383
·
verified ·
1 Parent(s): fefea85

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +12 -5
app.py CHANGED
@@ -3,6 +3,7 @@ from pydantic import BaseModel
3
  from transformers import AutoModelForCausalLM, AutoTokenizer
4
  import json
5
  import logging
 
6
 
7
  # Set up logging
8
  logging.basicConfig(level=logging.INFO)
@@ -17,11 +18,18 @@ class CoachingInput(BaseModel):
17
  milestones: str
18
  reflection_log: str
19
 
 
 
 
 
 
 
 
 
20
  # Load model and tokenizer
21
  try:
22
- model_path = "./fine_tuned_construction_llm"
23
- model = AutoModelForCausalLM.from_pretrained(model_path)
24
- tokenizer = AutoTokenizer.from_pretrained(model_path)
25
  logger.info("Model and tokenizer loaded successfully")
26
  except Exception as e:
27
  logger.error(f"Failed to load model or tokenizer: {str(e)}")
@@ -73,5 +81,4 @@ async def generate_coaching(data: CoachingInput):
73
 
74
  @app.get("/health")
75
  async def health_check():
76
- return {"status": "healthy"}
77
-
 
3
  from transformers import AutoModelForCausalLM, AutoTokenizer
4
  import json
5
  import logging
6
+ import os
7
 
8
  # Set up logging
9
  logging.basicConfig(level=logging.INFO)
 
18
  milestones: str
19
  reflection_log: str
20
 
21
+ # Define model path (absolute path in the container)
22
+ model_path = "/app/fine-tuned-construction-llm"
23
+
24
+ # Verify the model directory exists
25
+ if not os.path.isdir(model_path):
26
+ logger.error(f"Model directory not found: {model_path}")
27
+ raise Exception(f"Model directory not found: {model_path}")
28
+
29
  # Load model and tokenizer
30
  try:
31
+ model = AutoModelForCausalLM.from_pretrained(model_path, local_files_only=True)
32
+ tokenizer = AutoTokenizer.from_pretrained(model_path, local_files_only=True)
 
33
  logger.info("Model and tokenizer loaded successfully")
34
  except Exception as e:
35
  logger.error(f"Failed to load model or tokenizer: {str(e)}")
 
81
 
82
  @app.get("/health")
83
  async def health_check():
84
+ return {"status": "healthy"}