buelfhood commited on
Commit
74a99d1
·
verified ·
1 Parent(s): abf5c11

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +23 -17
app.py CHANGED
@@ -8,7 +8,6 @@ from typing import List
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)
@@ -93,29 +92,33 @@ def get_sim_list(zipped_file,Ws, Wl, Wj, model_name,threshold,number_results):
93
  similarity_df = pd.concat([pd.DataFrame(pairs_results)], ignore_index=True)
94
  similarity_df = similarity_df.sort_values(by='similarity_score', ascending=False)
95
  result = filter_and_return_top(similarity_df,threshold,number_results).round(2)
 
96
  return result
97
 
98
  # Define the Gradio app
99
- with gr.Blocks() as demo:
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
- model_dropdown = HuggingfaceHubSearch(
107
- label="Pre-Trained Model to use for Embeddings",
108
- placeholder="Search for Pre-Trained models on Hugging Face",
109
- search_type="model",
110
- #value = "huggingface/CodeBERTa-small-v1"
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,17 +142,20 @@ with gr.Blocks() as demo:
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
 
 
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)
 
92
  similarity_df = pd.concat([pd.DataFrame(pairs_results)], ignore_index=True)
93
  similarity_df = similarity_df.sort_values(by='similarity_score', ascending=False)
94
  result = filter_and_return_top(similarity_df,threshold,number_results).round(2)
95
+
96
  return result
97
 
98
  # Define the Gradio app
99
+ with gr.Blocks(theme=gr.themes.Glass()) as demo:
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
+ model_dropdown = gr.Dropdown(
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
  # 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
+ model_dropdown = gr.Dropdown(
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