Spaces:
Runtime error
Runtime error
Create app.py
Browse files
app.py
ADDED
@@ -0,0 +1,21 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
from transformers import AutoTokenizer, AutoModelForCausalLM
|
2 |
+
import gradio as gr
|
3 |
+
|
4 |
+
model_name = "Salesforce/codegen-350M-mono"
|
5 |
+
codegen_token = AutoTokenizer.from_pretrained(model_name)
|
6 |
+
model = AutoTokenizer.from_pretrained(model_name)
|
7 |
+
|
8 |
+
def codegen(intent):
|
9 |
+
"""Give input as text which reflects intent of the program.
|
10 |
+
"""
|
11 |
+
#text = "Write a function which takes 2 numbers as input and returns the larger of the two."
|
12 |
+
|
13 |
+
input_ids = codegen_token(intent, return_tensors="pt").input_ids
|
14 |
+
outcode_ids = model.generate(input_ids, max_length=128)
|
15 |
+
response = codegen_token.decode(outcode_ids[0], skip_special_tokens=True)
|
16 |
+
return response
|
17 |
+
|
18 |
+
# UX
|
19 |
+
in_text = gr.Textbox(lines=1, label="Place your intent here.")
|
20 |
+
out = gr.Textbox(lines=1, label="Generated python code", placeholder="")
|
21 |
+
gr.Interface(codegen, inputs=in_text, outputs=out).lanuch()
|