CoolFace
Apppublic

Akshatg007/CodeSimilarity

sourceHugging Facemitupdated 6mo agoView on Hugging Face
0likes
app.py34 linesDownload Raw Back to root
1import gradio as gr2from model_inference import compare_programs, load_weights3 4 5with gr.Blocks() as demo:6    gr.Markdown("## CodeGNN Clone Detection")7    gr.Markdown(8        "Paste/Write two code snippets below (C/C++) and click **Compare**. "9        "The app will run CodeGNN model and report a similarity score."10    )11 12    with gr.Row():13        code1 = gr.Code(label="Code 1", language="python")14        code2 = gr.Code(label="Code 2", language="python")15 16    compare_button = gr.Button("Compare with CodeGNN")17    output = gr.Textbox(label="Result", lines=10)18 19    def ui_compare(c1, c2):20        return compare_programs(c1, c2)21 22    compare_button.click(fn=ui_compare, inputs=[code1, code2], outputs=output)23 24 25if __name__ == "__main__":26    # Load trained weights before launching the app.27    # Make sure 'code_gnn_model.pth' is present in the same folder.28    try:29        load_weights("code_gnn_model.pth")30    except FileNotFoundError:31        print("Warning: 'code_gnn_model.pth' not found. The model will use random weights.")32 33    demo.launch()34