Alon Mota commited on
Commit ·
52ab3ac
1
Parent(s): 2ee692b
py files
Browse files- app.py +24 -0
- requirements.txt +4 -0
app.py
ADDED
|
@@ -0,0 +1,24 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from transformers import T5ForConditionalGeneration, AutoTokenizer
|
| 2 |
+
import gradio as gr
|
| 3 |
+
import os
|
| 4 |
+
cwd = os.getcwd()
|
| 5 |
+
|
| 6 |
+
print("Starting")
|
| 7 |
+
device = "cpu"
|
| 8 |
+
|
| 9 |
+
checkpoint = "./models/codet5_large_typescript"
|
| 10 |
+
|
| 11 |
+
tokenizer = AutoTokenizer.from_pretrained(checkpoint, local_files_only=True)
|
| 12 |
+
|
| 13 |
+
print("Loading Model")
|
| 14 |
+
model = T5ForConditionalGeneration.from_pretrained(checkpoint, local_files_only=True).to(device)
|
| 15 |
+
print("Model Loaded")
|
| 16 |
+
|
| 17 |
+
def completeCode(prompt):
|
| 18 |
+
inputs = tokenizer.encode(prompt, return_tensors="pt").to(device)
|
| 19 |
+
outputs = model.generate(inputs, max_new_tokens = 100, early_stopping = True ).to(device)
|
| 20 |
+
return tokenizer.decode(outputs[0])
|
| 21 |
+
|
| 22 |
+
iface = gr.Interface(fn=completeCode, inputs="text", outputs="text")
|
| 23 |
+
iface.launch()
|
| 24 |
+
print("Ready")
|
requirements.txt
ADDED
|
@@ -0,0 +1,4 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
transformers
|
| 2 |
+
torch
|
| 3 |
+
torchvision
|
| 4 |
+
torchaudio
|