George-API commited on
Commit
9dfc456
·
verified ·
1 Parent(s): cc775c6

Upload app.py with huggingface_hub

Browse files
Files changed (1) hide show
  1. app.py +28 -2
app.py CHANGED
@@ -22,8 +22,13 @@ logger = logging.getLogger(__name__)
22
  # Load environment variables
23
  load_dotenv()
24
 
 
 
 
 
25
  # Load config file
26
  def load_config(config_path="transformers_config.json"):
 
27
  try:
28
  with open(config_path, 'r') as f:
29
  config = json.load(f)
@@ -43,8 +48,22 @@ SPACE_NAME = os.getenv("HF_SPACE_NAME", "phi4training")
43
  # Function to run training in a thread and stream output to container logs
44
  def run_training():
45
  """Run the training script and stream its output to container logs"""
 
 
 
 
 
 
 
 
 
 
 
 
 
 
46
  process = subprocess.Popen(
47
- ["python", "run_cloud_training.py"],
48
  stdout=subprocess.PIPE,
49
  stderr=subprocess.STDOUT,
50
  universal_newlines=True,
@@ -62,6 +81,8 @@ def start_training():
62
  # Print directly to container logs
63
  print("\n===== STARTING TRAINING PROCESS =====\n")
64
  print(f"Model: {MODEL_NAME}")
 
 
65
  print(f"Training with configuration from transformers_config.json")
66
  print("Training logs will appear below:")
67
  print("=" * 50)
@@ -147,7 +168,12 @@ with gr.Blocks(css="footer {visibility: hidden}") as demo:
147
  if __name__ == "__main__":
148
  # Start Gradio with minimal features
149
  print("\n===== RESEARCH TRAINING DASHBOARD STARTED =====\n")
150
- print("Click 'Start Training' to begin the fine-tuning process")
 
 
 
 
 
151
  print("All training output will appear in these logs")
152
  logger.info("Starting research training dashboard")
153
  demo.launch(share=False)
 
22
  # Load environment variables
23
  load_dotenv()
24
 
25
+ # Get script directory - important for Hugging Face Space paths
26
+ SCRIPT_DIR = os.path.dirname(os.path.abspath(__file__))
27
+ BASE_DIR = os.path.abspath(os.path.join(SCRIPT_DIR, "."))
28
+
29
  # Load config file
30
  def load_config(config_path="transformers_config.json"):
31
+ config_path = os.path.join(BASE_DIR, config_path)
32
  try:
33
  with open(config_path, 'r') as f:
34
  config = json.load(f)
 
48
  # Function to run training in a thread and stream output to container logs
49
  def run_training():
50
  """Run the training script and stream its output to container logs"""
51
+ # Locate training script using absolute path
52
+ training_script = os.path.join(BASE_DIR, "run_cloud_training.py")
53
+
54
+ # Check if file exists and log the path
55
+ if not os.path.exists(training_script):
56
+ print(f"ERROR: Training script not found at: {training_script}")
57
+ print(f"Current directory: {os.getcwd()}")
58
+ print("Available files:")
59
+ for file in os.listdir(BASE_DIR):
60
+ print(f" - {file}")
61
+ return
62
+
63
+ print(f"Found training script at: {training_script}")
64
+
65
  process = subprocess.Popen(
66
+ [sys.executable, training_script],
67
  stdout=subprocess.PIPE,
68
  stderr=subprocess.STDOUT,
69
  universal_newlines=True,
 
81
  # Print directly to container logs
82
  print("\n===== STARTING TRAINING PROCESS =====\n")
83
  print(f"Model: {MODEL_NAME}")
84
+ print(f"Base directory: {BASE_DIR}")
85
+ print(f"Current working directory: {os.getcwd()}")
86
  print(f"Training with configuration from transformers_config.json")
87
  print("Training logs will appear below:")
88
  print("=" * 50)
 
168
  if __name__ == "__main__":
169
  # Start Gradio with minimal features
170
  print("\n===== RESEARCH TRAINING DASHBOARD STARTED =====\n")
171
+ print(f"Base directory: {BASE_DIR}")
172
+ print(f"Current working directory: {os.getcwd()}")
173
+ print("Available files:")
174
+ for file in os.listdir(BASE_DIR):
175
+ print(f" - {file}")
176
+ print("\nClick 'Start Training' to begin the fine-tuning process")
177
  print("All training output will appear in these logs")
178
  logger.info("Starting research training dashboard")
179
  demo.launch(share=False)