atishayj281 commited on
Commit
4b99f88
·
1 Parent(s): af29019

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +10 -5
app.py CHANGED
@@ -4,19 +4,23 @@ import requests
4
  API_URL = "https://api-inference.huggingface.co/models/ProsusAI/finbert"
5
  headers = {"Authorization": "Bearer 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"}
6
 
 
 
 
 
7
  def query(payload):
8
  response = requests.post(API_URL, headers=headers, json=payload)
9
  return response.json()
10
 
11
  def display_chat_history(chat_history):
12
- for entry in chat_history:
13
  if entry["speaker"] == "You":
14
  st.text(f"You: {entry['message']}")
15
  elif entry["speaker"] == "Chatbot":
16
  st.text(f"Chatbot:")
17
-
18
- for label_info in entry['message'][0]:
19
- st.write(f"Label: {label_info['label']}, Score: {label_info['score']}")
20
 
21
 
22
  def display_bot_response(bot_response):
@@ -41,8 +45,9 @@ def main():
41
  })
42
 
43
  # Update the chat history
44
- chat_history.append({"speaker": "You", "message": user_input})
45
  chat_history.append({"speaker": "Chatbot", "message": bot_response})
 
46
 
47
  # Save the chat history in session state
48
  st.session_state.chat_history = chat_history
 
4
  API_URL = "https://api-inference.huggingface.co/models/ProsusAI/finbert"
5
  headers = {"Authorization": "Bearer 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"}
6
 
7
+ def show_plot(bot_response):
8
+ scores = {label_info['label']: label_info['score'] for label_info in bot_response}
9
+ st.bar_chart(scores)
10
+
11
  def query(payload):
12
  response = requests.post(API_URL, headers=headers, json=payload)
13
  return response.json()
14
 
15
  def display_chat_history(chat_history):
16
+ for entry in chat_history[::-1]:
17
  if entry["speaker"] == "You":
18
  st.text(f"You: {entry['message']}")
19
  elif entry["speaker"] == "Chatbot":
20
  st.text(f"Chatbot:")
21
+ # for label_info in entry['message'][0]:
22
+ # st.write(f"Label: {label_info['label']}, Score: {label_info['score']}")
23
+ show_plot(entry['message'][0])
24
 
25
 
26
  def display_bot_response(bot_response):
 
45
  })
46
 
47
  # Update the chat history
48
+
49
  chat_history.append({"speaker": "Chatbot", "message": bot_response})
50
+ chat_history.append({"speaker": "You", "message": user_input})
51
 
52
  # Save the chat history in session state
53
  st.session_state.chat_history = chat_history