Update app.py
Browse files
app.py
CHANGED
|
@@ -47,92 +47,403 @@ def chat_with_bot_stream(user_input):
|
|
| 47 |
for msg in conversation_history
|
| 48 |
]
|
| 49 |
|
| 50 |
-
|
| 51 |
-
|
| 52 |
-
|
| 53 |
-
|
| 54 |
-
|
| 55 |
-
|
| 56 |
-
|
| 57 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 58 |
}
|
| 59 |
|
| 60 |
-
|
| 61 |
-
|
| 62 |
-
|
| 63 |
-
}
|
|
|
|
| 64 |
|
| 65 |
-
|
| 66 |
-
|
| 67 |
-
|
| 68 |
-
|
| 69 |
-
margin: 0 auto;
|
| 70 |
-
width: 80%;
|
| 71 |
-
border-radius: 8px;
|
| 72 |
-
padding: 20px;
|
| 73 |
-
min-height: 300px;
|
| 74 |
-
}
|
| 75 |
|
| 76 |
-
|
| 77 |
-
|
| 78 |
-
|
| 79 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 80 |
|
| 81 |
-
|
| 82 |
-
|
| 83 |
-
|
| 84 |
-
|
| 85 |
-
|
| 86 |
-
|
| 87 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 88 |
|
| 89 |
-
/* Button style */
|
| 90 |
-
button {
|
| 91 |
-
background-color: #56246B !important;
|
| 92 |
-
color: #FFFFFF !important;
|
| 93 |
-
border: none;
|
| 94 |
-
border-radius: 4px;
|
| 95 |
-
cursor: pointer;
|
| 96 |
-
}
|
| 97 |
-
button:hover {
|
| 98 |
-
background-color: #795699 !important;
|
| 99 |
-
}
|
| 100 |
-
"""
|
| 101 |
|
| 102 |
-
|
| 103 |
-
|
| 104 |
-
|
| 105 |
-
|
| 106 |
-
|
| 107 |
-
""
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 108 |
|
| 109 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 110 |
with gr.Tabs():
|
| 111 |
-
with gr.TabItem("
|
| 112 |
-
gr.HTML(
|
| 113 |
-
|
| 114 |
-
|
| 115 |
-
chatbot = gr.Chatbot(label="Chat Output", height=300)
|
| 116 |
-
|
| 117 |
with gr.Row():
|
| 118 |
user_input = gr.Textbox(
|
| 119 |
-
|
| 120 |
-
lines=1
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 121 |
)
|
| 122 |
-
send_button = gr.Button(value="🚀", elem_id="send_button_icon")
|
| 123 |
-
|
| 124 |
send_button.click(
|
| 125 |
fn=chat_with_bot_stream,
|
| 126 |
inputs=user_input,
|
| 127 |
-
outputs=chatbot
|
| 128 |
-
queue=True
|
| 129 |
).then(
|
| 130 |
fn=lambda: "",
|
| 131 |
inputs=None,
|
| 132 |
outputs=user_input
|
| 133 |
)
|
| 134 |
-
|
| 135 |
-
|
| 136 |
-
|
| 137 |
-
|
| 138 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 47 |
for msg in conversation_history
|
| 48 |
]
|
| 49 |
|
| 50 |
+
# word translation
|
| 51 |
+
translations = {
|
| 52 |
+
"English": {
|
| 53 |
+
"header_description": "Your own personal music discovery assistant!",
|
| 54 |
+
"user_input_placeholder": "Enter your music-related questions here!",
|
| 55 |
+
"send_button": "Send",
|
| 56 |
+
"settings_markdown": "### Settings",
|
| 57 |
+
"apply_settings_button": "Apply Settings",
|
| 58 |
+
"select_language_label": "Language",
|
| 59 |
+
"theme_label": "Theme",
|
| 60 |
+
"theme_choices": ["Dark", "Light"],
|
| 61 |
+
"font_size_label": "Font Size",
|
| 62 |
+
"font_size_choices": ["Small", "Medium", "Large"],
|
| 63 |
+
"language_choices": ["English", "Spanish", "French"]
|
| 64 |
+
},
|
| 65 |
+
"Spanish": {
|
| 66 |
+
"header_description": "¡Tu asistente personal para descubrir música!",
|
| 67 |
+
"user_input_placeholder": "¡Introduce tus preguntas relacionadas con la música!",
|
| 68 |
+
"send_button": "Enviar",
|
| 69 |
+
"settings_markdown": "### Configuración",
|
| 70 |
+
"apply_settings_button": "Aplicar Configuración",
|
| 71 |
+
"select_language_label": "🌐 Idioma",
|
| 72 |
+
"theme_label": "Tema",
|
| 73 |
+
"theme_choices": ["Oscuro", "Claro"],
|
| 74 |
+
"font_size_label": "Tamaño de Fuente",
|
| 75 |
+
"font_size_choices": ["Pequeño", "Mediano", "Grande"],
|
| 76 |
+
"language_choices": ["Inglés", "Español", "Francés"]
|
| 77 |
+
},
|
| 78 |
+
"French": {
|
| 79 |
+
"header_description": "Votre assistant personnel pour découvrir de la musique !",
|
| 80 |
+
"user_input_placeholder": "Entrez vos questions sur la musique ici !",
|
| 81 |
+
"send_button": "Envoyer",
|
| 82 |
+
"settings_markdown": "### Paramètres",
|
| 83 |
+
"apply_settings_button": "Appliquer les paramètres",
|
| 84 |
+
"select_language_label": "🌐 Langue",
|
| 85 |
+
"theme_label": "Thème",
|
| 86 |
+
"theme_choices": ["Sombre", "Clair"],
|
| 87 |
+
"font_size_label": "Taille de police",
|
| 88 |
+
"font_size_choices": ["Petit", "Moyen", "Grand"],
|
| 89 |
+
"language_choices": ["Anglais", "Espagnol", "Français"]
|
| 90 |
+
}
|
| 91 |
}
|
| 92 |
|
| 93 |
+
# translations for theme
|
| 94 |
+
english_to_spanish_theme = {"Dark": "Oscuro", "Light": "Claro"}
|
| 95 |
+
spanish_to_english_theme = {"Oscuro": "Dark", "Claro": "Light"}
|
| 96 |
+
english_to_french_theme = {"Dark": "Sombre", "Light": "Clair"}
|
| 97 |
+
french_to_english_theme = {"Sombre": "Dark", "Clair": "Light"}
|
| 98 |
|
| 99 |
+
english_to_spanish_font = {"Small": "Pequeño", "Medium": "Mediano", "Large": "Grande"}
|
| 100 |
+
spanish_to_english_font = {"Pequeño": "Small", "Mediano": "Medium", "Grande": "Large"}
|
| 101 |
+
english_to_french_font = {"Small": "Petit", "Medium": "Moyen", "Large": "Grand"}
|
| 102 |
+
french_to_english_font = {"Petit": "Small", "Moyen": "Medium", "Grand": "Large"}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 103 |
|
| 104 |
+
# I wanted to include the c in Fraincais and the spanish e and n in Spanish
|
| 105 |
+
def normalize_language(lang):
|
| 106 |
+
if lang in ["English", "Inglés", "Anglais"]:
|
| 107 |
+
return "English"
|
| 108 |
+
elif lang in ["Spanish", "Español", "Espagnol"]:
|
| 109 |
+
return "Spanish"
|
| 110 |
+
elif lang in ["French", "Français"]:
|
| 111 |
+
return "French"
|
| 112 |
+
else:
|
| 113 |
+
return "English"
|
| 114 |
|
| 115 |
+
def update_all_settings(theme, font_size, language):
|
| 116 |
+
target_lang = normalize_language(language)
|
| 117 |
+
t = translations[target_lang]
|
| 118 |
+
|
| 119 |
+
if target_lang == "Spanish":
|
| 120 |
+
theme_for_ui = english_to_spanish_theme.get(theme, theme) if theme in english_to_spanish_theme else theme if theme in spanish_to_english_theme else "Oscuro"
|
| 121 |
+
elif target_lang == "French":
|
| 122 |
+
theme_for_ui = english_to_french_theme.get(theme, theme) if theme in english_to_french_theme else theme if theme in french_to_english_theme else "Sombre"
|
| 123 |
+
else: # target is English
|
| 124 |
+
theme_for_ui = spanish_to_english_theme.get(theme, theme) if theme in spanish_to_english_theme else theme if theme in english_to_spanish_theme else "Dark"
|
| 125 |
+
|
| 126 |
+
if target_lang == "Spanish":
|
| 127 |
+
font_for_ui = english_to_spanish_font.get(font_size, font_size) if font_size in english_to_spanish_font else font_size if font_size in spanish_to_english_font else "Mediano"
|
| 128 |
+
elif target_lang == "French":
|
| 129 |
+
font_for_ui = english_to_french_font.get(font_size, font_size) if font_size in english_to_french_font else font_size if font_size in french_to_english_font else "Moyen"
|
| 130 |
+
else:
|
| 131 |
+
font_for_ui = spanish_to_english_font.get(font_size, font_size) if font_size in spanish_to_english_font else font_size if theme in english_to_spanish_font else "Medium"
|
| 132 |
+
|
| 133 |
+
if theme in ["Dark", "Light"]:
|
| 134 |
+
theme_for_style = theme
|
| 135 |
+
elif theme in spanish_to_english_theme:
|
| 136 |
+
theme_for_style = spanish_to_english_theme.get(theme, "Dark")
|
| 137 |
+
elif theme in french_to_english_theme:
|
| 138 |
+
theme_for_style = french_to_english_theme.get(theme, "Dark")
|
| 139 |
+
else:
|
| 140 |
+
theme_for_style = "Dark"
|
| 141 |
+
|
| 142 |
+
if font_size in ["Small", "Medium", "Large"]:
|
| 143 |
+
font_for_style = font_size
|
| 144 |
+
elif font_size in spanish_to_english_font:
|
| 145 |
+
font_for_style = spanish_to_english_font.get(font_size, "Medium")
|
| 146 |
+
elif font_size in french_to_english_font:
|
| 147 |
+
font_for_style = french_to_english_font.get(font_size, "Medium")
|
| 148 |
+
else:
|
| 149 |
+
font_for_style = "Medium"
|
| 150 |
+
|
| 151 |
+
dynamic_style = update_styles(theme_for_style, font_for_style)
|
| 152 |
+
|
| 153 |
+
#Languages
|
| 154 |
+
if target_lang == "English":
|
| 155 |
+
language_value = "English"
|
| 156 |
+
elif target_lang == "Spanish":
|
| 157 |
+
language_value = "Español"
|
| 158 |
+
elif target_lang == "French":
|
| 159 |
+
language_value = "Français"
|
| 160 |
+
header_html = f'<p id="header_description">{t["header_description"]}</p>'
|
| 161 |
+
|
| 162 |
+
return (
|
| 163 |
+
dynamic_style,
|
| 164 |
+
gr.update(value=header_html),
|
| 165 |
+
gr.update(placeholder=t["user_input_placeholder"]),
|
| 166 |
+
gr.update(value=t["send_button"]),
|
| 167 |
+
gr.update(value=t["settings_markdown"]),
|
| 168 |
+
gr.update(value=t["apply_settings_button"]),
|
| 169 |
+
gr.update(label=t["theme_label"], choices=t["theme_choices"], value=theme_for_ui),
|
| 170 |
+
gr.update(label=t["font_size_label"], choices=t["font_size_choices"], value=font_for_ui),
|
| 171 |
+
gr.update(label=t["select_language_label"], choices=t["language_choices"], value=language_value)
|
| 172 |
+
)
|
| 173 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 174 |
|
| 175 |
+
def update_styles(theme, font_size):
|
| 176 |
+
if theme == "Dark":
|
| 177 |
+
bg = "#18181B"
|
| 178 |
+
text_color = "#ffffff"
|
| 179 |
+
input_bg = "#2E2E2E"
|
| 180 |
+
button_bg = "#3A3A3A"
|
| 181 |
+
settings_box_bg = "#2E2E2E"
|
| 182 |
+
apply_button_bg = "#3A3A3A"
|
| 183 |
+
radio_bg = "#2E2E2E"
|
| 184 |
+
settings_heading_color = text_color
|
| 185 |
+
border_color = "#444444"
|
| 186 |
+
placeholder_color = "#888888"
|
| 187 |
+
chatbot_bg = "#18181B"
|
| 188 |
+
chatbot_text_color = "#ffffff"
|
| 189 |
+
else:
|
| 190 |
+
bg = "#ffffff"
|
| 191 |
+
text_color = "#000000"
|
| 192 |
+
input_bg = "#f2f2f2"
|
| 193 |
+
button_bg = "#dddddd"
|
| 194 |
+
settings_box_bg = "#eeeeee"
|
| 195 |
+
apply_button_bg = "#e0e0e0"
|
| 196 |
+
radio_bg = "#e0e0e0"
|
| 197 |
+
settings_heading_color = "#333333"
|
| 198 |
+
border_color = "#cccccc"
|
| 199 |
+
placeholder_color = "#666666"
|
| 200 |
+
chatbot_bg = "#cfcfcf"
|
| 201 |
+
chatbot_text_color = "#000000"
|
| 202 |
+
|
| 203 |
+
if font_size == "Small":
|
| 204 |
+
fsize = "0.8rem"
|
| 205 |
+
tab_padding = "4px 8px"
|
| 206 |
+
elif font_size == "Medium":
|
| 207 |
+
fsize = "1.2rem"
|
| 208 |
+
tab_padding = "6px 12px"
|
| 209 |
+
elif font_size == "Large":
|
| 210 |
+
fsize = "1.8rem"
|
| 211 |
+
tab_padding = "8px 16px"
|
| 212 |
+
else:
|
| 213 |
+
fsize = "1rem"
|
| 214 |
+
tab_padding = "5px 10px"
|
| 215 |
+
|
| 216 |
+
style = f"""
|
| 217 |
+
<style id="dynamic_styles">
|
| 218 |
+
@import url('https://fonts.googleapis.com/css2?family=Inter:wght@400;600&display=swap');
|
| 219 |
+
body, .gradio-container {{
|
| 220 |
+
background-color: {bg} !important;
|
| 221 |
+
color: {text_color} !important;
|
| 222 |
+
font-size: {fsize} !important;
|
| 223 |
+
font-family: 'Inter', sans-serif;
|
| 224 |
+
margin: 0;
|
| 225 |
+
padding: 0;
|
| 226 |
+
}}
|
| 227 |
+
|
| 228 |
+
#header_section {{
|
| 229 |
+
width: 400px;
|
| 230 |
+
height: 100px;
|
| 231 |
+
background: url("https://huggingface.co/spaces/MusifyLTD/Musify/resolve/main/logo.png")
|
| 232 |
+
no-repeat center center;
|
| 233 |
+
background-size: contain;
|
| 234 |
+
margin: 0px auto;
|
| 235 |
+
margin-bottom: -10px;
|
| 236 |
+
}}
|
| 237 |
+
|
| 238 |
+
#header_description {{
|
| 239 |
+
text-align: center;
|
| 240 |
+
color: {text_color} !important;
|
| 241 |
+
font-size: {fsize} !important;
|
| 242 |
+
margin-top: -10px;
|
| 243 |
+
margin-bottom: 10px;
|
| 244 |
+
}}
|
| 245 |
+
|
| 246 |
+
h3 {{
|
| 247 |
+
color: {text_color} !important;
|
| 248 |
+
}}
|
| 249 |
+
|
| 250 |
+
#chatbot {{
|
| 251 |
+
background-color: {chatbot_bg} !important;
|
| 252 |
+
color: {chatbot_text_color} !important;
|
| 253 |
+
font-size: {fsize} !important;
|
| 254 |
+
}}
|
| 255 |
+
|
| 256 |
+
div[role="log"] {{
|
| 257 |
+
background-color: {chatbot_bg} !important;
|
| 258 |
+
color: {chatbot_text_color} !important;
|
| 259 |
+
}}
|
| 260 |
|
| 261 |
+
div[data-testid="bot"], div[data-testid="user"] {{
|
| 262 |
+
color: {chatbot_text_color} !important;
|
| 263 |
+
}}
|
| 264 |
+
|
| 265 |
+
#user_input {{
|
| 266 |
+
background-color: {button_bg} !important;
|
| 267 |
+
border: 1px solid {border_color} !important;
|
| 268 |
+
height: 65px;
|
| 269 |
+
}}
|
| 270 |
+
#user_input textarea {{
|
| 271 |
+
background-color: {input_bg} !important;
|
| 272 |
+
color: {text_color} !important;
|
| 273 |
+
font-size: {fsize} !important;
|
| 274 |
+
border: 1px solid {border_color} !important;
|
| 275 |
+
padding: 10px;
|
| 276 |
+
border: none;
|
| 277 |
+
}}
|
| 278 |
+
#user_input textarea::placeholder {{
|
| 279 |
+
color: {placeholder_color} !important;
|
| 280 |
+
font-size: {fsize} !important;
|
| 281 |
+
opacity: 0.73;
|
| 282 |
+
}}
|
| 283 |
+
|
| 284 |
+
#send_button {{
|
| 285 |
+
background-color: {button_bg} !important;
|
| 286 |
+
color: {text_color} !important;
|
| 287 |
+
font-size: {fsize} !important;
|
| 288 |
+
border: 1px solid {border_color} !important;
|
| 289 |
+
margin-left: 1px;
|
| 290 |
+
font-family: 'Inter', sans-serif;
|
| 291 |
+
height: 67px;
|
| 292 |
+
display: flex;
|
| 293 |
+
align-items: center;
|
| 294 |
+
justify-content: center;
|
| 295 |
+
padding: 0 10px;
|
| 296 |
+
}}
|
| 297 |
+
|
| 298 |
+
#settings_box {{
|
| 299 |
+
background-color: {settings_box_bg} !important;
|
| 300 |
+
padding: 10px;
|
| 301 |
+
border-radius: 8px;
|
| 302 |
+
font-size: {fsize} !important;
|
| 303 |
+
border: 1px solid {border_color} !important;
|
| 304 |
+
}}
|
| 305 |
+
#settings_box .gr-markdown h3 {{
|
| 306 |
+
color: {settings_heading_color} !important;
|
| 307 |
+
font-size: {fsize} !important;
|
| 308 |
+
}}
|
| 309 |
+
|
| 310 |
+
#settings_box .gr-radio-group,
|
| 311 |
+
#settings_box .gr-radio-group * {{
|
| 312 |
+
background-color: {radio_bg} !important;
|
| 313 |
+
color: {text_color} !important;
|
| 314 |
+
font-size: {fsize} !important;
|
| 315 |
+
}}
|
| 316 |
+
|
| 317 |
+
#apply_settings_button {{
|
| 318 |
+
background-color: {apply_button_bg} !important;
|
| 319 |
+
color: {text_color} !important;
|
| 320 |
+
font-size: {fsize} !important;
|
| 321 |
+
border: 1px solid {border_color} !important;
|
| 322 |
+
}}
|
| 323 |
+
|
| 324 |
+
div[role="tablist"] {{
|
| 325 |
+
border: 1px;
|
| 326 |
+
border-radius: 8px;
|
| 327 |
+
padding: {tab_padding} !important;
|
| 328 |
+
height: auto !important;
|
| 329 |
+
min-height: 0 !important;
|
| 330 |
+
}}
|
| 331 |
+
div[role="tab"] {{
|
| 332 |
+
font-size: {fsize} !important;
|
| 333 |
+
padding: {tab_padding} !important;
|
| 334 |
+
color: {text_color} !important;
|
| 335 |
+
}}
|
| 336 |
+
|
| 337 |
+
button[role="tab"][aria-selected="true"]::after {{
|
| 338 |
+
background-color:#56246B !important;
|
| 339 |
+
}}
|
| 340 |
+
|
| 341 |
+
button[role="tab"][aria-selected="true"] {{
|
| 342 |
+
color: {text_color} !important;
|
| 343 |
+
}}
|
| 344 |
+
|
| 345 |
+
button[role="tab"][aria-selected="false"] {{
|
| 346 |
+
background-color:transparent !important;
|
| 347 |
+
color: #616161 !important;
|
| 348 |
+
}}
|
| 349 |
+
|
| 350 |
+
input[type="radio"] {{
|
| 351 |
+
background-color: #795699 !important;
|
| 352 |
+
}}
|
| 353 |
+
|
| 354 |
+
input[type="radio"]:checked {{
|
| 355 |
+
background-color: #56246B !important;
|
| 356 |
+
border-color: #795699 !important;
|
| 357 |
+
}}
|
| 358 |
+
|
| 359 |
+
fieldset {{
|
| 360 |
+
background-color: {settings_box_bg} !important;
|
| 361 |
+
color: {text_color} !important;
|
| 362 |
+
}}
|
| 363 |
+
|
| 364 |
+
label[data-testid] {{
|
| 365 |
+
background-color: {bg} !important;
|
| 366 |
+
color: {text_color} !important;
|
| 367 |
+
}}
|
| 368 |
+
|
| 369 |
+
[data-testid="block-info"] {{
|
| 370 |
+
color: {text_color} !important;
|
| 371 |
+
}}
|
| 372 |
+
|
| 373 |
+
</style>
|
| 374 |
+
"""
|
| 375 |
+
return style
|
| 376 |
+
|
| 377 |
+
# Gradio build stuff actually starts here
|
| 378 |
+
with gr.Blocks(css=None) as demo:
|
| 379 |
+
dynamic_styles = gr.HTML(value=update_styles("Dark", "Medium"))
|
| 380 |
+
|
| 381 |
with gr.Tabs():
|
| 382 |
+
with gr.TabItem("💬 Chatbot"):
|
| 383 |
+
gr.HTML('<div id="header_section"></div>')
|
| 384 |
+
header_desc = gr.HTML('<p id="header_description">' + translations["English"]["header_description"] + '</p>')
|
| 385 |
+
chatbot = gr.Chatbot(label="", height=400, show_label=False, elem_id="chatbot")
|
|
|
|
|
|
|
| 386 |
with gr.Row():
|
| 387 |
user_input = gr.Textbox(
|
| 388 |
+
show_label=False,
|
| 389 |
+
lines=1,
|
| 390 |
+
placeholder=translations["English"]["user_input_placeholder"],
|
| 391 |
+
interactive=True,
|
| 392 |
+
elem_id="user_input",
|
| 393 |
+
scale=15
|
| 394 |
+
)
|
| 395 |
+
send_button = gr.Button(
|
| 396 |
+
value=translations["English"]["send_button"],
|
| 397 |
+
elem_id="send_button",
|
| 398 |
+
scale=1
|
| 399 |
)
|
|
|
|
|
|
|
| 400 |
send_button.click(
|
| 401 |
fn=chat_with_bot_stream,
|
| 402 |
inputs=user_input,
|
| 403 |
+
outputs=chatbot
|
|
|
|
| 404 |
).then(
|
| 405 |
fn=lambda: "",
|
| 406 |
inputs=None,
|
| 407 |
outputs=user_input
|
| 408 |
)
|
| 409 |
+
|
| 410 |
+
# SETTINGS PAGE
|
| 411 |
+
with gr.TabItem("⚙️ Settings"):
|
| 412 |
+
with gr.Column(elem_id="settings_box"):
|
| 413 |
+
settings_md = gr.Markdown(translations["English"]["settings_markdown"])
|
| 414 |
+
theme_radio = gr.Radio(
|
| 415 |
+
choices=translations["English"]["theme_choices"],
|
| 416 |
+
value="Dark",
|
| 417 |
+
label=translations["English"]["theme_label"]
|
| 418 |
+
)
|
| 419 |
+
font_radio = gr.Radio(
|
| 420 |
+
choices=translations["English"]["font_size_choices"],
|
| 421 |
+
value="Medium",
|
| 422 |
+
label=translations["English"]["font_size_label"]
|
| 423 |
+
)
|
| 424 |
+
language_radio = gr.Radio(
|
| 425 |
+
choices=translations["English"]["language_choices"],
|
| 426 |
+
value="English",
|
| 427 |
+
label=translations["English"]["select_language_label"]
|
| 428 |
+
)
|
| 429 |
+
apply_button = gr.Button(
|
| 430 |
+
translations["English"]["apply_settings_button"],
|
| 431 |
+
elem_id="apply_settings_button"
|
| 432 |
+
)
|
| 433 |
+
apply_button.click(
|
| 434 |
+
fn=update_all_settings,
|
| 435 |
+
inputs=[theme_radio, font_radio, language_radio],
|
| 436 |
+
outputs=[
|
| 437 |
+
dynamic_styles,
|
| 438 |
+
header_desc,
|
| 439 |
+
user_input,
|
| 440 |
+
send_button,
|
| 441 |
+
settings_md,
|
| 442 |
+
apply_button,
|
| 443 |
+
theme_radio,
|
| 444 |
+
font_radio,
|
| 445 |
+
language_radio
|
| 446 |
+
]
|
| 447 |
+
)
|
| 448 |
+
|
| 449 |
+
demo.launch()
|