Spaces:
Sleeping
Sleeping
File size: 2,885 Bytes
84a2f6a 300cc8d 9adba36 8851723 b9f5d20 2579b4d 300cc8d 7b971c7 300cc8d 2579b4d 300cc8d b9f5d20 300cc8d 9adba36 407888c 41db9bf 2c68df4 41db9bf 84a2f6a 92789c4 41db9bf 7391bd6 |
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 |
from openai import OpenAI
from huggingface_hub import hf_hub_download
from llama_cpp import Llama
import gradio as gr
import os
os.makedirs("content", exist_ok=True) # Создание директории для сохранения модели
model_name = "aaditya/OpenBioLLM-Llama3-8B-GGUF"
model_file = "openbiollm-llama3-8b.Q5_K_M.gguf"
model_path = hf_hub_download(model_name,
filename=model_file,
local_dir='./content')
print("My model path: ", model_path)
llm = Llama(model_path=model_path,
n_gpu_layers=-1)
def my_inference_function(Question):
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:"
response = llm(prompt, max_tokens=4000)['choices'][0]['text']
return response
#gradio_interface = gr.Interface(
# fn = my_inference_function,
# inputs = "text",
# outputs = "text"
#)
#gradio_interface.launch()
def predict(message, history):
history_openai_format = []
for human, assistant in history:
history_openai_format.append({"role": "user", "content": human })
history_openai_format.append({"role": "assistant", "content":assistant})
history_openai_format.append({"role": "user", "content": message})
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:"
response = llm(prompt, max_tokens=4000)['choices'][0]['text']
partial_message = ""
for chunk in response:
if chunk.choices[0].delta.content is not None:
partial_message = partial_message + chunk.choices[0].delta.content
yield partial_message
# return gpt_response
gr.ChatInterface(predict).launch()
|