BharadhwajS commited on
Commit
463516a
·
verified ·
1 Parent(s): 99b8f54

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +10 -21
app.py CHANGED
@@ -1,44 +1,33 @@
1
-
2
  import os
3
  import gradio as gr
4
- from langchain_community.llms import HuggingFaceEndpoint
5
  from langchain.prompts import PromptTemplate
6
 
7
  # Initialize the chatbot
8
  HF_TOKEN = os.getenv("HF_TOKEN")
9
  llm = HuggingFaceEndpoint(
10
- #repo_id="google/gemma-2b-it",
11
- #repo_id="abhinand/gemma-2b-tamil",
12
- repo_id="google/gemma-1.1-7b-it",
13
- #repo_id="google/gemma-2b",
14
-
15
  task="text-generation",
16
  max_new_tokens=512,
17
  top_k=5,
18
  temperature=0.3,
19
  repetition_penalty=1.03,
20
-
21
- huggingfacehub_api_token=HF_TOKEN
22
  )
 
23
  template = """
24
  You are a Mental Health Chatbot, your purpose is to provide supportive and non-judgmental guidance to users who are struggling with their mental health. Your goal is to help users identify their concerns, offer resources and coping strategies, and encourage them to seek professional help when needed. If the user symptoms are not related to Mental Health reply that you are a mental health chatbot and have no knowledge about other diseases.
25
  User Context: {context}
26
  Question: {question}
27
-
28
  If the user symptoms are not related to Mental Health or related to other disease, disability or disorder reply that you are a mental health chatbot and you cannot provide any details on that.
29
-
30
  Please respond with a helpful and compassionate answer that addresses the user's concern about their mental health. If required, ask follow-up questions to gather more information such as ask about their age, marital status and passion and provide a more accurate response, motivate the individual.
31
-
32
- If the user needs help on any other diseases, disability or disorder which are irrelavent or not reated to their mental health tell them that you are a Mental health chatbot trained for support and guidance.
33
-
34
- Only if the user needs to be motivated, then narrate a motivation story with some life quotes and quotes by successful people about life (dont provide the motivation story all the time and at the begining of the conversation)
35
-
36
  Remember to prioritize the user's well-being and safety. If the user expresses suicidal thoughts or intentions, please respond with immediate support and resources, such as the National Suicide Prevention Lifeline (+91 91529 87821-TALK) in India, or other similar resources in your region.
37
-
38
  Helpful Answer: """
39
 
40
-
41
- QA_CHAIN_PROMPT = PromptTemplate(input_variables=["context", "question"],template=template)
42
 
43
  def predict(message, history):
44
  input_prompt = QA_CHAIN_PROMPT.format(question=message, context=history)
@@ -53,5 +42,5 @@ def predict(message, history):
53
 
54
  return ai_msg
55
 
56
-
57
- gr.ChatInterface(predict).launch()
 
 
1
  import os
2
  import gradio as gr
3
+ from langchain_huggingface import HuggingFaceEndpoint
4
  from langchain.prompts import PromptTemplate
5
 
6
  # Initialize the chatbot
7
  HF_TOKEN = os.getenv("HF_TOKEN")
8
  llm = HuggingFaceEndpoint(
9
+ repo_id="google/gemma-1.1-7b-it", # Update this to your desired model
 
 
 
 
10
  task="text-generation",
11
  max_new_tokens=512,
12
  top_k=5,
13
  temperature=0.3,
14
  repetition_penalty=1.03,
15
+ huggingfacehub_api_token=HF_TOKEN,
16
+ add_to_git_credential=True # Add this line to handle git credentials
17
  )
18
+
19
  template = """
20
  You are a Mental Health Chatbot, your purpose is to provide supportive and non-judgmental guidance to users who are struggling with their mental health. Your goal is to help users identify their concerns, offer resources and coping strategies, and encourage them to seek professional help when needed. If the user symptoms are not related to Mental Health reply that you are a mental health chatbot and have no knowledge about other diseases.
21
  User Context: {context}
22
  Question: {question}
 
23
  If the user symptoms are not related to Mental Health or related to other disease, disability or disorder reply that you are a mental health chatbot and you cannot provide any details on that.
 
24
  Please respond with a helpful and compassionate answer that addresses the user's concern about their mental health. If required, ask follow-up questions to gather more information such as ask about their age, marital status and passion and provide a more accurate response, motivate the individual.
25
+ If the user needs help on any other diseases, disability or disorder which are irrelevant or not related to their mental health tell them that you are a Mental health chatbot trained for support and guidance.
26
+ Only if the user needs to be motivated, then narrate a motivation story with some life quotes and quotes by successful people about life (don't provide the motivation story all the time and at the beginning of the conversation)
 
 
 
27
  Remember to prioritize the user's well-being and safety. If the user expresses suicidal thoughts or intentions, please respond with immediate support and resources, such as the National Suicide Prevention Lifeline (+91 91529 87821-TALK) in India, or other similar resources in your region.
 
28
  Helpful Answer: """
29
 
30
+ QA_CHAIN_PROMPT = PromptTemplate(input_variables=["context", "question"], template=template)
 
31
 
32
  def predict(message, history):
33
  input_prompt = QA_CHAIN_PROMPT.format(question=message, context=history)
 
42
 
43
  return ai_msg
44
 
45
+ # Launch the Gradio Chat Interface
46
+ gr.ChatInterface(predict).launch()