Spaces:
Runtime error
Runtime error
File size: 2,295 Bytes
d24249f 0710652 d24249f 813a71e d24249f 9b7861b 813a71e 659332b 813a71e 659332b 813a71e 42d6cf3 659332b 813a71e |
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 43 44 45 46 47 48 49 50 51 52 |
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) |