|
import gradio as gr
|
|
import os
|
|
from translator import get_translation_pipeline, translate_cobol_to_csharp
|
|
|
|
|
|
pipeline = get_translation_pipeline()
|
|
|
|
|
|
def translate_and_save(file_obj):
|
|
try:
|
|
if not file_obj:
|
|
return "β No file uploaded."
|
|
|
|
|
|
file_path = file_obj.name
|
|
|
|
|
|
with open(file_path, "r", encoding="utf-8") as f:
|
|
cobol_code = f.read()
|
|
|
|
|
|
base_name = os.path.splitext(os.path.basename(file_path))[0]
|
|
|
|
|
|
csharp_code = translate_cobol_to_csharp(pipeline, cobol_code)
|
|
|
|
|
|
output_file = f"{base_name}.cs"
|
|
with open(output_file, "w", encoding="utf-8") as f:
|
|
f.write(csharp_code)
|
|
|
|
return f"β
Translation complete. Saved as: {output_file}\n\n{csharp_code}"
|
|
|
|
except Exception as e:
|
|
return f"β ERROR: {str(e)}"
|
|
|
|
|
|
gr.Interface(
|
|
fn=translate_and_save,
|
|
inputs=gr.File(label="Upload COBOL File (.cob)", file_types=[".cob"]),
|
|
outputs=gr.Textbox(label="C# Output", lines=25),
|
|
title="COBOL to C# (.NET) Translator",
|
|
description="Upload a COBOL file. This app will translate it and save a .cs file."
|
|
).launch()
|
|
|