merve HF staff commited on
Commit
3252678
β€’
1 Parent(s): de4cce0

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +7 -7
app.py CHANGED
@@ -11,7 +11,7 @@ def query(payload):
11
  headers = {"Authorization": f"Bearer {api_token}"}
12
  API_URL = f"https://api-inference.huggingface.co/models/{model_id}"
13
  response = requests.post(API_URL, headers=headers, json=payload)
14
- return response.json()
15
 
16
 
17
 
@@ -34,7 +34,7 @@ with placeholder.container():
34
 
35
  message(input, is_user=True) # align's the message to the right
36
 
37
- data = query(
38
  {
39
  "inputs": {
40
  "question": input,
@@ -42,11 +42,11 @@ data = query(
42
  }
43
  }
44
  )
45
- #try:
46
- model_answer = data["answer"]
47
- response_templates = [f"{model_answer} is the best task for this 🀩", f"I think you should use {model_answer} πŸͺ„", f"I think {model_answer} should work for you πŸ€“"]
48
- bot_answer = random.choice(response_templates)
49
- message_history.append(bot_answer)
50
 
51
 
52
  """
 
11
  headers = {"Authorization": f"Bearer {api_token}"}
12
  API_URL = f"https://api-inference.huggingface.co/models/{model_id}"
13
  response = requests.post(API_URL, headers=headers, json=payload)
14
+ return response.json(), response
15
 
16
 
17
 
 
34
 
35
  message(input, is_user=True) # align's the message to the right
36
 
37
+ data, resp = query(
38
  {
39
  "inputs": {
40
  "question": input,
 
42
  }
43
  }
44
  )
45
+ if resp.status_code == 200:
46
+ model_answer = data["answer"]
47
+ response_templates = [f"{model_answer} is the best task for this 🀩", f"I think you should use {model_answer} πŸͺ„", f"I think {model_answer} should work for you πŸ€“"]
48
+ bot_answer = random.choice(response_templates)
49
+ message_history.append(bot_answer)
50
 
51
 
52
  """