Spaces:
Build error
Build error
AhmedSSoliman
commited on
Commit
·
b6cca88
1
Parent(s):
9cb4e36
Create app.py
Browse files
app.py
ADDED
@@ -0,0 +1,24 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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-DJANGO")
|
7 |
+
model = AutoModelForSeq2SeqLM.from_pretrained("AhmedSSoliman/MarianCG-DJANGO")
|
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
|
12 |
+
attention_mask = inputs.attention_mask
|
13 |
+
outputs = model.generate(input_ids, attention_mask=attention_mask)
|
14 |
+
|
15 |
+
output_code = tokenizer.decode(outputs[0], 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 |
+
#iface.launch(share=True)
|
22 |
+
|
23 |
+
#output_text = gr.outputs.Textbox()
|
24 |
+
#gr.Interface(generate_code,"textbox", output_text, title="MarianCG model for Code Generation", description="MarianCG model for Code Generation").launch()
|