Spaces:
Build error
Build error
Update app.py
Browse files12345678910111213141516171819202122232426 unmodified lines51525354555657585960616263646566import spacesimport torchimport gradio as grfrom transformers import pipeline, AutoModel, AutoTokenizerfrom llama_cpp import Llamaimport osMODEL_NAME = "openai/whisper-large-v3-turbo"MODEL_PATH = "model.gguf" # Path to the downloaded modelBATCH_SIZE = 8FILE_LIMIT_MB = 1000device = 0 if torch.cuda.is_available() else "cpu"# Download and load model if not already presentif not os.path.exists(MODEL_PATH):from huggingface_hub import hf_hub_downloadhf_hub_download(repo_id="MaziyarPanahi/Qwen2-7B-Instruct-GGUF", filename="model.gguf", local_dir="./")# Load the Llama model with specified context and threadingllm = Llama(model_path=MODEL_PATH, n_ctx=8000, n_threads=2, chat_format="chatml")# Initialize the transcription pipelinepipe = pipeline(26 unmodified lines# 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 inputsdemo = gr.Blocks(theme=gr.themes.Ocean())123456789101112131415161718192026 unmodified lines474849505152535455565758596061import spacesimport torchimport gradio as grfrom transformers import pipelinefrom llama_cpp import LlamaMODEL_NAME = "openai/whisper-large-v3-turbo"BATCH_SIZE = 8FILE_LIMIT_MB = 1000device = 0 if torch.cuda.is_available() else "cpu"# Load the Llama model directly from Hugging Facellm = Llama.from_pretrained(repo_id="MaziyarPanahi/Qwen2-7B-Instruct-GGUF",filename="Qwen2-7B-Instruct.Q4_K_M.gguf")# Initialize the transcription pipelinepipe = pipeline(26 unmodified lines# Function to generate SOAP notes using Llama modeldef generate_soap(transcribed_text):# Format the conversation for the Llama modelprompt = [{"role": "system", "content": sys_prompt},{"role": "user", "content": f"{task_prompt}\n{transcribed_text}"}]# Generate a responseresponse = llm.create_chat_completion(messages=prompt, temperature=0.7, max_tokens=2048)return response["choices"][0]["message"]["content"]# Gradio Interfaces for different inputsdemo = gr.Blocks(theme=gr.themes.Ocean())
app.py+14-19