File size: 785 Bytes
d170fb3
75254e1
55c4154
d170fb3
d5d2fa8
d170fb3
fe5503a
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
import gradio as gr

from transformers import AutoTokenizer, AutoModelForCausalLM, pipeline

model_id = "tiiuae/falcon-rw-1b"

tokenizer = AutoTokenizer.from_pretrained(model_id)
model = AutoModelForCausalLM.from_pretrained(model_id, device_map="auto")

pipe = pipeline("text-generation", model=model, tokenizer=tokenizer)

def chat_with_expert(message, history):
    prompt = f"<s>[INST] You are an expert assistant. Answer with clarity and depth.\n{message} [/INST]"
    response = pipe(prompt, max_new_tokens=256, do_sample=True, temperature=0.7)[0]['generated_text']
    answer = response.split('[/INST]')[-1].strip()
    history.append((message, answer))
    return history, history

chatbot = gr.ChatInterface(fn=chat_with_expert, title="Expert Chat Assistant")
chatbot.launch()