import os import subprocess import platform # Function to install Node.js and npm if not found def install_nodejs_npm(): system = platform.system().lower() if system == "linux": os.system("sudo apt update") os.system("sudo apt install -y nodejs npm") elif system == "darwin": os.system("brew install node") elif system == "windows": # You can provide instructions for Windows users to install Node.js manually print("Please install Node.js and npm manually for Windows.") else: print("Unsupported operating system. Please install Node.js and npm manually for your system.") # Check if Node.js and npm are installed try: subprocess.check_call(["node", "-v"]) subprocess.check_call(["npm", "-v"]) except FileNotFoundError: print("Node.js or npm not found. Installing Node.js and npm...") install_nodejs_npm() # Clone the GitHub repository os.system("git clone https://github.com/oobabooga/text-generation-webui.git") # Navigate to the project directory os.chdir("text-generation-webui") # Install Node.js dependencies os.system("npm install") # Start the Node.js server in the background node_process = subprocess.Popen(["npm", "start"]) # Wait for the Node.js server to start input("Press Enter when the Node.js server is running...") # Activate a virtual environment for Python os.system("python3 -m venv venv") if os.name == "posix": os.system("source venv/bin/activate") else: os.system("venv\\Scripts\\activate") # Install Gradio os.system("pip install gradio") # Modify the original code to integrate with Gradio # Example code: import gradio as gr def generate_text(input_text): # Replace this with your text generation logic generated_text = "Generated text goes here" return generated_text iface = gr.Interface( fn=generate_text, inputs=gr.Textbox(), outputs=gr.Textbox(), ) # Launch the Gradio interface iface.launch() # When you're done, you can manually stop the Node.js server and deactivate the virtual environment.