Spaces:
Build error
Build error
Upload 4 files
Browse files- Dockerfile +26 -0
- README.md +17 -11
- app.py +32 -0
- requirements.txt +2 -0
Dockerfile
ADDED
|
@@ -0,0 +1,26 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
FROM python:3.10-slim
|
| 2 |
+
|
| 3 |
+
# System dependencies
|
| 4 |
+
RUN apt-get update && \
|
| 5 |
+
apt-get install -y build-essential git wget curl && \
|
| 6 |
+
rm -rf /var/lib/apt/lists/*
|
| 7 |
+
|
| 8 |
+
# Create app directory
|
| 9 |
+
WORKDIR /app
|
| 10 |
+
|
| 11 |
+
# Copy files
|
| 12 |
+
COPY requirements.txt .
|
| 13 |
+
RUN pip install --upgrade pip
|
| 14 |
+
RUN pip install -r requirements.txt
|
| 15 |
+
|
| 16 |
+
COPY app.py .
|
| 17 |
+
|
| 18 |
+
# Expose Streamlit port
|
| 19 |
+
EXPOSE 7860
|
| 20 |
+
|
| 21 |
+
# Streamlit settings
|
| 22 |
+
ENV STREAMLIT_SERVER_PORT=7860
|
| 23 |
+
ENV STREAMLIT_SERVER_ADDRESS=0.0.0.0
|
| 24 |
+
ENV STREAMLIT_BROWSER_GATHER_USAGE_STATS=false
|
| 25 |
+
|
| 26 |
+
CMD ["streamlit", "run", "app.py"]
|
README.md
CHANGED
|
@@ -1,11 +1,17 @@
|
|
| 1 |
-
-
|
| 2 |
-
|
| 3 |
-
|
| 4 |
-
|
| 5 |
-
|
| 6 |
-
|
| 7 |
-
|
| 8 |
-
|
| 9 |
-
-
|
| 10 |
-
|
| 11 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# 🩺 Medical Chatbot - BioMistral
|
| 2 |
+
|
| 3 |
+
This is a doctor-style medical chatbot running on [BioMistral-7B GGUF](https://huggingface.co/TheBloke/BioMistral-7B-GGUF) using `llama-cpp-python`.
|
| 4 |
+
|
| 5 |
+
## 💡 Features
|
| 6 |
+
|
| 7 |
+
- Runs locally in your browser using Streamlit
|
| 8 |
+
- Doesn't require OpenAI or API keys
|
| 9 |
+
- Runs fully offline once model is downloaded
|
| 10 |
+
|
| 11 |
+
## 🧠 Model: BioMistral-7B.Q4_K_M.gguf
|
| 12 |
+
|
| 13 |
+
Deployed using [llama.cpp](https://github.com/ggerganov/llama.cpp) backend.
|
| 14 |
+
|
| 15 |
+
## 🚀 Usage
|
| 16 |
+
|
| 17 |
+
- Click `App` tab to start chatting with the doctor.
|
app.py
ADDED
|
@@ -0,0 +1,32 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import streamlit as st
|
| 2 |
+
from llama_cpp import Llama
|
| 3 |
+
|
| 4 |
+
st.set_page_config(page_title="🩺 Medical Chatbot", layout="centered")
|
| 5 |
+
st.title("🩺 Medical Chatbot (Doctor Mistral)")
|
| 6 |
+
|
| 7 |
+
@st.cache_resource
|
| 8 |
+
def load_model():
|
| 9 |
+
return Llama(
|
| 10 |
+
model_path="./models/BioMistral-7B.Q4_K_M.gguf", # <- Update to your actual path
|
| 11 |
+
n_ctx=2048,
|
| 12 |
+
n_threads=8,
|
| 13 |
+
n_gpu_layers=0 # Use GPU if available
|
| 14 |
+
)
|
| 15 |
+
|
| 16 |
+
llm = load_model()
|
| 17 |
+
|
| 18 |
+
if "chat_history" not in st.session_state:
|
| 19 |
+
st.session_state.chat_history = []
|
| 20 |
+
|
| 21 |
+
prompt = st.text_input("Ask me a medical question:")
|
| 22 |
+
|
| 23 |
+
if st.button("Send") and prompt:
|
| 24 |
+
st.session_state.chat_history.append(("You", prompt))
|
| 25 |
+
full_prompt = f"You are a helpful medical assistant.\n\nUser: {prompt}\nDoctor:"
|
| 26 |
+
output = llm(full_prompt, max_tokens=512, stop=["User:", "Doctor:"])
|
| 27 |
+
reply = output["choices"][0]["text"].strip()
|
| 28 |
+
st.session_state.chat_history.append(("Doctor", reply))
|
| 29 |
+
|
| 30 |
+
# Show chat history
|
| 31 |
+
for role, message in st.session_state.chat_history:
|
| 32 |
+
st.markdown(f"**{role}:** {message}")
|
requirements.txt
ADDED
|
@@ -0,0 +1,2 @@
|
|
|
|
|
|
|
|
|
|
| 1 |
+
streamlit>=1.30.0
|
| 2 |
+
llama-cpp-python==0.2.72
|