File size: 1,927 Bytes
8185d4a
2c45d67
8185d4a
2852c83
04197a7
8185d4a
 
04197a7
8185d4a
04197a7
8185d4a
 
2c45d67
8185d4a
 
2c45d67
2d9e29d
8185d4a
 
 
04197a7
 
 
 
 
 
 
 
 
 
 
 
 
 
b38b5ee
04197a7
8185d4a
 
2c45d67
04197a7
 
 
 
f27dd35
8185d4a
 
 
e85c8ba
8185d4a
 
 
 
04197a7
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
import gradio as gr
from transformers import AutoTokenizer, AutoModelForCausalLM
import torch

# Load model and tokenizer
model_name = "Spestly/AwA-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 AwA. 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. Don't overthink answers, but don't underthink them aswell.\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=600,
            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="AwA-1.5B πŸ”Ž - Experimental",
    description="Chat with AwA (Answers with Athena). Please note that since AwA is an experimental model, some outputs may not be accurate/expected!",
    theme="ocean",
    examples=[
        "How can CRISPR help us Humans?",
        "What are some important ethics in AI",
        "What is the capital of New Zealand?",
    ],
    type="messages"
)

iface.launch()