Spaces:
Sleeping
Sleeping
File size: 1,866 Bytes
7b260fb 3dad4f6 7b260fb 46f2d6a 7b260fb |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 |
import gradio as gr
from transformers import AutoTokenizer, AutoModelForCausalLM
import torch
# Load model and tokenizer
model_name = "Spestly/Athena-2-1.5B"
tokenizer = AutoTokenizer.from_pretrained(model_name)
model = AutoModelForCausalLM.from_pretrained(model_name, torch_dtype=torch.float32, low_cpu_mem_usage=True)
# Set to evaluation mode
model.eval()
def generate_response(message, history):
instruction = (
"You are an LLM called Athena. Aayan Mishra finetunes you. Anthropic does NOT train you. "
"You are a Qwen 2.5 fine-tune. Your purpose is the help the user accomplish their request to the best of your abilities. "
"Below is an instruction that describes a task. Answer it clearly and concisely.\n\n"
f"### Instruction:\n{message}\n\n### Response:"
)
inputs = tokenizer(instruction, return_tensors="pt")
with torch.no_grad():
outputs = model.generate(
**inputs,
max_new_tokens=1000,
num_return_sequences=1,
temperature=0.7,
top_p=0.9,
do_sample=True
)
response = tokenizer.decode(outputs[0], skip_special_tokens=True)
response = response.split("### Response:")[-1].strip()
return response
iface = gr.ChatInterface(
generate_response,
chatbot=gr.Chatbot(height=600, type="messages"),
textbox=gr.Textbox(placeholder="Type your message here...", container=False, scale=7),
title="Athena-2 🏛️ - Beta",
description="Chat with Athena-2 (Beta) Please note that since Athena-2 is in beta, some outputs may not be accurate/expected!",
theme="soft",
examples=[
"What is Pagani and what are they known for?",
"Make a small Neural Network using PyTorch.",
"What is the capital of Canada?",
],
type="messages"
)
iface.launch()
|