import gradio as gr import os import subprocess folder_path = 'src/server' file_name = 'main.cs' file_path = os.path.join(folder_path, file_name) os.makedirs(folder_path, exist_ok=True) open('roblox-cs.yml', 'w').write("""SourceFolder: src OutputFolder: dist EmitNativeAttributeOnClassOrNamespaceCallbacks: true EnabledBuiltInTransformers: - Debug CSharpOptions: EntryPointRequired: false EntryPointName: Game MainMethodName: Main AssemblyName: ExampleProject""") def check_dotnet_installed(): try: result = subprocess.run(['dotnet', '--version'], stdout=subprocess.PIPE, stderr=subprocess.PIPE, text=True) if result.returncode == 0: print(f".NET is already installed. Version: {result.stdout.strip()}") return True else: print("Unable to find .NET installed.") return False except FileNotFoundError: print(".NET is not installed.") return False def install_dotnet(): print("Installing .NET SDK...") subprocess.run(["sudo", "apt-get", "update"], check=True, shell=True) subprocess.run(["sudo", "apt-get", "install", "-y", "dotnet-sdk-8.0"], check=True, shell=True) subprocess.run(["sudo", "apt-get", "install", "-y", "dotnet-runtime-8.0"], check=True, shell=True) print(".NET SDK has been installed.") def compile(cs): # Create file with open(file_path, 'w') as file: file.write(cs) # Run command try: result = subprocess.run( ['dotnet', 'run', '--project roblox-cs-master/RobloxCS.CLI/RobloxCS.CLI.csproj'], capture_output=True, text=True, check=True ) except subprocess.CalledProcessError as e: gr.Error(f"Error: `{e.stderr}`, Exit Status: {e.returncode}") except: gr.Error("Unknown error!") return 'ha' if not check_dotnet_installed(): install_dotnet() demo = gr.Interface(fn=compile, inputs="text", outputs="text") demo.launch()