developer3000 commited on
Commit
e1bc398
·
verified ·
1 Parent(s): e6ffaed

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +10 -8
app.py CHANGED
@@ -1,17 +1,14 @@
 
1
  from huggingface_hub import hf_hub_download
2
  from llama_cpp import Llama
3
  import gradio as gr
4
  import os
5
- #from transformers import AutoModel, AutoTokenizer
6
 
7
  os.makedirs("content", exist_ok=True) # Создание директории для сохранения модели
8
 
9
  model_name = "aaditya/OpenBioLLM-Llama3-8B-GGUF"
10
  model_file = "openbiollm-llama3-8b.Q5_K_M.gguf"
11
 
12
- #tokenizer = AutoTokenizer.from_pretrained(model_name)
13
- #model = AutoModel.from_pretrained(model_name)
14
-
15
  model_path = hf_hub_download(model_name,
16
  filename=model_file,
17
  local_dir='./content')
@@ -19,10 +16,15 @@ print("My model path: ", model_path)
19
  llm = Llama(model_path=model_path,
20
  n_gpu_layers=-1)
21
 
22
- def my_inference_function(Question):
23
- prompt = f"You are an expert and experienced from the healthcare and biomedical domain with extensive medical knowledge and practical experience. Your name is OpenBioLLM, and you were developed by Saama AI Labs with Open Life Science AI. who's willing to help answer the user's query with explanation. In your explanation, leverage your deep medical expertise such as relevant anatomical structures, physiological processes, diagnostic criteria, treatment guidelines, or other pertinent medical concepts. Use precise medical terminology while still aiming to make the explanation clear and accessible to a general audience. Medical Question: {Question} Medical Answer:"
24
- response = llm(prompt, max_tokens=4000)['choices'][0]['text']
25
- print("\n\n\n", response)
 
 
 
 
 
26
 
27
  gradio_interface = gr.ChatInterface(my_inference_function)
28
 
 
1
+ from openai import OpenAI
2
  from huggingface_hub import hf_hub_download
3
  from llama_cpp import Llama
4
  import gradio as gr
5
  import os
 
6
 
7
  os.makedirs("content", exist_ok=True) # Создание директории для сохранения модели
8
 
9
  model_name = "aaditya/OpenBioLLM-Llama3-8B-GGUF"
10
  model_file = "openbiollm-llama3-8b.Q5_K_M.gguf"
11
 
 
 
 
12
  model_path = hf_hub_download(model_name,
13
  filename=model_file,
14
  local_dir='./content')
 
16
  llm = Llama(model_path=model_path,
17
  n_gpu_layers=-1)
18
 
19
+ def my_inference_function(message, history):
20
+ history_openai_format = []
21
+ for human, assistant in history:
22
+ history_openai_format.append({"role": "user", "content": human })
23
+ history_openai_format.append({"role": "assistant", "content":assistant})
24
+ history_openai_format.append({"role": "user", "content": message})
25
+ prompt = f"You are an expert and experienced from the healthcare and biomedical domain with extensive medical knowledge and practical experience. Your name is OpenBioLLM, and you were developed by Saama AI Labs with Open Life Science AI. who's willing to help answer the user's query with explanation. In your explanation, leverage your deep medical expertise such as relevant anatomical structures, physiological processes, diagnostic criteria, treatment guidelines, or other pertinent medical concepts. Use precise medical terminology while still aiming to make the explanation clear and accessible to a general audience. Medical Question: {history_openai_format} Medical Answer:"
26
+ response = llm(prompt, max_tokens=4000)['choices'][0]['text']
27
+ print("\n\n\n", response)
28
 
29
  gradio_interface = gr.ChatInterface(my_inference_function)
30