Spaces:
Build error
Build error
add files
Browse files- app.py +42 -0
- requirements.txt +2 -0
app.py
ADDED
@@ -0,0 +1,42 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import gradio as gr
|
2 |
+
from transformers import AutoTokenizer, AutoModelForSequenceClassification, pipeline
|
3 |
+
|
4 |
+
|
5 |
+
title = "Code Compexity Predictor"
|
6 |
+
description = "This is a space to predict complexity of Java code with [CodeParrot-Multi-Complexity](https://huggingface.co/codeparrot/codeparrot-small-multi),\
|
7 |
+
a multilingual model for code generation, finetuned on [CodeComplex](https://huggingface.co/datasets/codeparrot/codecomplex), a dataset for complexity prediction of Java code."
|
8 |
+
example = [
|
9 |
+
["code example 1", "nlogn"],
|
10 |
+
["code example 2", "constant"]]
|
11 |
+
|
12 |
+
# model to be changed to the finetuned one
|
13 |
+
tokenizer = AutoTokenizer.from_pretrained("codeparrot/codeparrot-small-multi")
|
14 |
+
model = AutoModelForSequenceClassification.from_pretrained("codeparrot/codeparrot-small-multi")
|
15 |
+
|
16 |
+
|
17 |
+
def complexity_estimation(gen_prompt, topk):
|
18 |
+
pipe = pipeline("text-classification", model=model, tokenizer=tokenizer)
|
19 |
+
label = pipe(gen_prompt, do_sample=True, top_k=topk)[0]['label']
|
20 |
+
return label
|
21 |
+
|
22 |
+
|
23 |
+
iface = gr.Interface(
|
24 |
+
fn=complexity_estimation,
|
25 |
+
inputs=[
|
26 |
+
gr.Textbox(lines=10, label="Input code"),
|
27 |
+
gr.inputs.Slider(
|
28 |
+
minimum=1,
|
29 |
+
maximum=3,
|
30 |
+
step=1,
|
31 |
+
default=1,
|
32 |
+
label="Number of results to return",
|
33 |
+
),
|
34 |
+
],
|
35 |
+
outputs=gr.Textbox(label="Predicted complexity", lines=10),
|
36 |
+
examples=example,
|
37 |
+
layout="vertical",
|
38 |
+
theme="peach",
|
39 |
+
description=description,
|
40 |
+
title=title
|
41 |
+
)
|
42 |
+
iface.launch()
|
requirements.txt
ADDED
@@ -0,0 +1,2 @@
|
|
|
|
|
|
|
1 |
+
transformers==4.19.0
|
2 |
+
torch==1.11.0
|