ysharma HF staff commited on
Commit
6181e1d
1 Parent(s): 028e7df

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +5 -2
app.py CHANGED
@@ -2,12 +2,15 @@ import json
2
  import gradio as gr
3
  import os
4
  import requests
 
5
 
6
  hf_token = os.getenv('HF_TOKEN')
7
  api_url = os.getenv('API_URL')
8
- api_url_nostream = os.getenv('API_URL_NOSTREAM')
9
  #headers = {'Content-Type': 'application/json',}
10
  headers = {"Authorization": f"Bearer {hf_token}"}
 
 
11
 
12
  system_message = "\nYou 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.\n\nIf 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."
13
  title = "Llama2 70B Chatbot"
@@ -100,7 +103,7 @@ def predict_batch(message, chatbot, system_prompt="", temperature=0.9, max_new_t
100
  },
101
  }
102
 
103
- response = requests.post(api_url_nostream, headers=headers, json=data ) #auth=('hf', hf_token)) data=json.dumps(data),
104
  print(f"response - {response}")
105
  print(f"response.status_code - {response.status_code}")
106
  print(f"response.text - {response.text}")
 
2
  import gradio as gr
3
  import os
4
  import requests
5
+ from huggingface_hub import AsyncInferenceClient
6
 
7
  hf_token = os.getenv('HF_TOKEN')
8
  api_url = os.getenv('API_URL')
9
+ #api_url_nostream = os.getenv('API_URL_NOSTREAM')
10
  #headers = {'Content-Type': 'application/json',}
11
  headers = {"Authorization": f"Bearer {hf_token}"}
12
+ client = AsyncInferenceClient(api_url)
13
+
14
 
15
  system_message = "\nYou 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.\n\nIf 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."
16
  title = "Llama2 70B Chatbot"
 
103
  },
104
  }
105
 
106
+ response = requests.post(api_url, headers=headers, json=data ) #auth=('hf', hf_token)) data=json.dumps(data),
107
  print(f"response - {response}")
108
  print(f"response.status_code - {response.status_code}")
109
  print(f"response.text - {response.text}")