Spaces:
Runtime error
Runtime error
Commit
·
678810a
1
Parent(s):
51c0b94
Create app.py
Browse files
app.py
ADDED
@@ -0,0 +1,23 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import torch
|
2 |
+
import transformers
|
3 |
+
from transformers import AutoTokenizer, AutoModelForSeq2SeqLM
|
4 |
+
import gradio as gr
|
5 |
+
|
6 |
+
tokenizer = AutoTokenizer.from_pretrained("AhmedSSoliman/MarianCG_NL2Code")
|
7 |
+
model = AutoModelForSeq2SeqLM.from_pretrained("AhmedSSoliman/MarianCG_NL2Code")
|
8 |
+
|
9 |
+
def generate_code(NL):
|
10 |
+
inputs = tokenizer([NL], padding="max_length", truncation=True, max_length=512, return_tensors="pt")
|
11 |
+
input_ids = inputs.input_ids.to("cuda")
|
12 |
+
attention_mask = inputs.attention_mask.to("cuda")
|
13 |
+
outputs = new_model.generate(input_ids, attention_mask=attention_mask)
|
14 |
+
# all special tokens including will be removed
|
15 |
+
output_code = tokenizer.batch_decode(outputs, skip_special_tokens=True)
|
16 |
+
return output_code
|
17 |
+
|
18 |
+
|
19 |
+
iface = gr.Interface(fn=generate_code, inputs="text", outputs="text")
|
20 |
+
iface.launch()
|
21 |
+
|
22 |
+
#output_text = gr.outputs.Textbox()
|
23 |
+
#gr.Interface(generate_code,"textbox", output_text, title="MarianMT Code Generation", description="MarianMT Code Generation").launch()
|