Spaces:
Sleeping
Sleeping
| import gradio as gr | |
| import subprocess | |
| import threading | |
| import time | |
| # Fungsi untuk menjalankan Django di thread terpisah | |
| def start_django(): | |
| process = subprocess.Popen( | |
| ["python", "manage.py", "runserver", "0.0.0.0:8000", "--noreload"], | |
| stdout=subprocess.PIPE, | |
| stderr=subprocess.PIPE | |
| ) | |
| time.sleep(5) # Beri waktu Django untuk berjalan | |
| return "Django server berjalan di http://127.0.0.1:8000" | |
| def run_server(): | |
| thread = threading.Thread(target=start_django) | |
| thread.daemon = True | |
| thread.start() | |
| return "Server Django sedang berjalan..." | |
| # UI Gradio | |
| iface = gr.Interface( | |
| fn=run_server, | |
| inputs=[], | |
| outputs="text", | |
| title="Django Server Starter", | |
| description="Klik tombol di bawah untuk menjalankan Django Server." | |
| ) | |
| if __name__ == "__main__": | |
| iface.launch(share=True, server_port=7860) # Pastikan Gradio menggunakan port yang berbeda | |