Dawoodthouseef commited on
Commit
d24249f
·
1 Parent(s): 20bd8da

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +38 -0
app.py CHANGED
@@ -0,0 +1,38 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import gradio as gr
2
+ from transformers import AutoModelForCausalLM, AutoTokenizer
3
+ import torch
4
+
5
+ # Load the model
6
+ 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)
7
+ ins = '''[INST] <<SYS>>
8
+ 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.
9
+ 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.
10
+ <</SYS>>
11
+ {} [/INST]
12
+ '''
13
+
14
+
15
+ # Define the conversation history
16
+ conversation_history = []
17
+
18
+ # Create a Gradio interface
19
+ gr.Interface(
20
+ fn=None,
21
+ inputs=gr.Textbox(placeholder="Type a message..."),
22
+ outputs=gr.Textbox(""),
23
+ live=True,
24
+ layout="vertical",
25
+ title="MISTGPT",
26
+ theme="huggingface",
27
+ ).launch()
28
+
29
+
30
+ def generate_response(input_text):
31
+ global conversation_history
32
+ # Append the user's input to the conversation history
33
+ conversation_history.append({"role": "system", "content": input_text})
34
+ response_text = model(conversation_history)
35
+ conversation_history.append({"role": "user", "content": input_text})
36
+ conversation_history.append({"role": "assistant", "content": response_text})
37
+
38
+ return response_text