Spaces:
Build error
Build error
| from .parse import parse_csharp | |
| from .mapper import load_mapping | |
| from .synth import synthesize_cpp, synthesize_blueprint_python | |
| from .llm_client import generate_with_hf, generate_with_openai | |
| class TranslationAgent: | |
| def __init__(self, mapping_path="mapping_table.json"): | |
| self.mapping = load_mapping(mapping_path) | |
| def translate(self, csharp_code: str, target_format="both", model_choice="hf"): | |
| """ | |
| Convert Unity C# code into Unreal C++ and/or Blueprint Python. | |
| Args: | |
| csharp_code: Unity source | |
| target_format: "cpp", "blueprint", or "both" | |
| model_choice: "hf" or "openai" | |
| """ | |
| parsed = parse_csharp(csharp_code) | |
| results = {"cpp": "", "blueprint_py": ""} | |
| # choose model backend | |
| backend = "hf" if model_choice == "hf" else "openai" | |
| if target_format in ("cpp", "both"): | |
| results["cpp"] = synthesize_cpp(parsed, self.mapping, model_backend=backend) | |
| if target_format in ("blueprint", "both"): | |
| results["blueprint_py"] = synthesize_blueprint_python(parsed, self.mapping, model_backend=backend) | |
| return results["cpp"], results["blueprint_py"] | |