keivalya commited on
Commit
c341c03
·
1 Parent(s): 61df5be

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +41 -1
app.py CHANGED
@@ -1,3 +1,43 @@
 
 
1
  import gradio as gr
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
2
 
3
- gr.load("models/keivalya/SahaAI").launch()
 
1
+ %pip install accelerate
2
+
3
  import gradio as gr
4
+ from transformers import AutoModelForCausalLM, AutoTokenizer
5
+ import torch
6
+ import accelerate
7
+
8
+ model_path = "01-ai/Yi-6B-200K"
9
+ model = AutoModelForCausalLM.from_pretrained(model_path, device_map="cuda", torch_dtype="auto")
10
+ tokenizer = AutoTokenizer.from_pretrained(model_path)
11
+
12
+ def respond_to_input(user_input):
13
+ prompt = f"""
14
+ You are sahaAI, an empathetic chatbot, which consoles the User, and makes his/her mood positive, joyful and enjoyable.
15
+ <SahaAI>: Hello! I'm here to help you with any psychological concerns or questions you may have. Feel free to share your thoughts and feelings with me, and I'll do my best to provide support and guidance.
16
+ <User>: {user_input}
17
+ <SahaAI>:
18
+ """
19
+ inputs = tokenizer(prompt, return_tensors="pt")
20
+ max_length = 256
21
+ outputs = model.generate(
22
+ inputs.input_ids.cuda(),
23
+ max_length=max_length,
24
+ eos_token_id=tokenizer.eos_token_id,
25
+ do_sample=True,
26
+ repetition_penalty=1.3,
27
+ no_repeat_ngram_size=5,
28
+ temperature=0.5,
29
+ top_k=40,
30
+ top_p=0.8,
31
+ )
32
+ return tokenizer.decode(outputs[0], skip_special_tokens=True)
33
+
34
+ interface = gr.Interface(
35
+ fn=respond_to_input,
36
+ inputs=gr.inputs.Textbox(lines=5, placeholder="Type your message here..."), # Multiline text input
37
+ outputs="text", # Text output
38
+ title="SahaAI", # Title of the web interface
39
+ description="Online psychology assistant, to help your mental health.", # Description of the web interface
40
+ theme="dark" # Dark theme to match your screenshot
41
+ )
42
 
43
+ interface.launch()