sjdata commited on
Commit
29f2930
1 Parent(s): 067b4cd

fixed app.py

Browse files
Files changed (1) hide show
  1. app.py +16 -21
app.py CHANGED
@@ -1,8 +1,10 @@
1
  import gradio as gr
2
  from huggingface_hub import hf_hub_download
3
- from llama_cpp import Llama
4
 
5
  hf_hub_download(repo_id="LLukas22/gpt4all-lora-quantized-ggjt", filename="ggjt-model.bin", local_dir=".")
 
 
 
6
  llm = Llama(model_path="./ggjt-model.bin")
7
 
8
  ins = '''### Instruction:
@@ -10,31 +12,24 @@ ins = '''### Instruction:
10
  ### Response:
11
  '''
12
 
13
- theme = gr.themes.Monochrome(
14
- primary_hue="indigo",
15
- secondary_hue="blue",
16
- neutral_hue="slate",
17
- radius_size=gr.themes.sizes.radius_sm,
18
- font=[gr.themes.GoogleFont("Open Sans"), "ui-sans-serif", "system-ui", "sans-serif"],
19
- )
20
-
21
- def generate(instruction):
22
- result = ""
23
- for x in llm(ins.format(instruction), stop=['### Instruction:', '### End'], stream=True):
24
- result += x['choices'][0]['text']
25
- yield result
26
 
 
 
 
 
 
 
 
27
  gr.ChatInterface(
28
- fn=generate,
29
  chatbot=gr.Chatbot(height=300),
30
  textbox=gr.Textbox(placeholder="Ask me a question"),
31
  title="Healthcare Bot",
32
  description="Ask the Healthcare Bot any question",
33
  examples = [
34
- "Give me treatments for heart disease",
35
- "I hate exercise, what else can I do to treat my high blood pressure",
36
- "How can I avoid lung disease",
37
- ],
38
- theme=theme,
39
  ).launch()
40
-
 
1
  import gradio as gr
2
  from huggingface_hub import hf_hub_download
 
3
 
4
  hf_hub_download(repo_id="LLukas22/gpt4all-lora-quantized-ggjt", filename="ggjt-model.bin", local_dir=".")
5
+
6
+ from llama_cpp import Llama
7
+
8
  llm = Llama(model_path="./ggjt-model.bin")
9
 
10
  ins = '''### Instruction:
 
12
  ### Response:
13
  '''
14
 
15
+ fixed_instruction = "You are a healthcare bot designed to give advice for the prevention and treatment of various illnesses."
 
 
 
 
 
 
 
 
 
 
 
 
16
 
17
+ def respond(message, chat_history):
18
+ full_instruction = fixed_instruction + " " + message
19
+ formatted_instruction = ins.format(full_instruction)
20
+ bot_message = llm(formatted_instruction, stop=['### Instruction:', '### End'])
21
+ bot_message = bot_message['choices'][0]['text']
22
+ return bot_message
23
+
24
  gr.ChatInterface(
25
+ fn=respond,
26
  chatbot=gr.Chatbot(height=300),
27
  textbox=gr.Textbox(placeholder="Ask me a question"),
28
  title="Healthcare Bot",
29
  description="Ask the Healthcare Bot any question",
30
  examples = [
31
+ "Give me treatements for heart disease",
32
+ "I hate excercise, what else can I do to treat my high blood pressure",
33
+ "How can I avoid lung disease",
34
+ ],
 
35
  ).launch()