File size: 1,157 Bytes
8040f5f
c2b5d4b
 
8040f5f
c2b5d4b
8040f5f
c2b5d4b
 
 
 
 
8040f5f
c2b5d4b
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
import gradio as gr
from transformers import AutoTokenizer, AutoModelForCausalLM
import torch

model_name = "lamapi/next-1b"

tokenizer = AutoTokenizer.from_pretrained(model_name)
model = AutoModelForCausalLM.from_pretrained(
    model_name,
    torch_dtype=torch.float16,
    device_map="auto"
)
model.eval()

def chat(message, history):
    history = history or []
    prompt = "".join([f"User: {u}\nBot: {b}\n" for u,b in history])
    prompt += f"User: {message}\nBot:"
    inputs = tokenizer(prompt, return_tensors="pt").to(model.device)

    with torch.inference_mode():
        outputs = model.generate(
            **inputs,
            max_new_tokens=150,
            do_sample=True,
            temperature=0.8,
            top_p=0.9
        )

    text = tokenizer.decode(outputs[0], skip_special_tokens=True)
    reply = text.split("Bot:")[-1].strip()
    history.append((message, reply))
    return reply, history

iface = gr.ChatInterface(
    fn=chat,
    title="Next-1B Chatbot ⚡",
    description="Lamapi model ile hızlı, kuyruksuz chat!",
).launch(share=True, server_name="0.0.0.0", server_port=7860, concurrency_count=4, queue=False)