Spaces:
Build error
Build error
Update app.py
Browse files1234567810 unmodified lines1920212223242526272829303132333416 unmodified lines515253545556575859606162import spacesimport torchimport gradio as grfrom transformers import AutoTokenizer, LlamaForCausalLMimport bitsandbytes, flash_attnimport osMODEL_NAME = "openai/whisper-large-v3-turbo"10 unmodified linesdevice=device,)# Load tokenizer and model for SOAP note generationtokenizer = AutoTokenizer.from_pretrained("NousResearch/Hermes-3-Llama-3.1-8B", trust_remote_code=True)model = LlamaForCausalLM.from_pretrained("NousResearch/Hermes-3-Llama-3.1-8B",torch_dtype=torch.float16,device_map="auto",load_in_8bit=False,load_in_4bit=True,use_flash_attention_2=True)# Prompt for SOAP note generationsys_prompt = "You are a world class clinical assistant."16 unmodified linestext = pipe(inputs, batch_size=BATCH_SIZE, generate_kwargs={"task": task}, return_timestamps=True)["text"]return text# Function to generate SOAP notes using LLMdef generate_soap(transcribed_text):prompt = f"<|im_start|>system\n{sys_prompt}<|im_end|>\n<|im_start|>user\n{task_prompt}\n{transcribed_text}<|im_end|>\n<|im_start|>assistant"input_ids = tokenizer(prompt, return_tensors="pt").input_ids.to("cuda")generated_ids = model.generate(input_ids, max_new_tokens=2048, temperature=0.8, repetition_penalty=1.1, do_sample=True, eos_token_id=tokenizer.eos_token_id)response = tokenizer.decode(generated_ids[0][input_ids.shape[-1]:], skip_special_tokens=True, clean_up_tokenization_space=True)return response# Gradio Interfaces for different inputs1234567810 unmodified lines192021222324252616 unmodified lines4344454647484950515253545556575859import spacesimport torchimport gradio as grfrom transformers import pipelinefrom llama_cpp import Llamaimport osMODEL_NAME = "openai/whisper-large-v3-turbo"10 unmodified linesdevice=device,)# Load the Llama model for SOAP note generationllm = Llama(model_path="model.gguf", n_ctx=8000, n_threads=2, chat_format="chatml")# Prompt for SOAP note generationsys_prompt = "You are a world class clinical assistant."16 unmodified linestext = pipe(inputs, batch_size=BATCH_SIZE, generate_kwargs={"task": task}, return_timestamps=True)["text"]return text# Function to generate SOAP notes using Llama modeldef generate_soap(transcribed_text):prompt = [{"role": "system", "content": sys_prompt}]prompt.append({"role": "user", "content": f"{task_prompt}\n{transcribed_text}"})# Generate a response using the Llama model in streaming modestream_response = llm.create_chat_completion(messages=prompt, temperature=0.7, max_tokens=2048, stream=True)response = ""for chunk in stream_response:if "content" in chunk['choices'][0]["delta"]:response += chunk['choices'][0]["delta"]["content"]return response# Gradio Interfaces for different inputs
app.py+14-17