Spaces:
Runtime error
Runtime error
Initial app.py with LLaMA 3.1 assistant
Browse files
app.py
ADDED
|
@@ -0,0 +1,15 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# app.py
|
| 2 |
+
import gradio as gr
|
| 3 |
+
from transformers import AutoModelForCausalLM, AutoTokenizer, pipeline
|
| 4 |
+
|
| 5 |
+
model_id = "meta-llama/Llama-3.1-8B-Instruct"
|
| 6 |
+
|
| 7 |
+
tokenizer = AutoTokenizer.from_pretrained(model_id)
|
| 8 |
+
model = AutoModelForCausalLM.from_pretrained(model_id, device_map="auto")
|
| 9 |
+
pipe = pipeline("text-generation", model=model, tokenizer=tokenizer)
|
| 10 |
+
|
| 11 |
+
def chat_with_llama(prompt):
|
| 12 |
+
result = pipe(prompt, max_new_tokens=256, do_sample=True, temperature=0.7)
|
| 13 |
+
return result[0]['generated_text']
|
| 14 |
+
|
| 15 |
+
gr.Interface(fn=chat_with_llama, inputs="text", outputs="text", title="Venkat Assistant").launch()
|