Jip7e commited on
Commit
5e0ecd2
·
verified ·
1 Parent(s): 00d3ff9

Update src/streamlit_app.py

Browse files
Files changed (1) hide show
  1. 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"Explain simply for a medical student: {question}"
 
 
43
 
44
- inputs = tokenizer(prompt, return_tensors="pt").to(model.device)
 
45
 
46
- with torch.no_grad():
47
- output = model.generate(
48
- **inputs,
49
- max_new_tokens=120,
50
- temperature=0.7,
51
- top_p=0.9
52
- )
 
 
 
 
 
 
 
 
 
53
 
54
- answer = tokenizer.decode(output[0], skip_special_tokens=True)
 
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)