Arjun Singh commited on
Commit
300b9d3
·
1 Parent(s): 6c8d0db

adding usage counter

Browse files
Files changed (1) hide show
  1. app.py +4 -1
app.py CHANGED
@@ -5,8 +5,10 @@ from huggingface_hub.utils import HfHubHTTPError
5
  system_prompt = """
6
  You are a helpful, respectful and honest assistant. Always answer as helpfully as possible, while being safe. Your answers should not include any harmful, unethical, racist, sexist, toxic, dangerous, or illegal content. Please ensure that your responses are socially unbiased and positive in nature. If a question does not make any sense, or is not factually coherent, explain why instead of answering something not correct. If you don't know the answer to a question, please don't share false information. Your response should be complete, and not end abruptly.
7
  """
8
-
9
  def chat_with_Mixtral(prompt, hugging_face_api_key):
 
 
10
  model_name = "NousResearch/Nous-Hermes-2-Mixtral-8x7B-DPO"
11
  try:
12
  client = InferenceClient(model=model_name,token=hugging_face_api_key)
@@ -33,6 +35,7 @@ def clear_fields():
33
  with gr.Blocks(theme='freddyaboulton/test-blue') as demo:
34
  gr.Markdown("<center><h2>Arjun's Chatbot</h2></center>")
35
  gr.Markdown("Hi there! I'm an AI assistant tasked with answering one question at a time. I'm instructed to provide complete and truthful responses, without any harmful or biased content. I have some memory issues which are work in progress, so I cannot remember previous conversations, yet! In order to get a response, please provide your Hugging Face (HF) API Token along with your question. This token is unique for every HF user and can be found at [Access Tokens](https://huggingface.co/settings/tokens). Happy Chatting!")
 
36
  prompt = gr.Textbox(label='Question', lines=2, max_lines=5, placeholder = 'Type your question here.')
37
  token = gr.Textbox(label="Hugging Face API Key", type="password")
38
 
 
5
  system_prompt = """
6
  You are a helpful, respectful and honest assistant. Always answer as helpfully as possible, while being safe. Your answers should not include any harmful, unethical, racist, sexist, toxic, dangerous, or illegal content. Please ensure that your responses are socially unbiased and positive in nature. If a question does not make any sense, or is not factually coherent, explain why instead of answering something not correct. If you don't know the answer to a question, please don't share false information. Your response should be complete, and not end abruptly.
7
  """
8
+ usage_counter = 0
9
  def chat_with_Mixtral(prompt, hugging_face_api_key):
10
+ global usage_counter
11
+ usage_counter += 1
12
  model_name = "NousResearch/Nous-Hermes-2-Mixtral-8x7B-DPO"
13
  try:
14
  client = InferenceClient(model=model_name,token=hugging_face_api_key)
 
35
  with gr.Blocks(theme='freddyaboulton/test-blue') as demo:
36
  gr.Markdown("<center><h2>Arjun's Chatbot</h2></center>")
37
  gr.Markdown("Hi there! I'm an AI assistant tasked with answering one question at a time. I'm instructed to provide complete and truthful responses, without any harmful or biased content. I have some memory issues which are work in progress, so I cannot remember previous conversations, yet! In order to get a response, please provide your Hugging Face (HF) API Token along with your question. This token is unique for every HF user and can be found at [Access Tokens](https://huggingface.co/settings/tokens). Happy Chatting!")
38
+ usage_display = gr.Markdown(f"This app has been used {usage_counter} times.")
39
  prompt = gr.Textbox(label='Question', lines=2, max_lines=5, placeholder = 'Type your question here.')
40
  token = gr.Textbox(label="Hugging Face API Key", type="password")
41