eddddyy commited on
Commit
799893f
·
verified ·
1 Parent(s): 1d096a4

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +19 -0
app.py ADDED
@@ -0,0 +1,19 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+
2
+ import gradio as gr
3
+ from transformers import pipeline, AutoTokenizer, AutoModelForCausalLM
4
+
5
+ model_id = "meta-llama/Llama-3.1-8B-Instruct"
6
+
7
+ tokenizer = AutoTokenizer.from_pretrained(model_id, use_auth_token=True)
8
+ model = AutoModelForCausalLM.from_pretrained(model_id, device_map="auto", load_in_4bit=True, use_auth_token=True)
9
+
10
+ pipe = pipeline("text-generation", model=model, tokenizer=tokenizer)
11
+
12
+ def ai_assistant(command):
13
+ prompt = f"<|begin_of_text|><|start_header_id|>user<|end_header_id|>\n{command}<|eot_id|><|start_header_id|>assistant<|end_header_id|>\n"
14
+ result = pipe(prompt, max_new_tokens=100)[0]["generated_text"]
15
+ return result.split("<|eot_id|>")[0].split("<|end_header_id|>\n")[-1].strip()
16
+
17
+ demo = gr.Interface(fn=ai_assistant, inputs="text", outputs="text", title="Llama 3.1 AI Assistant", description="Ask your assistant to do anything")
18
+
19
+ demo.launch()