Add multimodal
Browse files
app.py
CHANGED
|
@@ -5,16 +5,37 @@ 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 |
with gr.Blocks() as web:
|
| 13 |
with gr.Row():
|
| 14 |
with gr.Column(scale=1):
|
| 15 |
code_box = gr.Textbox(lines=20, label="C++ Code")
|
| 16 |
with gr.Column(scale=1):
|
| 17 |
cpp_file = gr.File(label="Upload C++ File (.cpp)", file_types=[".cpp"])
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 18 |
check_btn = gr.Button("Check")
|
| 19 |
|
| 20 |
# Result section
|
|
@@ -23,25 +44,16 @@ with gr.Blocks() as web:
|
|
| 23 |
|
| 24 |
with gr.Row():
|
| 25 |
with gr.Column(scale=1):
|
| 26 |
-
|
| 27 |
-
with gr.Column(scale=1):
|
| 28 |
-
confidence_box1 = gr.Textbox(label="AI Percentage", interactive=False)
|
| 29 |
-
|
| 30 |
-
with gr.Row():
|
| 31 |
-
gr.Markdown("### Result (Code Format) :")
|
| 32 |
-
|
| 33 |
-
with gr.Row():
|
| 34 |
-
with gr.Column(scale=1):
|
| 35 |
-
label_box2 = gr.Textbox(label="Label", interactive=False)
|
| 36 |
with gr.Column(scale=1):
|
| 37 |
-
|
| 38 |
|
| 39 |
# Bind functions
|
| 40 |
cpp_file.change(fn=load_cpp_file, inputs=cpp_file, outputs=code_box)
|
| 41 |
check_btn.click(
|
| 42 |
-
|
| 43 |
-
|
| 44 |
-
|
| 45 |
)
|
| 46 |
|
| 47 |
web.launch()
|
|
|
|
| 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
|
|
|
|
| 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()
|