Update app.py
Browse files
app.py
CHANGED
@@ -8,6 +8,7 @@ from typing import List
|
|
8 |
import zipfile
|
9 |
import os
|
10 |
import io
|
|
|
11 |
|
12 |
def calculate_similarity(code1, code2, Ws, Wl, Wj, model_name):
|
13 |
model = SentenceTransformer(model_name)
|
@@ -96,29 +97,25 @@ def get_sim_list(zipped_file,Ws, Wl, Wj, model_name,threshold,number_results):
|
|
96 |
return result
|
97 |
|
98 |
# Define the Gradio app
|
99 |
-
with gr.Blocks(
|
100 |
# Tab for similarity calculation
|
101 |
with gr.Tab("Code Pair Similarity"):
|
102 |
# Input components
|
103 |
code1 = gr.Textbox(label="Code 1")
|
104 |
code2 = gr.Textbox(label="Code 2")
|
105 |
|
|
|
|
|
|
|
|
|
|
|
|
|
106 |
# Accordion for weights and models
|
107 |
with gr.Accordion("Weights and Models", open=False):
|
108 |
Ws = gr.Slider(0, 1, value=0.7, label="Semantic Search Weight", step=0.1)
|
109 |
Wl = gr.Slider(0, 1, value=0.3, label="Levenshiern Distance Weight", step=0.1)
|
110 |
Wj = gr.Slider(0, 1, value=0.0, label="Jaro Winkler Weight", step=0.1)
|
111 |
-
|
112 |
-
[("codebert", "microsoft/codebert-base"),
|
113 |
-
("graphcodebert", "microsoft/graphcodebert-base"),
|
114 |
-
("UnixCoder", "microsoft/unixcoder-base-unimodal"),
|
115 |
-
("CodeBERTa", "huggingface/CodeBERTa-small-v1"),
|
116 |
-
("CodeT5 small", "Salesforce/codet5-small"),
|
117 |
-
("PLBART", "uclanlp/plbart-java-cs"),],
|
118 |
-
label="Select Model",
|
119 |
-
value= "uclanlp/plbart-java-cs"
|
120 |
-
)
|
121 |
-
|
122 |
# Output component
|
123 |
output = gr.Textbox(label="Similarity Score")
|
124 |
|
@@ -142,20 +139,17 @@ with gr.Blocks(theme=gr.themes.Glass()) as demo:
|
|
142 |
# File uploader component
|
143 |
file_uploader = gr.File(label="Upload a Zip file",file_types=[".zip"])
|
144 |
|
|
|
|
|
|
|
|
|
|
|
|
|
145 |
with gr.Accordion("Weights and Models", open=False):
|
146 |
Ws = gr.Slider(0, 1, value=0.7, label="Semantic Search Weight", step=0.1)
|
147 |
Wl = gr.Slider(0, 1, value=0.3, label="Levenshiern Distance Weight", step=0.1)
|
148 |
Wj = gr.Slider(0, 1, value=0.0, label="Jaro Winkler Weight", step=0.1)
|
149 |
-
|
150 |
-
[("codebert", "microsoft/codebert-base"),
|
151 |
-
("graphcodebert", "microsoft/graphcodebert-base"),
|
152 |
-
("UnixCoder", "microsoft/unixcoder-base-unimodal"),
|
153 |
-
("CodeBERTa", "huggingface/CodeBERTa-small-v1"),
|
154 |
-
("CodeT5 small", "Salesforce/codet5-small"),
|
155 |
-
("PLBART", "uclanlp/plbart-java-cs"),],
|
156 |
-
label="Select Model",
|
157 |
-
value= "uclanlp/plbart-java-cs"
|
158 |
-
)
|
159 |
threshold = gr.Slider(0, 1, value=0, label="Threshold", step=0.01)
|
160 |
number_results = gr.Slider(1, 1000, value=10, label="Number of Returned pairs", step=1)
|
161 |
|
|
|
8 |
import zipfile
|
9 |
import os
|
10 |
import io
|
11 |
+
from gradio_huggingfacehub_search import HuggingfaceHubSearch
|
12 |
|
13 |
def calculate_similarity(code1, code2, Ws, Wl, Wj, model_name):
|
14 |
model = SentenceTransformer(model_name)
|
|
|
97 |
return result
|
98 |
|
99 |
# Define the Gradio app
|
100 |
+
with gr.Blocks() as demo:
|
101 |
# Tab for similarity calculation
|
102 |
with gr.Tab("Code Pair Similarity"):
|
103 |
# Input components
|
104 |
code1 = gr.Textbox(label="Code 1")
|
105 |
code2 = gr.Textbox(label="Code 2")
|
106 |
|
107 |
+
model_dropdown = HuggingfaceHubSearch(
|
108 |
+
label="Pre-Trained Model to use for Embeddings",
|
109 |
+
placeholder="Search for Pre-Trained models on Hugging Face",
|
110 |
+
search_type="model",
|
111 |
+
)
|
112 |
+
|
113 |
# Accordion for weights and models
|
114 |
with gr.Accordion("Weights and Models", open=False):
|
115 |
Ws = gr.Slider(0, 1, value=0.7, label="Semantic Search Weight", step=0.1)
|
116 |
Wl = gr.Slider(0, 1, value=0.3, label="Levenshiern Distance Weight", step=0.1)
|
117 |
Wj = gr.Slider(0, 1, value=0.0, label="Jaro Winkler Weight", step=0.1)
|
118 |
+
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
119 |
# Output component
|
120 |
output = gr.Textbox(label="Similarity Score")
|
121 |
|
|
|
139 |
# File uploader component
|
140 |
file_uploader = gr.File(label="Upload a Zip file",file_types=[".zip"])
|
141 |
|
142 |
+
model_dropdown = HuggingfaceHubSearch(
|
143 |
+
label="Pre-Trained Model to use for Embeddings",
|
144 |
+
placeholder="Search for Pre-Trained models on Hugging Face",
|
145 |
+
search_type="model",
|
146 |
+
)
|
147 |
+
|
148 |
with gr.Accordion("Weights and Models", open=False):
|
149 |
Ws = gr.Slider(0, 1, value=0.7, label="Semantic Search Weight", step=0.1)
|
150 |
Wl = gr.Slider(0, 1, value=0.3, label="Levenshiern Distance Weight", step=0.1)
|
151 |
Wj = gr.Slider(0, 1, value=0.0, label="Jaro Winkler Weight", step=0.1)
|
152 |
+
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
153 |
threshold = gr.Slider(0, 1, value=0, label="Threshold", step=0.01)
|
154 |
number_results = gr.Slider(1, 1000, value=10, label="Number of Returned pairs", step=1)
|
155 |
|