a0ms1n commited on
Commit
5198b48
·
1 Parent(s): 7e49edf

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +58 -58
app.py CHANGED
@@ -1,59 +1,59 @@
1
- import gradio as gr
2
- import Evaluate1
3
- import Evaluate2
4
- import re
5
-
6
- def load_cpp_file(file):
7
- text = file.name
8
- with open(text, 'r', encoding='utf-8') as f:
9
- content = f.read()
10
- return content
11
-
12
- def Evaluate_Code(code, method):
13
- if method == 0:
14
- return Evaluate1.eval(code)
15
- elif method == 1:
16
- return Evaluate2.eval(code)
17
- elif method == 2:
18
- label1, conf1 = Evaluate1.eval(code)
19
- label2, conf2 = Evaluate2.eval(code)
20
- conf1_val = float(conf1.replace("%", "").strip())
21
- conf2_val = float(conf2.replace("%", "").strip())
22
- avg_conf = (conf1_val + conf2_val) / 2.0
23
- label = "AI" if avg_conf > 50.0 else "Human"
24
- return label, f"{avg_conf:.2f} %"
25
- else:
26
- return "Invalid method", "0.00 %"
27
-
28
- with gr.Blocks() as web:
29
- with gr.Row():
30
- with gr.Column(scale=1):
31
- code_box = gr.Textbox(lines=20, label="C++ Code")
32
- with gr.Column(scale=1):
33
- cpp_file = gr.File(label="Upload C++ File (.cpp)", file_types=[".cpp"])
34
- method_choice = gr.Radio(
35
- choices=["No Format", "Format Code", "Combine"],
36
- value=0,
37
- label="Evaluation Method"
38
- )
39
- check_btn = gr.Button("Check")
40
-
41
- # Result section
42
- with gr.Row():
43
- gr.Markdown("### Result :")
44
-
45
- with gr.Row():
46
- with gr.Column(scale=1):
47
- label_box = gr.Textbox(label="Label", interactive=False)
48
- with gr.Column(scale=1):
49
- confidence_box = gr.Textbox(label="AI Percentage", interactive=False)
50
-
51
- # Bind functions
52
- cpp_file.change(fn=load_cpp_file, inputs=cpp_file, outputs=code_box)
53
- check_btn.click(
54
- fn=Evaluate_Code,
55
- inputs=[code_box, method_choice],
56
- outputs=[label_box, confidence_box]
57
- )
58
-
59
  web.launch()
 
1
+ import gradio as gr
2
+ import Evaluate1
3
+ import Evaluate2
4
+ import re
5
+
6
+ def load_cpp_file(file):
7
+ text = file.name
8
+ with open(text, 'r', encoding='utf-8') as f:
9
+ content = f.read()
10
+ return content
11
+
12
+ def Evaluate_Code(code, method):
13
+ if method == "No Format":
14
+ return Evaluate1.eval(code)
15
+ elif method == "Format Code":
16
+ return Evaluate2.eval(code)
17
+ elif method == "Combine":
18
+ label1, conf1 = Evaluate1.eval(code)
19
+ label2, conf2 = Evaluate2.eval(code)
20
+ conf1_val = float(conf1.replace("%", "").strip())
21
+ conf2_val = float(conf2.replace("%", "").strip())
22
+ avg_conf = (conf1_val + conf2_val) / 2.0
23
+ label = "AI" if avg_conf > 50.0 else "Human"
24
+ return label, f"{avg_conf:.2f} %"
25
+ else:
26
+ return "Invalid method", "0.00 %"
27
+
28
+ with gr.Blocks() as web:
29
+ with gr.Row():
30
+ with gr.Column(scale=1):
31
+ code_box = gr.Textbox(lines=20, label="C++ Code")
32
+ with gr.Column(scale=1):
33
+ cpp_file = gr.File(label="Upload C++ File (.cpp)", file_types=[".cpp"])
34
+ method_choice = gr.Radio(
35
+ choices=["No Format", "Format Code", "Combine"],
36
+ value=0,
37
+ label="Evaluation Method"
38
+ )
39
+ check_btn = gr.Button("Check")
40
+
41
+ # Result section
42
+ with gr.Row():
43
+ gr.Markdown("### Result :")
44
+
45
+ with gr.Row():
46
+ with gr.Column(scale=1):
47
+ label_box = gr.Textbox(label="Label", interactive=False)
48
+ with gr.Column(scale=1):
49
+ confidence_box = gr.Textbox(label="AI Percentage", interactive=False)
50
+
51
+ # Bind functions
52
+ cpp_file.change(fn=load_cpp_file, inputs=cpp_file, outputs=code_box)
53
+ check_btn.click(
54
+ fn=Evaluate_Code,
55
+ inputs=[code_box, method_choice],
56
+ outputs=[label_box, confidence_box]
57
+ )
58
+
59
  web.launch()