nagasaich123 commited on
Commit
08f4c14
·
verified ·
1 Parent(s): b78672c

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +18 -37
app.py CHANGED
@@ -1,49 +1,30 @@
1
- import os
2
- import streamlit as st
3
- from llama_cpp import Llama
4
  from huggingface_hub import hf_hub_download
 
 
5
 
6
- # Hugging Face repo and model info
7
  REPO_ID = "MaziyarPanahi/BioMistral-7B-GGUF"
8
- MODEL_FILENAME = "BioMistral-7B.Q4_K_M.gguf"
9
 
10
- # Streamlit UI
11
  st.set_page_config(page_title="Medical Chatbot")
12
  st.title("🩺 Medical Chatbot using BioMistral-7B")
13
 
14
- # Download model via huggingface_hub
15
- with st.spinner("🔄 Checking/downloading model (this may take a few minutes)..."):
16
- try:
17
- model_path = hf_hub_download(
18
- repo_id=REPO_ID,
19
- filename=MODEL_FILENAME,
20
- cache_dir="models" # Optional: use your preferred directory
21
- )
22
- except Exception as e:
23
- st.error(f"❌ Failed to download model: {e}")
24
- st.stop()
25
 
26
  # Load model
27
  with st.spinner("⚙️ Loading BioMistral model..."):
28
- try:
29
- llm = Llama(
30
- model_path=model_path,
31
- n_ctx=4096,
32
- n_threads=8,
33
- n_gpu_layers=35 # Set to 0 for CPU
34
- )
35
- except Exception as e:
36
- st.error(f"❌ Failed to load model: {e}")
37
- st.stop()
38
 
39
- # Chat UI
40
- query = st.text_input("💬 Ask a medical question:")
41
  if query:
42
- with st.spinner("🧠 Generating answer..."):
43
- try:
44
- response = llm(query, max_tokens=512, stop=["</s>"])
45
- answer = response["choices"][0]["text"].strip()
46
- st.markdown("**🩺 Answer:**")
47
- st.write(answer)
48
- except Exception as e:
49
- st.error(f"⚠️ Error generating response: {e}")
 
 
 
 
1
  from huggingface_hub import hf_hub_download
2
+ from llama_cpp import Llama
3
+ import streamlit as st
4
 
5
+ # Model info
6
  REPO_ID = "MaziyarPanahi/BioMistral-7B-GGUF"
7
+ FILENAME = "BioMistral-7B.Q4_K_M.gguf"
8
 
 
9
  st.set_page_config(page_title="Medical Chatbot")
10
  st.title("🩺 Medical Chatbot using BioMistral-7B")
11
 
12
+ with st.spinner("📦 Downloading model (first-time only)..."):
13
+ model_path = hf_hub_download(repo_id=REPO_ID, filename=FILENAME)
 
 
 
 
 
 
 
 
 
14
 
15
  # Load model
16
  with st.spinner("⚙️ Loading BioMistral model..."):
17
+ llm = Llama(
18
+ model_path=model_path,
19
+ n_ctx=4096,
20
+ n_threads=8,
21
+ n_gpu_layers=35 # Adjust to 0 if CPU-only
22
+ )
 
 
 
 
23
 
24
+ # UI
25
+ query = st.text_input("💬 Enter your medical question:")
26
  if query:
27
+ with st.spinner("🧠 Thinking..."):
28
+ response = llm(query, max_tokens=512, stop=["</s>"])
29
+ st.markdown("**Answer:**")
30
+ st.write(response["choices"][0]["text"].strip())