Dawoodthouseef commited on
Commit
331005b
1 Parent(s): 37e184c

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +11 -14
app.py CHANGED
@@ -12,16 +12,14 @@ from huggingface_hub import hf_hub_download
12
 
13
  # Set gpu_layers to the number of layers to offload to GPU. Set to 0 if no GPU acceleration is available on your system.
14
  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)
15
- """ins = '''[INST] <<SYS>>
16
  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.
17
  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.
18
  <</SYS>>
19
  {} [/INST]
20
  '''
21
- """
22
- ins=""" System:Your Helpful Assistant
23
- {User}:{question}
24
- {bot_name}:"""
25
  theme = gr.themes.Monochrome(
26
  primary_hue="indigo",
27
  secondary_hue="blue",
@@ -29,8 +27,8 @@ theme = gr.themes.Monochrome(
29
  radius_size=gr.themes.sizes.radius_sm,
30
  font=[gr.themes.GoogleFont("Open Sans"), "ui-sans-serif", "system-ui", "sans-serif"],
31
  )
32
- def response(user_name,bot_name,question):
33
- res = model(ins.format(user_name=user_name,bot_name=bot_name,question=question))
34
  yield res
35
 
36
 
@@ -41,8 +39,8 @@ examples = [
41
  "I'm selling my Nikon D-750, write a short blurb for my ad."
42
  ]
43
 
44
- def process_example(**args):
45
- for x in response(**args):
46
  pass
47
  return x
48
 
@@ -110,8 +108,7 @@ with gr.Blocks(theme=seafoam, analytics_enabled=False, css=css) as demo:
110
  )
111
 
112
  with gr.Row():
113
- user_name = gr.Textbox(placeholder="Enter your Name", label="User Name", elem_id="user-input")
114
- bot_name = gr.Textbox(placeholder="Enter your question here", label="Question", elem_id="q-input")
115
  with gr.Column(scale=3):
116
  instruction = gr.Textbox(placeholder="Enter your question here", label="Question", elem_id="q-input")
117
 
@@ -121,7 +118,7 @@ with gr.Blocks(theme=seafoam, analytics_enabled=False, css=css) as demo:
121
  submit = gr.Button("Generate", variant="primary")
122
  gr.Examples(
123
  examples=examples,
124
- inputs=[user_name,bot_name,instruction],
125
  cache_examples=True,
126
  fn=process_example,
127
  outputs=[output],
@@ -129,7 +126,7 @@ with gr.Blocks(theme=seafoam, analytics_enabled=False, css=css) as demo:
129
 
130
 
131
 
132
- submit.click(response, inputs=[use_name,bot_name,instruction], outputs=[output])
133
- instruction.submit(response, inputs=[use_name,bot_name,instruction], outputs=[output])
134
 
135
  demo.queue(concurrency_count=1).launch(debug=False)
 
12
 
13
  # Set gpu_layers to the number of layers to offload to GPU. Set to 0 if no GPU acceleration is available on your system.
14
  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)
15
+ ins = '''[INST] <<SYS>>
16
  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.
17
  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.
18
  <</SYS>>
19
  {} [/INST]
20
  '''
21
+
22
+
 
 
23
  theme = gr.themes.Monochrome(
24
  primary_hue="indigo",
25
  secondary_hue="blue",
 
27
  radius_size=gr.themes.sizes.radius_sm,
28
  font=[gr.themes.GoogleFont("Open Sans"), "ui-sans-serif", "system-ui", "sans-serif"],
29
  )
30
+ def response(question):
31
+ res = model(ins.format(question))
32
  yield res
33
 
34
 
 
39
  "I'm selling my Nikon D-750, write a short blurb for my ad."
40
  ]
41
 
42
+ def process_example(args):
43
+ for x in response(args):
44
  pass
45
  return x
46
 
 
108
  )
109
 
110
  with gr.Row():
111
+
 
112
  with gr.Column(scale=3):
113
  instruction = gr.Textbox(placeholder="Enter your question here", label="Question", elem_id="q-input")
114
 
 
118
  submit = gr.Button("Generate", variant="primary")
119
  gr.Examples(
120
  examples=examples,
121
+ inputs=[instruction],
122
  cache_examples=True,
123
  fn=process_example,
124
  outputs=[output],
 
126
 
127
 
128
 
129
+ submit.click(response, inputs=[instruction], outputs=[output])
130
+ instruction.submit(response, inputs=[instruction], outputs=[output])
131
 
132
  demo.queue(concurrency_count=1).launch(debug=False)