George-API commited on
Commit
928b596
·
verified ·
1 Parent(s): ab1497e

Upload app.py with huggingface_hub

Browse files
Files changed (1) hide show
  1. app.py +38 -49
app.py CHANGED
@@ -37,34 +37,46 @@ model_config = config.get("model_config", {})
37
  # Model details from config
38
  MODEL_NAME = model_config.get("model_name_or_path", "unsloth/DeepSeek-R1-Distill-Qwen-14B-bnb-4bit")
39
  SPACE_NAME = os.getenv("HF_SPACE_NAME", "phi4training")
40
- TRAINING_ACTIVE = os.path.exists("TRAINING_ACTIVE")
41
 
42
  # Function to start the training process
43
  def start_training():
44
  try:
45
- # Create TRAINING_ACTIVE file
46
- with open("TRAINING_ACTIVE", "w") as f:
47
- f.write("Training in progress")
48
-
49
- # Run the training script in the background
50
- subprocess.Popen(["python", "run_cloud_training.py"],
51
- stdout=subprocess.PIPE,
52
- stderr=subprocess.PIPE)
53
 
54
- return "✅ Training started! Check status below for updates."
 
 
 
 
 
 
 
 
 
 
 
 
 
 
55
  except Exception as e:
56
  logger.error(f"Error starting training: {str(e)}")
57
  return f"❌ Error starting training: {str(e)}"
58
 
59
  # Create Gradio interface - training status only, no model outputs
60
  with gr.Blocks(css="footer {visibility: hidden}") as demo:
61
- gr.Markdown(f"# {SPACE_NAME}: Training Status Dashboard")
62
 
63
  with gr.Row():
64
  with gr.Column():
65
  status = gr.Markdown(
66
  f"""
67
- ## Research Training Phase Active
68
 
69
  **Model**: {MODEL_NAME}
70
  **Dataset**: phi4-cognitive-dataset
@@ -78,62 +90,39 @@ with gr.Blocks(css="footer {visibility: hidden}") as demo:
78
  - **Learning Rate**: {config.get("training_config", {}).get("learning_rate", 2e-5)}
79
  - **Max Sequence Length**: {config.get("training_config", {}).get("max_seq_length", 2048)}
80
 
81
- ### Training Status:
82
- {"🟢 Training in progress" if TRAINING_ACTIVE else "⚪ Training not currently active"}
83
-
84
  ⚠️ **NOTE**: This space does not provide model outputs during the research training phase.
 
85
  """
86
  )
87
 
88
  with gr.Row():
89
- # Add buttons for starting training and refreshing status
90
  start_btn = gr.Button("Start Training", variant="primary")
91
- refresh_btn = gr.Button("Refresh Status")
92
 
93
  # Output area for training start messages
94
  training_output = gr.Markdown("")
95
 
96
- def refresh_status():
97
- # Re-check if training is active
98
- training_active = os.path.exists("TRAINING_ACTIVE")
99
- return f"""
100
- ## Research Training Phase Active
101
-
102
- **Model**: {MODEL_NAME}
103
- **Dataset**: phi4-cognitive-dataset
104
-
105
- This is a multidisciplinary research training phase. The model is not available for interactive use.
106
-
107
- ### Training Configuration:
108
- - **Epochs**: {config.get("training_config", {}).get("num_train_epochs", 3)}
109
- - **Batch Size**: {config.get("training_config", {}).get("per_device_train_batch_size", 2)}
110
- - **Gradient Accumulation Steps**: {config.get("training_config", {}).get("gradient_accumulation_steps", 4)}
111
- - **Learning Rate**: {config.get("training_config", {}).get("learning_rate", 2e-5)}
112
- - **Max Sequence Length**: {config.get("training_config", {}).get("max_seq_length", 2048)}
113
-
114
- ### Training Status:
115
- {"🟢 Training in progress" if training_active else "⚪ Training not currently active"}
116
-
117
- ⚠️ **NOTE**: This space does not provide model outputs during the research training phase.
118
- """
119
-
120
- # Connect button clicks to functions
121
  start_btn.click(start_training, outputs=training_output)
122
- refresh_btn.click(refresh_status, outputs=status)
123
 
