Spaces:
Runtime error
Runtime error
Commit
·
d3fbab9
1
Parent(s):
6b980f5
Update app.py
Browse files
app.py
CHANGED
@@ -6,9 +6,12 @@ model_code2desc = AutoModel.from_pretrained("microsoft/codebert-base")
|
|
6 |
|
7 |
def code_to_description(code: str) -> str:
|
8 |
inputs = tokenizer_code2desc.encode("summarize: " + code, return_tensors="pt", max_length=512)
|
9 |
-
|
10 |
-
|
|
|
|
|
11 |
return description
|
12 |
|
13 |
iface = gr.Interface(fn=code_to_description, inputs="text", outputs="text")
|
14 |
iface.launch()
|
|
|
|
6 |
|
7 |
def code_to_description(code: str) -> str:
|
8 |
inputs = tokenizer_code2desc.encode("summarize: " + code, return_tensors="pt", max_length=512)
|
9 |
+
# Updated generate function
|
10 |
+
outputs = model_code2desc.generate(inputs, max_length=150, num_return_sequences=1, no_repeat_ngram_size=2, do_sample=True, top_k=50, top_p=0.95, temperature=0.8)
|
11 |
+
# Updated decode function
|
12 |
+
description = tokenizer_code2desc.decode(outputs[0], skip_special_tokens=True, clean_up_tokenization_spaces=True)
|
13 |
return description
|
14 |
|
15 |
iface = gr.Interface(fn=code_to_description, inputs="text", outputs="text")
|
16 |
iface.launch()
|
17 |
+
|