Create app.py
Browse files
app.py
ADDED
|
@@ -0,0 +1,14 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import gradio as gr #webinterface
|
| 2 |
+
from transformers import AutoModelForCasualLM,Auto Tokenizer # for loading the moel and making the inputs into tokens
|
| 3 |
+
model_name="Salesforce/codegen-350M-multi"
|
| 4 |
+
|
| 5 |
+
#initialize the tokenizer and model
|
| 6 |
+
tokenizer=Auto Tokenizer.from_pretrained(model_name)
|
| 7 |
+
model=AutoModelForCasualLM.from_pretrained(model_name)
|
| 8 |
+
|
| 9 |
+
def generate_code(prompt,max_length=100,temperature=0.7,top_p=0.95):
|
| 10 |
+
inputs=tokenizer(prompt,return_tensors='pt')
|
| 11 |
+
output=model.generate(**inputs,max_length=max_length,temperature=temperature,top_p=top_p,do_sample=True)
|
| 12 |
+
|
| 13 |
+
generated_code=tokenizer.decode(outputs[0],skip_special_tokens=True)
|
| 14 |
+
return generated_code
|