Mistral-7B-V2 / app.py
Dawoodthouseef's picture
Update app.py
42d6cf3
import gradio as gr
from ctransformers 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 = []
css = ".generating {visibility: hidden}"
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
with gr.Blocks( analytics_enabled=False, css=css) as demo:
with gr.Column():
gr.Markdown(
""" ## Mistral-7b
Type in the box below and click the button to generate answers to your most pressing questions!
"""
)
with gr.Row():
with gr.Column(scale=3):
instruction = gr.Textbox(placeholder="Type Your message here...", label="Question", elem_id="q-input")
with gr.Box():
gr.Markdown("**Answer**")
output = gr.Markdown(elem_id="q-output")
submit = gr.Button("Generate", variant="primary")
submit.click(generate_response, inputs=[instruction], outputs=[output])
instruction.submit(generate_response, inputs=[instruction], outputs=[output])
demo.queue(concurrency_count=1).launch(debug=False,share=True)