
!pip install mlflow boto3 openai import os
import mlflow
from datetime import datetime
# AUTO-CONFIGURATION - Just Run This Cell!
# Everything is pre-configured by the admin. No setup needed!
# Your username is automatically detected
STUDENT_NAME = os.environ.get('JUPYTERHUB_USER', 'Student')
# Verify setup
print("=" * 50)
print("STUDENT SETUP VERIFICATION")
print("=" * 50)
print(f" Student Name: {STUDENT_NAME}")
print(f" MLflow: {'Connected' if os.environ.get('MLFLOW_TRACKING_URI') else ' Not Set'}")
print(f" MinIO Storage: {'Connected' if os.environ.get('MLFLOW_S3_ENDPOINT_URL') else ' Not Set'}")
print(f" Credentials: {'Auto-configured' if os.environ.get('AWS_ACCESS_KEY_ID') else ' Not Set'}")
print("=" * 50)
print(f"\n Your files will be saved to: niet-minio-bucket/{STUDENT_NAME}/")
print("\n You're all set! Continue running the notebook.") from openai import OpenAI
client = OpenAI(
base_url="http://10.10.0.10:8000/v1",
api_key="class-secret-key-2026"
)
response = client.chat.completions.create(
model="mistralai/Mistral-7B-Instruct-v0.3",
messages=[{"role": "user", "content": "Your question here"}]
)
print(response.choices[0].message.content)import os
import mlflow
from datetime import datetime
# -----------------------------
# AUTO CONFIG (JupyterHub)
# -----------------------------
mlflow.set_tracking_uri(
os.environ.get(
"MLFLOW_TRACKING_URI",
"http://mlflow.mlops.svc.cluster.local:5000"
)
)
STUDENT_NAME = os.environ.get("JUPYTERHUB_USER", "Student")
# One experiment per student (recommended)
experiment_name = f"{STUDENT_NAME}_AUTO_TRACKING"
artifact_location = f"s3://niet-minio-bucket/{STUDENT_NAME}"
# Create or load experiment
try:
experiment_id = mlflow.create_experiment(
name=experiment_name,
artifact_location=artifact_location
)
print(f"Created experiment: {experiment_name}")
except:
experiment = mlflow.get_experiment_by_name(experiment_name)
experiment_id = experiment.experiment_id
print(f"Using existing experiment: {experiment_name}")
mlflow.set_experiment(experiment_name)
# -----------------------------
# ENABLE FULL AUTO-LOGGING
# -----------------------------
mlflow.autolog(log_models=True)
# -----------------------------
# AUTO RUN CONTEXT
# -----------------------------
with mlflow.start_run(run_name=f"{STUDENT_NAME}_AUTO_RUN_{datetime.now().strftime('%H%M%S')}"):
# Minimal manual metadata (optional)
mlflow.set_tag("student_name", STUDENT_NAME)
mlflow.set_tag("mode", "auto_tracking")
mlflow.set_tag("platform", "jupyterhub")
# -----------------------------
# STUDENT WORK STARTS HERE
# (ANY ML / GENAI / DATA CODE)
# -----------------------------
# Example: student creates outputs normally
os.makedirs("outputs", exist_ok=True)
with open("outputs/result.txt", "w") as f:
f.write("This file was automatically captured by MLflow.")
# Auto-log all outputs
mlflow.log_artifacts("outputs")
run_id = mlflow.active_run().info.run_id
# -----------------------------
# CONFIRMATION
# -----------------------------
print("\n AUTO TRACKING ENABLED SUCCESSFULLY")
print(f"Experiment ID : {experiment_id}")
print(f"Run ID : {run_id}")
print("\nMinIO Path:")
print(f"{STUDENT_NAME}/{experiment_id}/{run_id}/artifacts/")