File size: 1,042 Bytes
3cfc12b
22f1de6
 
3cfc12b
 
22f1de6
3cfc12b
22f1de6
 
3cfc12b
 
22f1de6
 
3cfc12b
 
22f1de6
 
 
 
 
 
 
 
 
 
 
 
3cfc12b
22f1de6
 
 
 
 
3cfc12b
22f1de6
 
 
 
 
3cfc12b
22f1de6
 
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
import os
import torch
from transformers import AutoModelForCausalLM, AutoTokenizer, pipeline
import gradio as gr

model_id = "mistralai/Mistral-7B-Instruct-v0.3"

# Load tokenizer and model with correct settings
tokenizer = AutoTokenizer.from_pretrained(model_id, use_fast=False)  # Important fix
model = AutoModelForCausalLM.from_pretrained(
    model_id,
    torch_dtype=torch.float16,
    device_map="auto"
)

# Create generation pipeline
pipe = pipeline(
    "text-generation",
    model=model,
    tokenizer=tokenizer,
    max_new_tokens=512,
    do_sample=True,
    top_k=50,
    top_p=0.95,
    temperature=0.7,
    repetition_penalty=1.1
)

# Define Gradio UI
def chat_fn(message, history):
    prompt = f"[INST] {message.strip()} [/INST]"
    output = pipe(prompt)[0]['generated_text']
    return output.replace(prompt, "").strip()

chatbot = gr.ChatInterface(
    fn=chat_fn,
    title="πŸ€– Vynix AI - Powered by Mistral",
    description="Ask anything! Built using Mistral-7B-Instruct-v0.3.",
)

# Launch the app
chatbot.launch()