124
  gr.Markdown("""
125
  ### Research Training Information
 
126
  This model is being fine-tuned on research-focused datasets and is not available for interactive querying.
127
- Training logs are available to authorized researchers only.
128
 
129
- ### Instructions
130
  1. Click "Start Training" to begin the fine-tuning process
131
- 2. Use "Refresh Status" to check training progress
132
- 3. Training logs are saved to the output directory
 
 
 
 
133
  """)
134
 
135
  # Launch the interface
136
  if __name__ == "__main__":
137
  # Start Gradio with minimal features
138
- logger.info("Starting training status dashboard")
139
- demo.launch(share=False) # Removed enable_queue parameter which is no longer supported in Gradio 5.x
 
37
  # Model details from config
38
  MODEL_NAME = model_config.get("model_name_or_path", "unsloth/DeepSeek-R1-Distill-Qwen-14B-bnb-4bit")
39
  SPACE_NAME = os.getenv("HF_SPACE_NAME", "phi4training")
 
40
 
41
  # Function to start the training process
42
  def start_training():
43
  try:
44
+ # Run the training script using HF's native logging
45
+ process = subprocess.Popen(
46
+ ["python", "run_cloud_training.py"],
47
+ stdout=subprocess.PIPE,
48
+ stderr=subprocess.PIPE,
49
+ universal_newlines=True
50
+ )
 
51
 
52
+ # Log the start of training
53
+ logger.info("Training started - Check Hugging Face logs for details")
54
+
55
+ return """
56
+ ✅ Training process initiated!
57
+
58
+ The model is now being fine-tuned in the background.
59
+
60
+ To monitor progress:
61
+ 1. Check the Hugging Face space logs in the "Logs" tab
62
+ 2. Training metrics will be available in the Hugging Face UI
63
+ 3. The process will continue running in the background
64
+
65
+ NOTE: This is a research training phase only, no model outputs will be available.
66
+ """
67
  except Exception as e:
68
  logger.error(f"Error starting training: {str(e)}")
69
  return f"❌ Error starting training: {str(e)}"
70
 
71
  # Create Gradio interface - training status only, no model outputs
72
  with gr.Blocks(css="footer {visibility: hidden}") as demo:
73
+ gr.Markdown(f"# {SPACE_NAME}: Research Training Dashboard")
74
 
75
  with gr.Row():
76
  with gr.Column():
77
  status = gr.Markdown(
78
  f"""
79
+ ## DeepSeek-R1-Distill-Qwen-14B Research Training
80
 
81
  **Model**: {MODEL_NAME}
82
  **Dataset**: phi4-cognitive-dataset
 
90
  - **Learning Rate**: {config.get("training_config", {}).get("learning_rate", 2e-5)}
91
  - **Max Sequence Length**: {config.get("training_config", {}).get("max_seq_length", 2048)}
92
 
 
 
 
93
  ⚠️ **NOTE**: This space does not provide model outputs during the research training phase.
94
+ All logs are available in the Hugging Face "Logs" tab.
95
  """
96
  )
97
 
98
  with gr.Row():
99
+ # Add button for starting training
100
  start_btn = gr.Button("Start Training", variant="primary")
 
101
 
102
  # Output area for training start messages
103
  training_output = gr.Markdown("")
104
 
105
+ # Connect start button to function
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
106
  start_btn.click(start_training, outputs=training_output)
 
107
 
108
  gr.Markdown("""
109
  ### Research Training Information
110
+
111
  This model is being fine-tuned on research-focused datasets and is not available for interactive querying.
112
+ The training process will run in the background and logs will be available in the Hugging Face UI.
113
 
114
+ #### Instructions
115
  1. Click "Start Training" to begin the fine-tuning process
116
+ 2. Monitor progress in the Hugging Face "Logs" tab
117
+ 3. Training metrics and results will be saved to the output directory
118
+
119
+ #### About This Project
120
+ The model is being fine-tuned on the phi4-cognitive-dataset with a focus on research capabilities.
121
+ This training phase does not include any interactive features or output generation.
122
  """)
123
 
124
  # Launch the interface
125
  if __name__ == "__main__":
126
  # Start Gradio with minimal features
127
+ logger.info("Starting research training dashboard")
128
+ demo.launch(share=False)