Sal-ONE commited on
Commit
f52d6eb
·
1 Parent(s): 7d928b8

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +43 -0
app.py ADDED
@@ -0,0 +1,43 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import torch
2
+ import gradio as gr
3
+ from transformers import AutoTokenizer, AutoModelForCausalLM, pipeline, logging
4
+
5
+
6
+ checkpoint = "Salesforce/codegen-350M-mono"
7
+
8
+ tokenizer = AutoTokenizer.from_pretrained(checkpoint, trust_remote_code=True)
9
+ model = AutoModelForCausalLM.from_pretrained(checkpoint, cache_dir="models/", trust_remote_code=True, revision="main")
10
+
11
+
12
+ def code_gen(text, max_tokens, temp, top_p, rep_penality):
13
+ logging.set_verbosity(logging.CRITICAL)
14
+ pipe = pipeline(
15
+ model=checkpoint,
16
+ max_new_tokens=max_tokens,
17
+ temperature=temp,
18
+ top_p=top_p,
19
+ device= "cuda" if torch.cuda.is_available() else "cpu",
20
+ repetition_penalty=rep_penality
21
+ )
22
+
23
+ response = pipe(text)
24
+ print(response)
25
+
26
+ return response[0]['generated_text']
27
+
28
+
29
+ Inferece = gr.Interface(
30
+ fn=code_gen,
31
+ inputs=[
32
+ gr.components.Textbox(label="Input what you want, the AI will make the code for you."),
33
+ gr.components.Slider(minimum=128, maximum=512, step=128, label="Choose Max Token"),
34
+ gr.components.Slider(minimum=0.1, maximum=1, step=0.05, label="Choose the model Temperature"),
35
+ gr.components.Slider(minimum=0.1, maximum=1.25, step=0.05, label="Choose top_p"),
36
+ gr.components.Slider(minimum=0.1, maximum=2, step=0.1, label="Choose repetition_penalty")
37
+ ],
38
+ outputs="text",
39
+ live=False # Ensure live is set to False
40
+ )
41
+
42
+ gr.Markdown('<h2 align="center">AI Code Gen</h2>')
43
+ Inferece.launch()