Spaces:
Runtime error
Runtime error
Commit
·
abf3702
1
Parent(s):
a3a16ae
Upload 3 files
Browse files- app.py +14 -0
- readme.md +14 -0
- requirements.txt +2 -0
app.py
ADDED
|
@@ -0,0 +1,14 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import gradio as gr
|
| 2 |
+
from transformers import AutoTokenizer, AutoModelForSeq2SeqLM
|
| 3 |
+
|
| 4 |
+
tokenizer_code2desc = AutoTokenizer.from_pretrained("microsoft/codebert-base")
|
| 5 |
+
model_code2desc = AutoModelForSeq2SeqLM.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 |
+
outputs = model_code2desc.generate(inputs, max_length=150, num_return_sequences=1, no_repeat_ngram_size=2)
|
| 10 |
+
description = tokenizer_code2desc.decode(outputs[0], skip_special_tokens=True)
|
| 11 |
+
return description
|
| 12 |
+
|
| 13 |
+
iface = gr.Interface(fn=code_to_description, inputs="text", outputs="text")
|
| 14 |
+
iface.launch()
|
readme.md
ADDED
|
@@ -0,0 +1,14 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
---
|
| 2 |
+
title: Code-to-Detailed-English-Description
|
| 3 |
+
emoji: 🌍
|
| 4 |
+
colorFrom: red
|
| 5 |
+
colorTo: red
|
| 6 |
+
sdk: gradio
|
| 7 |
+
sdk_version: 3.30.3
|
| 8 |
+
app_file: app.py
|
| 9 |
+
pinned: true
|
| 10 |
+
license: mit
|
| 11 |
+
|
| 12 |
+
---
|
| 13 |
+
|
| 14 |
+
Check out the configuration reference at https://huggingface.co/docs/hub/spaces-config-refer
|
requirements.txt
ADDED
|
@@ -0,0 +1,2 @@
|
|
|
|
|
|
|
|
|
|
| 1 |
+
gradio
|
| 2 |
+
transformers
|