Update app.py
Browse files
app.py
CHANGED
|
@@ -27,19 +27,38 @@ def detect_clone(code1, code2):
|
|
| 27 |
)
|
| 28 |
return result, sim_score
|
| 29 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 30 |
# Gradioインターフェースの作成
|
| 31 |
demo = gr.Interface(
|
| 32 |
fn=detect_clone,
|
| 33 |
inputs=[
|
| 34 |
-
gr.Textbox(label="コードスニペット1", lines=
|
| 35 |
-
gr.Textbox(label="コードスニペット2", lines=
|
| 36 |
],
|
| 37 |
outputs=[
|
| 38 |
gr.Markdown(label="判定結果"),
|
| 39 |
gr.Number(label="Cosine Similarity")
|
| 40 |
],
|
| 41 |
title="Code Clone Detection with ModernBERT-Owl 🦉",
|
| 42 |
-
description="Shuu12121/CodeModernBERT-Owl によって構築された Sentence-BERT
|
| 43 |
)
|
| 44 |
|
| 45 |
if __name__ == "__main__":
|
|
|
|
| 27 |
)
|
| 28 |
return result, sim_score
|
| 29 |
|
| 30 |
+
# Javaクローン例(ファイル読み込み)
|
| 31 |
+
java_code1 = """\
|
| 32 |
+
public static String readFileToString(File file, Charset encoding) throws IOException {
|
| 33 |
+
try (BufferedReader reader = new BufferedReader(new InputStreamReader(new FileInputStream(file), encoding))) {
|
| 34 |
+
StringBuilder sb = new StringBuilder();
|
| 35 |
+
String line;
|
| 36 |
+
while ((line = reader.readLine()) != null) {
|
| 37 |
+
sb.append(line).append("\\n");
|
| 38 |
+
}
|
| 39 |
+
return sb.toString();
|
| 40 |
+
}
|
| 41 |
+
}"""
|
| 42 |
+
|
| 43 |
+
java_code2 = """\
|
| 44 |
+
public static String readFileToString(File file, Charset encoding) throws IOException {
|
| 45 |
+
byte[] bytes = java.nio.file.Files.readAllBytes(file.toPath());
|
| 46 |
+
return new String(bytes, encoding);
|
| 47 |
+
}"""
|
| 48 |
+
|
| 49 |
# Gradioインターフェースの作成
|
| 50 |
demo = gr.Interface(
|
| 51 |
fn=detect_clone,
|
| 52 |
inputs=[
|
| 53 |
+
gr.Textbox(label="コードスニペット1", lines=12, value=java_code1),
|
| 54 |
+
gr.Textbox(label="コードスニペット2", lines=8, value=java_code2),
|
| 55 |
],
|
| 56 |
outputs=[
|
| 57 |
gr.Markdown(label="判定結果"),
|
| 58 |
gr.Number(label="Cosine Similarity")
|
| 59 |
],
|
| 60 |
title="Code Clone Detection with ModernBERT-Owl 🦉",
|
| 61 |
+
description="Shuu12121/CodeModernBERT-Owl によって構築された Sentence-BERT モデルを使用し、コードクローンを検出します。これは Java における意味的に同等なファイル読み込み関数の例です。"
|
| 62 |
)
|
| 63 |
|
| 64 |
if __name__ == "__main__":
|