Spaces:
Sleeping
Sleeping
| # File: tasks.py (File ini mendefinisikan tugas latar belakang -fine-tuning- yang akan dijalankan oleh Celery.) | |
| import os | |
| from celery import Celery | |
| import subprocess | |
| # Ambil URL broker dari environment variable | |
| CELERY_BROKER_URL = os.getenv('CELERY_BROKER_URL', 'redis://redis:6379/0') | |
| # Inisialisasi aplikasi Celery | |
| celery_app = Celery('lessonplan_tasks', broker=CELERY_BROKER_URL) | |
| def start_lessonplan_finetune_task(): | |
| """ | |
| Tugas ini memanggil script fine-tuning utama. | |
| Ini akan dijalankan oleh Celery Worker di server GPU. | |
| """ | |
| try: | |
| print("Memulai proses fine-tuning untuk Lesson Plan Assistant...") | |
| # Menjalankan script sebagai proses terpisah | |
| # Pastikan environment worker memiliki akses ke semua environment variable | |
| result = subprocess.run( | |
| ["python", "simple_finetune.py"], | |
| check=True, | |
| capture_output=True, | |
| text=True | |
| ) | |
| print("Proses fine-tuning selesai.") | |
| print("Output:", result.stdout) | |
| return {"status": "Completed", "output": result.stdout} | |
| except subprocess.CalledProcessError as e: | |
| print(f"Error saat fine-tuning: {e.stderr}") | |
| return {"status": "Failed", "error": e.stderr} |