Wirayudhia
commited on
Commit
·
ac1efe2
1
Parent(s):
90cb934
Initial commit of CodeT5p-220m demo app
Browse files- app.py +23 -0
- requirements.txt +3 -0
app.py
ADDED
|
@@ -0,0 +1,23 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import gradio as gr
|
| 2 |
+
from transformers import AutoModelForSeq2SeqLM, AutoTokenizer
|
| 3 |
+
|
| 4 |
+
model_name = "Salesforce/codet5p-220m"
|
| 5 |
+
|
| 6 |
+
tokenizer = AutoTokenizer.from_pretrained(model_name)
|
| 7 |
+
model = AutoModelForSeq2SeqLM.from_pretrained(model_name)
|
| 8 |
+
|
| 9 |
+
def generate_code(input_text):
|
| 10 |
+
inputs = tokenizer(input_text, return_tensors="pt")
|
| 11 |
+
outputs = model.generate(**inputs)
|
| 12 |
+
return tokenizer.decode(outputs[0], skip_special_tokens=True)
|
| 13 |
+
|
| 14 |
+
iface = gr.Interface(
|
| 15 |
+
fn=generate_code,
|
| 16 |
+
inputs=gr.Textbox(lines=5, label="Input Text"),
|
| 17 |
+
outputs=gr.Textbox(lines=10, label="Generated Code"),
|
| 18 |
+
title="CodeT5p-220m Code Generation",
|
| 19 |
+
description="Generate code snippets using Salesforce/codet5p-220m model"
|
| 20 |
+
)
|
| 21 |
+
|
| 22 |
+
if __name__ == "__main__":
|
| 23 |
+
iface.launch()
|
requirements.txt
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
transformers
|
| 2 |
+
torch
|
| 3 |
+
gradio
|