Spaces:
Sleeping
Sleeping
import time | |
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(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'] | |
for i in range(len(response)): | |
time.sleep(0.01) | |
yield response[: i+1] | |
gradio_interface = gr.ChatInterface(my_inference_function) | |
gradio_interface.launch() | |