Akhil Padmanaban commited on
Commit
356e049
·
1 Parent(s): 015d885

Added the file

Browse files
Files changed (1) hide show
  1. HelpingMentalAsst.py +60 -0
HelpingMentalAsst.py ADDED
@@ -0,0 +1,60 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+
2
+ import torch
3
+ from transformers import AutoModelForCausalLM, AutoTokenizer
4
+ import gradio as gr
5
+
6
+ # Load the HelpingAI2.5-10B model
7
+ model_name = "HelpingAI/HelpingAI2.5-10B-1M"
8
+ model = AutoModelForCausalLM.from_pretrained(model_name)
9
+ tokenizer = AutoTokenizer.from_pretrained(model_name)
10
+
11
+ # Helper function to generate response
12
+ def generate_response(user_input):
13
+ chat = [
14
+ {"role": "system", "content": "You are HelpingAI, an emotional AI specialized in medical assistance. Understand the user's mental state through their text and respond empathetically."},
15
+ {"role": "user", "content": user_input}
16
+ ]
17
+
18
+ inputs = tokenizer.apply_chat_template(
19
+ chat,
20
+ add_generation_prompt=True,
21
+ return_tensors="pt"
22
+ ).to(model.device)
23
+
24
+ outputs = model.generate(
25
+ inputs,
26
+ max_new_tokens=256,
27
+ do_sample=True,
28
+ temperature=0.6,
29
+ top_p=0.9,
30
+ )
31
+
32
+ response = outputs[0][inputs.shape[-1]:]
33
+ return tokenizer.decode(response, skip_special_tokens=True)
34
+
35
+ # Define Gradio app
36
+ def chatbot(user_input):
37
+ try:
38
+ response = generate_response(user_input)
39
+ return response
40
+ except Exception as e:
41
+ return f"An error occurred: {str(e)}"
42
+
43
+ # Gradio interface
44
+ description = """
45
+ ### HelpingAI - Medical Assistance Chatbot
46
+
47
+ This AI is designed to provide empathetic medical assistance. It understands the user's mental state through text and provides relevant responses.
48
+ """
49
+
50
+ demo = gr.Interface(
51
+ fn=chatbot,
52
+ inputs=gr.Textbox(label="Enter your message", placeholder="Describe your medical concern or feelings..."),
53
+ outputs=gr.Textbox(label="HelpingAI Response"),
54
+ title="HelpingAI Medical Assistance",
55
+ description=description,
56
+ theme="compact",
57
+ )
58
+
59
+ if __name__ == "__main__":
60
+ demo.launch()