Spaces:
Running
Running
Upload app.py
Browse files
app.py
CHANGED
|
@@ -41,6 +41,7 @@ import random
|
|
| 41 |
|
| 42 |
def greet(X, ny):
|
| 43 |
global eng_dict
|
|
|
|
| 44 |
if ny == 0:
|
| 45 |
rand_no = random.random()
|
| 46 |
tok_map = {2: 0.4363429005892416,
|
|
@@ -173,27 +174,7 @@ def greet(X, ny):
|
|
| 173 |
# else:
|
| 174 |
# astr+=mock.capitalize()
|
| 175 |
er = er+" (with PLL value of: "+str(vali)+")"
|
| 176 |
-
return er
|
| 177 |
-
|
| 178 |
-
def meet(X):
|
| 179 |
-
tot_pll = 100.00
|
| 180 |
-
print_str = ""
|
| 181 |
-
fin_out = "The highest confidence prediction is: "
|
| 182 |
-
add_out = ""
|
| 183 |
-
for r in range(6):
|
| 184 |
-
er, pll = greet(X, 6-r)
|
| 185 |
-
print_str+= er
|
| 186 |
-
print_str+='\n'
|
| 187 |
-
if (pll - tot_pll) > 0.1:
|
| 188 |
-
break
|
| 189 |
-
elif pll >= tot_pll:
|
| 190 |
-
continue
|
| 191 |
-
else:
|
| 192 |
-
add_out = er
|
| 193 |
-
tot_pll = pll
|
| 194 |
-
print_str= print_str+fin_out+add_out
|
| 195 |
-
return print_str
|
| 196 |
-
|
| 197 |
title = "Rename a variable in a Java class"
|
| 198 |
description = """This model is a fine-tuned GraphCodeBERT model fine-tuned to output higher-quality variable names for Java classes. Long classes are handled by the
|
| 199 |
model. Replace any variable name with a "[MASK]" to get an identifier renaming.
|
|
@@ -219,7 +200,7 @@ ex.printStackTrace();
|
|
| 219 |
}
|
| 220 |
}
|
| 221 |
}
|
| 222 |
-
}"""], ["""import java.net.*;
|
| 223 |
import java.io.*;
|
| 224 |
|
| 225 |
public class s {
|
|
@@ -237,7 +218,7 @@ public class s {
|
|
| 237 |
if ([MASK] != null) [MASK].close();
|
| 238 |
}
|
| 239 |
}
|
| 240 |
-
}"""], ["""import java.io.*;
|
| 241 |
import java.util.*;
|
| 242 |
|
| 243 |
public class y {
|
|
@@ -254,13 +235,13 @@ public class y {
|
|
| 254 |
e.printStackTrace();
|
| 255 |
}
|
| 256 |
}
|
| 257 |
-
}"""]]
|
| 258 |
# We instantiate the Textbox class
|
| 259 |
textbox = gr.Textbox(label="Type Java code snippet:", placeholder="replace variable with [MASK]", lines=10)
|
| 260 |
-
|
| 261 |
|
| 262 |
-
gr.Interface(title = title, description = description, examples = ex, fn=
|
| 263 |
-
textbox
|
| 264 |
], outputs="text").launch()
|
| 265 |
|
| 266 |
|
|
|
|
| 41 |
|
| 42 |
def greet(X, ny):
|
| 43 |
global eng_dict
|
| 44 |
+
ny = int(ny)
|
| 45 |
if ny == 0:
|
| 46 |
rand_no = random.random()
|
| 47 |
tok_map = {2: 0.4363429005892416,
|
|
|
|
| 174 |
# else:
|
| 175 |
# astr+=mock.capitalize()
|
| 176 |
er = er+" (with PLL value of: "+str(vali)+")"
|
| 177 |
+
return er
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 178 |
title = "Rename a variable in a Java class"
|
| 179 |
description = """This model is a fine-tuned GraphCodeBERT model fine-tuned to output higher-quality variable names for Java classes. Long classes are handled by the
|
| 180 |
model. Replace any variable name with a "[MASK]" to get an identifier renaming.
|
|
|
|
| 200 |
}
|
| 201 |
}
|
| 202 |
}
|
| 203 |
+
}""", "0"], ["""import java.net.*;
|
| 204 |
import java.io.*;
|
| 205 |
|
| 206 |
public class s {
|
|
|
|
| 218 |
if ([MASK] != null) [MASK].close();
|
| 219 |
}
|
| 220 |
}
|
| 221 |
+
}""", "2"], ["""import java.io.*;
|
| 222 |
import java.util.*;
|
| 223 |
|
| 224 |
public class y {
|
|
|
|
| 235 |
e.printStackTrace();
|
| 236 |
}
|
| 237 |
}
|
| 238 |
+
}""", "2"]]
|
| 239 |
# We instantiate the Textbox class
|
| 240 |
textbox = gr.Textbox(label="Type Java code snippet:", placeholder="replace variable with [MASK]", lines=10)
|
| 241 |
+
textbox1 = gr.Textbox(label="Number of tokens in name:", placeholder="0 for randomly sampled number of tokens",lines=1)
|
| 242 |
|
| 243 |
+
gr.Interface(title = title, description = description, examples = ex, fn=greet, inputs=[
|
| 244 |
+
textbox,textbox1
|
| 245 |
], outputs="text").launch()
|
| 246 |
|
| 247 |
|