add application file
Browse files
deploy.py
ADDED
|
@@ -0,0 +1,29 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import gradio as gr
|
| 2 |
+
from transformers import AutoTokenizer, AutoModelForCausalLM
|
| 3 |
+
import torch
|
| 4 |
+
from transformers import pipeline
|
| 5 |
+
|
| 6 |
+
# Load our Tokenizer
|
| 7 |
+
tokenizer = AutoTokenizer.from_pretrained("huggingface/nlux/CodeLlama-7b-hf")
|
| 8 |
+
|
| 9 |
+
# Load your model
|
| 10 |
+
model = "./nlux/CodeLlama-7b-hf_merge"
|
| 11 |
+
|
| 12 |
+
# load into pipeline
|
| 13 |
+
pipe = pipeline("text-generation", model=model, tokenizer=tokenizer)
|
| 14 |
+
|
| 15 |
+
def predict(input):
|
| 16 |
+
# Generate text using the pipeline
|
| 17 |
+
outputs = pipe(input, max_new_tokens=256, do_sample=True, temperature=0.7, top_k=50, top_p=0.95, eos_token_id=pipe.tokenizer.eos_token_id, pad_token_id=pipe.tokenizer.pad_token_id)
|
| 18 |
+
output = outputs[0]['generated_text'].strip()
|
| 19 |
+
|
| 20 |
+
# Print results
|
| 21 |
+
print(f"Generated Answer:\\n{output}")
|
| 22 |
+
return output
|
| 23 |
+
|
| 24 |
+
# Create a Gradio interface
|
| 25 |
+
iface = gr.Interface(fn=predict, inputs="text", outputs="text")
|
| 26 |
+
|
| 27 |
+
# Launch the interface
|
| 28 |
+
iface.launch(share=True)
|
| 29 |
+
|