Spaces:
Runtime error
Runtime error
reqs added
Browse files
app.py
CHANGED
@@ -4,21 +4,26 @@ import torch
|
|
4 |
|
5 |
import transformers
|
6 |
import torch
|
|
|
|
|
|
|
|
|
|
|
|
|
7 |
|
8 |
-
model_id = "meta-llama/Meta-Llama-3-8B"
|
9 |
|
10 |
-
pipeline = transformers.pipeline(
|
11 |
-
"text-generation", model=model_id, model_kwargs={"torch_dtype": torch.bfloat16}, device_map="auto"
|
12 |
-
)
|
13 |
@spaces.GPU
|
14 |
def yes_man(message, history):
|
15 |
-
|
|
|
|
|
|
|
16 |
|
17 |
gr.ChatInterface(
|
18 |
yes_man,
|
19 |
chatbot=gr.Chatbot(height=300),
|
20 |
-
textbox=gr.Textbox(placeholder="
|
21 |
-
title="
|
22 |
description="Ask Yes Man any question",
|
23 |
theme="soft",
|
24 |
examples=["Hello", "Am I cool?", "Are tomatoes vegetables?"],
|
|
|
4 |
|
5 |
import transformers
|
6 |
import torch
|
7 |
+
from transformers import AutoModelForCausalLM, AutoTokenizer
|
8 |
+
|
9 |
+
model_name = "meta-llama/Meta-Llama-3-8B"
|
10 |
+
|
11 |
+
tokenizer = AutoTokenizer.from_pretrained(model_name)
|
12 |
+
model = AutoModelForCausalLM.from_pretrained(model_name, torch_dtype=torch.float16,device_map="auto")
|
13 |
|
|
|
14 |
|
|
|
|
|
|
|
15 |
@spaces.GPU
|
16 |
def yes_man(message, history):
|
17 |
+
input_ids = tokenizer(message, return_tensors="pt").input_ids.to(model.device)
|
18 |
+
output = model.generate(input_ids, max_length=512, num_return_sequences=1)
|
19 |
+
detailed_prompt = tokenizer.decode(output[0], skip_special_tokens=True)
|
20 |
+
return detailed_prompt
|
21 |
|
22 |
gr.ChatInterface(
|
23 |
yes_man,
|
24 |
chatbot=gr.Chatbot(height=300),
|
25 |
+
textbox=gr.Textbox(placeholder="Enter message here", container=False, scale=7),
|
26 |
+
title="LLAMA 3 8B Chat",
|
27 |
description="Ask Yes Man any question",
|
28 |
theme="soft",
|
29 |
examples=["Hello", "Am I cool?", "Are tomatoes vegetables?"],
|