File size: 810 Bytes
b079a26
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
import gradio as gr
from transformers import pipeline
import torch
from huggingface_hub import login
import os

login(
    token = os.getenv("HF_TOKEN"),
)

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

print("\n\nDownloading model...\n\n")
pipe = pipeline("text-generation", model=model_id, torch_dtype=torch.bfloat16)
print("\n\nModel Initialized successfully!!\n\n")

def interact(message: str, history: list):
    chat_history = [msg for msg in history]
    chat_history.append({
        "role":"user",
        "content": message
    })

    response = pipe(chat_history)
    print("\n\nResponse: ",response, end="\n\n")
    return response[0]["generated_text"][-1]["content"]

interface = gr.ChatInterface(
    fn=interact,
    type="messages",
    title="Mistral Model Interface"
)

interface.launch()