Spaces:
Paused
Paused
Upload 5 files
Browse files- README.md +17 -6
- app.py +78 -0
- requirements.txt +6 -0
README.md
CHANGED
|
@@ -1,12 +1,23 @@
|
|
| 1 |
---
|
| 2 |
-
title:
|
| 3 |
-
emoji:
|
| 4 |
-
colorFrom:
|
| 5 |
colorTo: indigo
|
| 6 |
-
sdk:
|
|
|
|
| 7 |
pinned: false
|
| 8 |
license: apache-2.0
|
| 9 |
-
short_description:
|
| 10 |
---
|
| 11 |
|
| 12 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
---
|
| 2 |
+
title: Blue Scrub 150M
|
| 3 |
+
emoji: 🩺
|
| 4 |
+
colorFrom: blue
|
| 5 |
colorTo: indigo
|
| 6 |
+
sdk: streamlit
|
| 7 |
+
app_file: app.py
|
| 8 |
pinned: false
|
| 9 |
license: apache-2.0
|
| 10 |
+
short_description: CPU inference demo for mps/blue-scrub-150M
|
| 11 |
---
|
| 12 |
|
| 13 |
+
# Blue Scrub 150M Inference
|
| 14 |
+
|
| 15 |
+
This Space runs a simple Streamlit CPU inference UI for `mps/blue-scrub-150M`.
|
| 16 |
+
|
| 17 |
+
The model is a non-instruction-tuned/base causal language model, so prompts should be plain text continuations rather than chat-style instructions.
|
| 18 |
+
|
| 19 |
+
## Notes
|
| 20 |
+
|
| 21 |
+
- Free CPU inference can be slow.
|
| 22 |
+
- The model loads from Hugging Face Hub when the Space starts.
|
| 23 |
+
- No Docker and no Gradio are used.
|
app.py
ADDED
|
@@ -0,0 +1,78 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import torch
|
| 2 |
+
import streamlit as st
|
| 3 |
+
from transformers import AutoModelForCausalLM, AutoTokenizer
|
| 4 |
+
|
| 5 |
+
MODEL_ID = "mps/blue-scrub-150M"
|
| 6 |
+
|
| 7 |
+
|
| 8 |
+
st.set_page_config(
|
| 9 |
+
page_title="Blue Scrub 150M",
|
| 10 |
+
page_icon="🩺",
|
| 11 |
+
layout="wide",
|
| 12 |
+
)
|
| 13 |
+
|
| 14 |
+
|
| 15 |
+
@st.cache_resource(show_spinner="Loading model from Hugging Face Hub...")
|
| 16 |
+
def load_model():
|
| 17 |
+
tokenizer = AutoTokenizer.from_pretrained(MODEL_ID)
|
| 18 |
+
model = AutoModelForCausalLM.from_pretrained(
|
| 19 |
+
MODEL_ID,
|
| 20 |
+
torch_dtype=torch.float32,
|
| 21 |
+
low_cpu_mem_usage=True,
|
| 22 |
+
)
|
| 23 |
+
model.eval()
|
| 24 |
+
return tokenizer, model
|
| 25 |
+
|
| 26 |
+
|
| 27 |
+
def generate_text(prompt: str, max_new_tokens: int, temperature: float, top_p: float) -> str:
|
| 28 |
+
tokenizer, model = load_model()
|
| 29 |
+
inputs = tokenizer(prompt, return_tensors="pt")
|
| 30 |
+
|
| 31 |
+
do_sample = temperature > 0
|
| 32 |
+
generation_kwargs = {
|
| 33 |
+
"max_new_tokens": max_new_tokens,
|
| 34 |
+
"do_sample": do_sample,
|
| 35 |
+
"pad_token_id": tokenizer.eos_token_id,
|
| 36 |
+
"eos_token_id": tokenizer.eos_token_id,
|
| 37 |
+
}
|
| 38 |
+
if do_sample:
|
| 39 |
+
generation_kwargs.update({"temperature": temperature, "top_p": top_p})
|
| 40 |
+
|
| 41 |
+
with torch.no_grad():
|
| 42 |
+
output_ids = model.generate(**inputs, **generation_kwargs)
|
| 43 |
+
|
| 44 |
+
generated_ids = output_ids[0][inputs["input_ids"].shape[-1]:]
|
| 45 |
+
return tokenizer.decode(generated_ids, skip_special_tokens=True).strip()
|
| 46 |
+
|
| 47 |
+
|
| 48 |
+
st.title("🩺 Blue Scrub 150M Inference")
|
| 49 |
+
st.caption(f"Model: `{MODEL_ID}` · Streamlit CPU Space · non-instruction-tuned base model")
|
| 50 |
+
|
| 51 |
+
st.warning(
|
| 52 |
+
"This is a base/non-instruction-tuned model. It completes text and is not a chat assistant. "
|
| 53 |
+
"Do not use outputs as medical advice. Free CPU inference can be slow."
|
| 54 |
+
)
|
| 55 |
+
|
| 56 |
+
with st.sidebar:
|
| 57 |
+
st.header("Generation settings")
|
| 58 |
+
max_new_tokens = st.slider("Max new tokens", min_value=8, max_value=256, value=96, step=8)
|
| 59 |
+
temperature = st.slider("Temperature", min_value=0.0, max_value=2.0, value=0.7, step=0.1)
|
| 60 |
+
top_p = st.slider("Top-p", min_value=0.05, max_value=1.0, value=0.9, step=0.05)
|
| 61 |
+
st.markdown("---")
|
| 62 |
+
st.markdown("[Open model card](https://huggingface.co/mps/blue-scrub-150M)")
|
| 63 |
+
|
| 64 |
+
prompt = st.text_area(
|
| 65 |
+
"Prompt",
|
| 66 |
+
value="Medical evidence suggests that",
|
| 67 |
+
height=180,
|
| 68 |
+
help="Use continuation-style prompts because this is a base model, not an instruction model.",
|
| 69 |
+
)
|
| 70 |
+
|
| 71 |
+
if st.button("Generate", type="primary", disabled=not prompt.strip()):
|
| 72 |
+
try:
|
| 73 |
+
with st.spinner("Generating..."):
|
| 74 |
+
text = generate_text(prompt, max_new_tokens, temperature, top_p)
|
| 75 |
+
st.subheader("Generated continuation")
|
| 76 |
+
st.write(text or "No text generated.")
|
| 77 |
+
except Exception as exc:
|
| 78 |
+
st.error(f"Inference failed: {exc}")
|
requirements.txt
ADDED
|
@@ -0,0 +1,6 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
streamlit
|
| 2 |
+
transformers
|
| 3 |
+
accelerate
|
| 4 |
+
torch
|
| 5 |
+
safetensors
|
| 6 |
+
sentencepiece
|