Spaces:
Build error
Build error
Update app.py
Browse files
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 |
-
#
|
| 7 |
REPO_ID = "MaziyarPanahi/BioMistral-7B-GGUF"
|
| 8 |
-
|
| 9 |
|
| 10 |
-
# Streamlit UI
|
| 11 |
st.set_page_config(page_title="Medical Chatbot")
|
| 12 |
st.title("🩺 Medical Chatbot using BioMistral-7B")
|
| 13 |
|
| 14 |
-
|
| 15 |
-
|
| 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 |
-
|
| 29 |
-
|
| 30 |
-
|
| 31 |
-
|
| 32 |
-
|
| 33 |
-
|
| 34 |
-
)
|
| 35 |
-
except Exception as e:
|
| 36 |
-
st.error(f"❌ Failed to load model: {e}")
|
| 37 |
-
st.stop()
|
| 38 |
|
| 39 |
-
#
|
| 40 |
-
query = st.text_input("💬
|
| 41 |
if query:
|
| 42 |
-
with st.spinner("🧠
|
| 43 |
-
|
| 44 |
-
|
| 45 |
-
|
| 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())
|
|
|
|
|
|
|
|
|
|
|
|