Views
No views yet
1from transformers import AutoModelForCausalLM, AutoTokenizer
2
3# Load the model
4model = AutoModelForCausalLM.from_pretrained("JCholder/womens-health-chatbot")
5tokenizer = AutoTokenizer.from_pretrained("JCholder/womens-health-chatbot")
6
7def ask_health_question(question):
8 prompt = f"USER: {question}\nDOCTOR:"
9 inputs = tokenizer(prompt, return_tensors="pt", max_length=400, truncation=True)
10
11 outputs = model.generate(
12 **inputs,
13 max_new_tokens=120,
14 temperature=0.7,
15 top_p=0.9,
16 repetition_penalty=1.3,
17 do_sample=True,
18 pad_token_id=tokenizer.eos_token_id
19 )
20
21 full_response = tokenizer.decode(outputs[0], skip_special_tokens=True)
22 response = full_response.split("DOCTOR:")[-1].strip()
23 return response
24
25# Example usage
26question = "What causes irregular periods?"
27response = ask_health_question(question)
28print(response)1// NextJS API Route (pages/api/chat.js)
2import { pipeline } from '@huggingface/transformers';
3
4let chatbot;
5
6async function initializeChatbot() {
7 if (!chatbot) {
8 chatbot = await pipeline('text-generation', 'JCholder/womens-health-chatbot');
9 }
10 return chatbot;
11}
12
13export default async function handler(req, res) {
14 const { message } = req.body;
15 const model = await initializeChatbot();
16
17 const prompt = `USER: ${message}\nDOCTOR:`;
18 const result = await model(prompt, {
19 max_new_tokens: 100,
20 temperature: 0.7,
21 return_full_text: false
22 });
23
24 const response = result[0].generated_text.trim();
25 res.json({ response });
26}1@misc{womens-health-chatbot,
2 title={Women's Health Chatbot},
3 author={Juliana Holder},
4 year={2025},
5 url={https://huggingface.co/JCholder/womens-health-chatbot}
6}altaidevorg/women-health-mini dataset containing professional women's health Q&A pairs.