hf-dongpyo commited on
Commit
d89c47c
·
1 Parent(s): 8dc2cd0

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +24 -0
app.py ADDED
@@ -0,0 +1,24 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from transformers import AutoTokenizer, AutoModelForCausalLM
2
+ import gradio as grad
3
+
4
+ codegen_tkn = AutoTokenizer.from_pretrained('Salesforce/codegen-350M-mono')
5
+ mdl = AutoModelForCausalLM.from_pretrained('Salesforce/codegen-250M-mono')
6
+
7
+ def codegen(intent):
8
+ # given input as text which reflects intent of the program.
9
+ # text = " write a function which takes 2 numbers as input
10
+ # and returns the larger of the two"
11
+ input_ids = codegen_tkn(intent, return_tensors = 'pt').input_ids
12
+ gen_ids = mdl.generate(input_ids, max_length = 128)
13
+ response = codegen_tkn.decode(gen_ids[0], skip_special_tokens = True)
14
+
15
+ return response
16
+
17
+ output = grad.Textbox(lines = 1, label = 'Generated Python Code', placeholder = '')
18
+ inp = grad.Textbox(lines = 1, label = 'Place your intent here')
19
+ grad.Interface(
20
+ codegen,
21
+ inputs = inp,
22
+ outputs = output
23
+ ).launch()
24
+