Spaces:
Running
Running
david-oplatka
commited on
Commit
•
1163ecc
1
Parent(s):
c2df775
Add Language Setting
Browse files- app.py +15 -3
- requirements.txt +2 -0
app.py
CHANGED
@@ -9,6 +9,9 @@ import streamlit as st
|
|
9 |
from streamlit_pills import pills
|
10 |
from streamlit_feedback import streamlit_feedback
|
11 |
|
|
|
|
|
|
|
12 |
import sqlite3
|
13 |
import pandas as pd
|
14 |
from datasets import load_dataset
|
@@ -29,6 +32,10 @@ headers = {
|
|
29 |
}
|
30 |
amp_api_key = os.getenv('AMPLITUDE_TOKEN')
|
31 |
|
|
|
|
|
|
|
|
|
32 |
def thumbs_feedback(feedback, **kwargs):
|
33 |
"""
|
34 |
Sends feedback to Amplitude Analytics
|
@@ -40,9 +47,11 @@ def thumbs_feedback(feedback, **kwargs):
|
|
40 |
"event_type": "provided_feedback",
|
41 |
"event_properties": {
|
42 |
"Space Name": kwargs.get("demo_name", "Unknown"),
|
|
|
43 |
"query": kwargs.get("prompt", "No user input"),
|
44 |
"response": kwargs.get("response", "No chat response"),
|
45 |
-
"feedback": feedback["score"]
|
|
|
46 |
}
|
47 |
}]
|
48 |
}
|
@@ -163,8 +172,10 @@ def launch_bot():
|
|
163 |
"event_type": "submitted_query",
|
164 |
"event_properties": {
|
165 |
"Space Name": cfg['demo_name'],
|
|
|
166 |
"query": st.session_state.messages[-2]["content"],
|
167 |
-
"response": st.session_state.messages[-1]["content"]
|
|
|
168 |
}
|
169 |
}]
|
170 |
}
|
@@ -182,7 +193,8 @@ def launch_bot():
|
|
182 |
streamlit_feedback(feedback_type="thumbs", on_submit = thumbs_feedback, key = st.session_state.feedback_key,
|
183 |
kwargs = {"prompt": st.session_state.messages[-2]["content"],
|
184 |
"response": st.session_state.messages[-1]["content"],
|
185 |
-
"demo_name": cfg["demo_name"]
|
|
|
186 |
|
187 |
log_placeholder = st.empty()
|
188 |
with log_placeholder.container():
|
|
|
9 |
from streamlit_pills import pills
|
10 |
from streamlit_feedback import streamlit_feedback
|
11 |
|
12 |
+
from langdetect import detect_langs
|
13 |
+
from langcodes import Language
|
14 |
+
|
15 |
import sqlite3
|
16 |
import pandas as pd
|
17 |
from datasets import load_dataset
|
|
|
32 |
}
|
33 |
amp_api_key = os.getenv('AMPLITUDE_TOKEN')
|
34 |
|
35 |
+
def identifyLanguage(response):
|
36 |
+
lang_code = detect_langs(response)[0].lang
|
37 |
+
return Language.make(language=lang_code).display_name()
|
38 |
+
|
39 |
def thumbs_feedback(feedback, **kwargs):
|
40 |
"""
|
41 |
Sends feedback to Amplitude Analytics
|
|
|
47 |
"event_type": "provided_feedback",
|
48 |
"event_properties": {
|
49 |
"Space Name": kwargs.get("demo_name", "Unknown"),
|
50 |
+
"Demo Type": "Agent",
|
51 |
"query": kwargs.get("prompt", "No user input"),
|
52 |
"response": kwargs.get("response", "No chat response"),
|
53 |
+
"feedback": feedback["score"],
|
54 |
+
"Response Language": kwargs.get("language", "Unknown language")
|
55 |
}
|
56 |
}]
|
57 |
}
|
|
|
172 |
"event_type": "submitted_query",
|
173 |
"event_properties": {
|
174 |
"Space Name": cfg['demo_name'],
|
175 |
+
"Demo Type": "Agent",
|
176 |
"query": st.session_state.messages[-2]["content"],
|
177 |
+
"response": st.session_state.messages[-1]["content"],
|
178 |
+
"Response Language": identifyLanguage(st.session_state.messages[-1])
|
179 |
}
|
180 |
}]
|
181 |
}
|
|
|
193 |
streamlit_feedback(feedback_type="thumbs", on_submit = thumbs_feedback, key = st.session_state.feedback_key,
|
194 |
kwargs = {"prompt": st.session_state.messages[-2]["content"],
|
195 |
"response": st.session_state.messages[-1]["content"],
|
196 |
+
"demo_name": cfg["demo_name"],
|
197 |
+
"language": identifyLanguage(st.session_state.messages[-1]["content"])})
|
198 |
|
199 |
log_placeholder = st.empty()
|
200 |
with log_placeholder.container():
|
requirements.txt
CHANGED
@@ -4,6 +4,8 @@ python-dotenv==1.0.1
|
|
4 |
streamlit==1.32.2
|
5 |
streamlit_pills==0.3.0
|
6 |
streamlit-feedback==0.1.3
|
|
|
|
|
7 |
datasets==2.14.7
|
8 |
uuid==1.30
|
9 |
git+https://{GITHUB_TOKEN}@github.com/vectara/vectara-agent.git
|
|
|
4 |
streamlit==1.32.2
|
5 |
streamlit_pills==0.3.0
|
6 |
streamlit-feedback==0.1.3
|
7 |
+
langdetect==1.0.9
|
8 |
+
langcodes==3.4.0
|
9 |
datasets==2.14.7
|
10 |
uuid==1.30
|
11 |
git+https://{GITHUB_TOKEN}@github.com/vectara/vectara-agent.git
|