Create app.py
Browse files
app.py
ADDED
|
@@ -0,0 +1,15 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import gradio as gr
|
| 2 |
+
from transformers import AutoTokenizer, AutoModelForCausalLM, pipeline
|
| 3 |
+
|
| 4 |
+
model_id = "codellama/CodeLlama-34b-hf" # You can change to 13b or 34b if you have the hardware
|
| 5 |
+
|
| 6 |
+
tokenizer = AutoTokenizer.from_pretrained(model_id)
|
| 7 |
+
model = AutoModelForCausalLM.from_pretrained(model_id, device_map="auto", torch_dtype="auto")
|
| 8 |
+
|
| 9 |
+
pipe = pipeline("text-generation", model=model, tokenizer=tokenizer)
|
| 10 |
+
|
| 11 |
+
def generate_code(prompt):
|
| 12 |
+
output = pipe(prompt, max_new_tokens=200, do_sample=True, temperature=0.7)
|
| 13 |
+
return output[0]["generated_text"]
|
| 14 |
+
|
| 15 |
+
gr.Interface(fn=generate_code, inputs="text", outputs="text", title="Code Llama Playground").launch()
|