| import gradio as gr
|
| import Evaluate1
|
| import Evaluate2
|
| import re
|
|
|
| def load_cpp_file(file):
|
| text = file.name
|
| with open(text, 'r', encoding='utf-8') as f:
|
| content = f.read()
|
| return content
|
|
|
| def Evaluate_Code(code, method):
|
| if method == 0:
|
| return Evaluate1.eval(code)
|
| elif method == 1:
|
| return Evaluate2.eval(code)
|
| elif method == 2:
|
| label1, conf1 = Evaluate1.eval(code)
|
| label2, conf2 = Evaluate2.eval(code)
|
| conf1_val = float(conf1.replace("%", "").strip())
|
| conf2_val = float(conf2.replace("%", "").strip())
|
| avg_conf = (conf1_val + conf2_val) / 2.0
|
| label = "AI" if avg_conf > 50.0 else "Human"
|
| return label, f"{avg_conf:.2f} %"
|
| else:
|
| return "Invalid method", "0.00 %"
|
|
|
| with gr.Blocks() as web:
|
| with gr.Row():
|
| with gr.Column(scale=1):
|
| code_box = gr.Textbox(lines=20, label="C++ Code")
|
| with gr.Column(scale=1):
|
| cpp_file = gr.File(label="Upload C++ File (.cpp)", file_types=[".cpp"])
|
| method_choice = gr.Radio(
|
| choices=["No Format", "Format Code", "Combine"],
|
| value=0,
|
| label="Evaluation Method"
|
| )
|
| check_btn = gr.Button("Check")
|
|
|
|
|
| with gr.Row():
|
| gr.Markdown("### Result :")
|
|
|
| with gr.Row():
|
| with gr.Column(scale=1):
|
| label_box = gr.Textbox(label="Label", interactive=False)
|
| with gr.Column(scale=1):
|
| confidence_box = gr.Textbox(label="AI Percentage", interactive=False)
|
|
|
|
|
| cpp_file.change(fn=load_cpp_file, inputs=cpp_file, outputs=code_box)
|
| check_btn.click(
|
| fn=Evaluate_Code,
|
| inputs=[code_box, method_choice],
|
| outputs=[label_box, confidence_box]
|
| )
|
|
|
| web.launch() |