Mistral-7B-V2 / app.py
Dawoodthouseef's picture
Update app.py
d24249f
raw
history blame
1.57 kB
import gradio as gr
from transformers import AutoModelForCausalLM, AutoTokenizer
import torch
# Load the model
model = AutoModelForCausalLM.from_pretrained("TheBloke/Mistral-7B-Instruct-v0.1-GGUF", model_file="mistral-7b-instruct-v0.1.Q5_K_S.gguf", model_type="mistral", gpu_layers=0)
ins = '''[INST] <<SYS>>
You are a helpful, respectful and honest assistant. Always answer as helpfully as possible, while being safe. Your answers should not include any harmful, unethical, racist, sexist, toxic, dangerous, or illegal content. Please ensure that your responses are socially unbiased and positive in nature.
If a question does not make any sense, or is not factually coherent, explain why instead of answering something not correct. If you don't know the answer to a question, please don't share false information.
<</SYS>>
{} [/INST]
'''
# Define the conversation history
conversation_history = []
# Create a Gradio interface
gr.Interface(
fn=None,
inputs=gr.Textbox(placeholder="Type a message..."),
outputs=gr.Textbox(""),
live=True,
layout="vertical",
title="MISTGPT",
theme="huggingface",
).launch()
def generate_response(input_text):
global conversation_history
# Append the user's input to the conversation history
conversation_history.append({"role": "system", "content": input_text})
response_text = model(conversation_history)
conversation_history.append({"role": "user", "content": input_text})
conversation_history.append({"role": "assistant", "content": response_text})
return response_text