Spaces:
Runtime error
Runtime error
Upload app.py with huggingface_hub
Browse files
app.py
CHANGED
|
@@ -19,11 +19,20 @@ def check_daily_limit():
|
|
| 19 |
today = datetime.now().date()
|
| 20 |
limit_file = f"daily_limit_{today}.txt"
|
| 21 |
|
|
|
|
| 22 |
if os.path.exists(limit_file):
|
| 23 |
-
|
| 24 |
-
|
| 25 |
-
|
| 26 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 27 |
|
| 28 |
return True, "Ready to train!"
|
| 29 |
|
|
@@ -34,6 +43,18 @@ def mark_daily_usage():
|
|
| 34 |
|
| 35 |
with open(limit_file, 'w') as f:
|
| 36 |
f.write(str(today))
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 37 |
|
| 38 |
def run_training():
|
| 39 |
"""Run the free H200 training."""
|
|
@@ -56,12 +77,19 @@ def run_training():
|
|
| 56 |
print("Starting free H200 training...")
|
| 57 |
start_time = time.time()
|
| 58 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 59 |
# Run training with timeout
|
| 60 |
process = subprocess.Popen(
|
| 61 |
["python", TRAINING_SCRIPT],
|
| 62 |
stdout=subprocess.PIPE,
|
| 63 |
stderr=subprocess.STDOUT,
|
| 64 |
-
universal_newlines=True
|
|
|
|
| 65 |
)
|
| 66 |
|
| 67 |
output_lines = []
|
|
@@ -133,6 +161,7 @@ with gr.Blocks(title="Nano-Coder Free H200 Training") as demo:
|
|
| 133 |
with gr.Column():
|
| 134 |
gr.Markdown("### π― Training Control")
|
| 135 |
train_button = gr.Button("π Start Free H200 Training", variant="primary")
|
|
|
|
| 136 |
status_text = gr.Textbox(label="Training Status", lines=10, interactive=False)
|
| 137 |
|
| 138 |
with gr.Column():
|
|
@@ -160,6 +189,11 @@ with gr.Blocks(title="Nano-Coder Free H200 Training") as demo:
|
|
| 160 |
outputs=status_text
|
| 161 |
)
|
| 162 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 163 |
model_status_button.click(
|
| 164 |
fn=check_model_status,
|
| 165 |
outputs=model_status_text
|
|
|
|
| 19 |
today = datetime.now().date()
|
| 20 |
limit_file = f"daily_limit_{today}.txt"
|
| 21 |
|
| 22 |
+
# For debugging, let's check what's in the file
|
| 23 |
if os.path.exists(limit_file):
|
| 24 |
+
try:
|
| 25 |
+
with open(limit_file, 'r') as f:
|
| 26 |
+
last_run = f.read().strip()
|
| 27 |
+
print(f"Debug: Found limit file with content: '{last_run}' for date: {today}")
|
| 28 |
+
if last_run == str(today):
|
| 29 |
+
return False, f"Daily H200 limit reached. Try again tomorrow! (Last run: {last_run})"
|
| 30 |
+
except Exception as e:
|
| 31 |
+
print(f"Debug: Error reading limit file: {e}")
|
| 32 |
+
# If there's an error reading the file, let's allow training
|
| 33 |
+
return True, "Ready to train! (Limit file error, allowing training)"
|
| 34 |
+
else:
|
| 35 |
+
print(f"Debug: No limit file found for today: {today}")
|
| 36 |
|
| 37 |
return True, "Ready to train!"
|
| 38 |
|
|
|
|
| 43 |
|
| 44 |
with open(limit_file, 'w') as f:
|
| 45 |
f.write(str(today))
|
| 46 |
+
print(f"Debug: Marked daily usage for {today}")
|
| 47 |
+
|
| 48 |
+
def reset_daily_limit():
|
| 49 |
+
"""Reset the daily limit (for testing)."""
|
| 50 |
+
today = datetime.now().date()
|
| 51 |
+
limit_file = f"daily_limit_{today}.txt"
|
| 52 |
+
|
| 53 |
+
if os.path.exists(limit_file):
|
| 54 |
+
os.remove(limit_file)
|
| 55 |
+
return f"β
Daily limit reset for {today}"
|
| 56 |
+
else:
|
| 57 |
+
return f"βΉοΈ No limit file found for {today}"
|
| 58 |
|
| 59 |
def run_training():
|
| 60 |
"""Run the free H200 training."""
|
|
|
|
| 77 |
print("Starting free H200 training...")
|
| 78 |
start_time = time.time()
|
| 79 |
|
| 80 |
+
# Set environment variables for HF
|
| 81 |
+
env = os.environ.copy()
|
| 82 |
+
# HF Spaces automatically provides HF_TOKEN
|
| 83 |
+
if 'HF_TOKEN' not in env:
|
| 84 |
+
env['HF_TOKEN'] = os.environ.get('HF_TOKEN', '')
|
| 85 |
+
|
| 86 |
# Run training with timeout
|
| 87 |
process = subprocess.Popen(
|
| 88 |
["python", TRAINING_SCRIPT],
|
| 89 |
stdout=subprocess.PIPE,
|
| 90 |
stderr=subprocess.STDOUT,
|
| 91 |
+
universal_newlines=True,
|
| 92 |
+
env=env
|
| 93 |
)
|
| 94 |
|
| 95 |
output_lines = []
|
|
|
|
| 161 |
with gr.Column():
|
| 162 |
gr.Markdown("### π― Training Control")
|
| 163 |
train_button = gr.Button("π Start Free H200 Training", variant="primary")
|
| 164 |
+
reset_button = gr.Button("π Reset Daily Limit", variant="secondary")
|
| 165 |
status_text = gr.Textbox(label="Training Status", lines=10, interactive=False)
|
| 166 |
|
| 167 |
with gr.Column():
|
|
|
|
| 189 |
outputs=status_text
|
| 190 |
)
|
| 191 |
|
| 192 |
+
reset_button.click(
|
| 193 |
+
fn=reset_daily_limit,
|
| 194 |
+
outputs=status_text
|
| 195 |
+
)
|
| 196 |
+
|
| 197 |
model_status_button.click(
|
| 198 |
fn=check_model_status,
|
| 199 |
outputs=model_status_text
|