George-API commited on
Commit
2e87761
·
verified ·
1 Parent(s): 6fda5d8

Upload app.py with huggingface_hub

Browse files
Files changed (1) hide show
  1. app.py +115 -0
app.py ADDED
@@ -0,0 +1,115 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import gradio as gr
2
+ import os
3
+ import json
4
+ import torch
5
+ from dotenv import load_dotenv
6
+ import logging
7
+
8
+ # Configure logging
9
+ logging.basicConfig(
10
+ level=logging.INFO,
11
+ format='%(asctime)s - %(name)s - %(levelname)s - %(message)s',
12
+ handlers=[
13
+ logging.StreamHandler(),
14
+ logging.FileHandler("app.log")
15
+ ]
16
+ )
17
+ logger = logging.getLogger(__name__)
18
+
19
+ # Load environment variables
20
+ load_dotenv()
21
+
22
+ # Load config file
23
+ def load_config(config_path="transformers_config.json"):
24
+ try:
25
+ with open(config_path, 'r') as f:
26
+ config = json.load(f)
27
+ return config
28
+ except Exception as e:
29
+ logger.error(f"Error loading config: {str(e)}")
30
+ return {}
31
+
32
+ # Load configuration
33
+ config = load_config()
34
+ model_config = config.get("model_config", {})
35
+
36
+ # Model details from config
37
+ MODEL_NAME = model_config.get("model_name_or_path", "unsloth/DeepSeek-R1-Distill-Qwen-14B-bnb-4bit")
38
+ SPACE_NAME = os.getenv("HF_SPACE_NAME", "phi4training")
39
+ TRAINING_ACTIVE = os.path.exists("TRAINING_ACTIVE")
40
+
41
+ # Create Gradio interface - training status only, no model outputs
42
+ with gr.Blocks(css="footer {visibility: hidden}") as demo:
43
+ gr.Markdown(f"# {SPACE_NAME}: Training Status Dashboard")
44
+
45
+ with gr.Row():
46
+ with gr.Column():
47
+ status = gr.Markdown(
48
+ f"""
49
+ ## Research Training Phase Active
50
+
51
+ **Model**: {MODEL_NAME}
52
+ **Dataset**: phi4-cognitive-dataset
53
+
54
+ This is a multidisciplinary research training phase. The model is not available for interactive use.
55
+
56
+ ### Training Configuration:
57
+ - **Epochs**: {config.get("training_config", {}).get("num_train_epochs", 3)}
58
+ - **Batch Size**: {config.get("training_config", {}).get("per_device_train_batch_size", 2)}
59
+ - **Gradient Accumulation Steps**: {config.get("training_config", {}).get("gradient_accumulation_steps", 4)}
60
+ - **Learning Rate**: {config.get("training_config", {}).get("learning_rate", 2e-5)}
61
+ - **Max Sequence Length**: {config.get("training_config", {}).get("max_seq_length", 2048)}
62
+
63
+ ### Training Status:
64
+ {"🟢 Training in progress" if TRAINING_ACTIVE else "⚪ Training not currently active"}
65
+
66
+ ⚠️ **NOTE**: This space does not provide model outputs during the research training phase.
67
+ """
68
+ )
69
+
70
+ # Add a refresh button to check status
71
+ refresh_btn = gr.Button("Refresh Status")
72
+
73
+ def refresh_status():
74
+ # Re-check if training is active
75
+ training_active = os.path.exists("TRAINING_ACTIVE")
76
+ return f"""
77
+ ## Research Training Phase Active
78
+
79
+ **Model**: {MODEL_NAME}
80
+ **Dataset**: phi4-cognitive-dataset
81
+
82
+ This is a multidisciplinary research training phase. The model is not available for interactive use.
83
+
84
+ ### Training Configuration:
85
+ - **Epochs**: {config.get("training_config", {}).get("num_train_epochs", 3)}
86
+ - **Batch Size**: {config.get("training_config", {}).get("per_device_train_batch_size", 2)}
87
+ - **Gradient Accumulation Steps**: {config.get("training_config", {}).get("gradient_accumulation_steps", 4)}
88
+ - **Learning Rate**: {config.get("training_config", {}).get("learning_rate", 2e-5)}
89
+ - **Max Sequence Length**: {config.get("training_config", {}).get("max_seq_length", 2048)}
90
+
91
+ ### Training Status:
92
+ {"🟢 Training in progress" if training_active else "⚪ Training not currently active"}
93
+
94
+ ⚠️ **NOTE**: This space does not provide model outputs during the research training phase.
95
+ """
96
+
97
+ refresh_btn.click(refresh_status, outputs=status)
98
+
99
+ gr.Markdown("""
100
+ ### Research Training Information
101
+ This model is being fine-tuned on research-focused datasets and is not available for interactive querying.
102
+ Training logs are available to authorized researchers only.
103
+ """)
104
+
105
+ # Launch the interface
106
+ if __name__ == "__main__":
107
+ # Create an empty TRAINING_ACTIVE file to indicate training is in progress
108
+ # This would be managed by the actual training script
109
+ if not os.path.exists("TRAINING_ACTIVE"):
110
+ with open("TRAINING_ACTIVE", "w") as f:
111
+ f.write("Training in progress")
112
+
113
+ # Start Gradio with minimal features
114
+ logger.info("Starting training status dashboard")
115
+ demo.launch(share=False)