File size: 784 Bytes
448071f
 
 
 
b64aad2
448071f
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
9558f7b
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
import gradio as gr
from transformers import AutoModelForCausalLM, AutoTokenizer, pipeline
import torch

model_id = "mistralai/Mistral-7B-v0.1" 

tokenizer = AutoTokenizer.from_pretrained(model_id)
model = AutoModelForCausalLM.from_pretrained(
    model_id,
    device_map="auto",
    torch_dtype=torch.float16,
    load_in_4bit=True
)

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

def chat(prompt, history=[]):
    full_prompt = prompt
    output = pipe(full_prompt, max_new_tokens=200, do_sample=True, temperature=0.7)
    return output[0]["generated_text"]

gr.ChatInterface(
    fn=chat,
    title="🧠 Mistral 7B Instruct Chatbot",
    description="This chatbot is powered by the open-source Mistral 7B LLM. Ask anything!",
    theme="soft"
).launch()