Spaces:
Sleeping
Sleeping
Update src/streamlit_app.py
Browse files- src/streamlit_app.py +23 -10
src/streamlit_app.py
CHANGED
|
@@ -39,18 +39,31 @@ if st.button("Ask DocMed"):
|
|
| 39 |
if question.strip() == "":
|
| 40 |
st.warning("Please enter a question.")
|
| 41 |
else:
|
| 42 |
-
prompt = f"
|
|
|
|
|
|
|
| 43 |
|
| 44 |
-
|
|
|
|
| 45 |
|
| 46 |
-
|
| 47 |
-
|
| 48 |
-
|
| 49 |
-
|
| 50 |
-
|
| 51 |
-
|
| 52 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 53 |
|
| 54 |
-
|
|
|
|
| 55 |
st.markdown("### 🧠 DocMed says:")
|
| 56 |
st.write(answer)
|
|
|
|
| 39 |
if question.strip() == "":
|
| 40 |
st.warning("Please enter a question.")
|
| 41 |
else:
|
| 42 |
+
prompt = f"""You are DocMed, a medical study assistant.
|
| 43 |
+
Explain the following clearly and concisely for a medical student.
|
| 44 |
+
Give the answer directly.
|
| 45 |
|
| 46 |
+
Question:
|
| 47 |
+
{question}
|
| 48 |
|
| 49 |
+
Answer:
|
| 50 |
+
"""
|
| 51 |
+
|
| 52 |
+
inputs = tokenizer(prompt, return_tensors="pt").to(model.device)
|
| 53 |
+
|
| 54 |
+
with torch.no_grad():
|
| 55 |
+
output = model.generate(
|
| 56 |
+
**inputs,
|
| 57 |
+
max_new_tokens=120,
|
| 58 |
+
temperature=0.6,
|
| 59 |
+
top_p=0.9,
|
| 60 |
+
repetition_penalty=1.2,
|
| 61 |
+
do_sample=True
|
| 62 |
+
)
|
| 63 |
+
|
| 64 |
+
decoded = tokenizer.decode(output[0], skip_special_tokens=True)
|
| 65 |
|
| 66 |
+
# Remove prompt echo if present
|
| 67 |
+
answer = decoded.split("Answer:")[-1].strip()
|
| 68 |
st.markdown("### 🧠 DocMed says:")
|
| 69 |
st.write(answer)
|