baadror commited on
Commit
4797321
1 Parent(s): 04586ac

added files

Browse files
Files changed (2) hide show
  1. app.py +29 -0
  2. requirements.txt +3 -0
app.py ADDED
@@ -0,0 +1,29 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from transformers import AutoTokenizer, AutoModelForCausalLM
2
+ import gradio as gr
3
+
4
+ tokenizer = AutoTokenizer.from_pretrained("Salesforce/codegen-350M-mono")
5
+ model = AutoModelForCausalLM.from_pretrained("Salesforce/codegen-350M-mono")
6
+
7
+ # text = "create a function recieve two arguments that return sum as a result"
8
+ example_text = [ 'create a function to calculate the n!', "create a function recieve two arguments that return sum as a result"]
9
+
10
+ def get_code(prompt):
11
+ input_ids = tokenizer(prompt, return_tensors="pt").input_ids
12
+
13
+ generated_ids = model.generate(input_ids, max_length=128)
14
+ return tokenizer.decode(generated_ids[0], skip_special_tokens=True)
15
+
16
+ demo = gr.Blocks()
17
+
18
+ with demo:
19
+ gr.Markdown(
20
+ "## This Demo will generate python code only upto 128 tokens "
21
+ )
22
+ with gr.Row():
23
+ inputs = gr.Textbox(label='Prompt for generating code', lines=5)
24
+ outputs = gr.Textbox(label='Python Code', lines=10)
25
+ b1 = gr.Button('Generate Code')
26
+ gr.Examples(examples=example_text, inputs= inputs, outputs= outputs)
27
+
28
+ b1.click(fn = get_code,inputs= inputs, outputs= outputs )
29
+ demo.launch()
requirements.txt ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ gradio
2
+ transformers
3
+ torch