Spaces:
Sleeping
Sleeping
Commit
·
420b66d
1
Parent(s):
856a204
Update app.py
Browse files
app.py
CHANGED
|
@@ -4,7 +4,7 @@ from huggingface_hub import InferenceClient
|
|
| 4 |
# Define available models (update with your actual model IDs)
|
| 5 |
model_list = {
|
| 6 |
"Safe LM": "HuggingFaceH4/zephyr-7b-beta", # Replace with your Safe LM model ID
|
| 7 |
-
"
|
| 8 |
"Another Model": "HuggingFaceH4/zephyr-7b-beta"
|
| 9 |
}
|
| 10 |
|
|
@@ -47,45 +47,50 @@ def respond(message, history, system_message, max_tokens, temperature, top_p, se
|
|
| 47 |
print(f"Error calling model API: {e}")
|
| 48 |
yield f"Sorry, there was an error: {str(e)}"
|
| 49 |
|
| 50 |
-
# Custom CSS for branding with blue,
|
| 51 |
css = """
|
|
|
|
|
|
|
| 52 |
body {
|
| 53 |
-
background-color: #
|
| 54 |
-
font-family: '
|
|
|
|
|
|
|
| 55 |
}
|
| 56 |
.gradio-container {
|
| 57 |
background-color: #FFFFFF;
|
| 58 |
border-radius: 16px;
|
| 59 |
-
box-shadow: 0
|
| 60 |
-
max-width:
|
| 61 |
-
margin:
|
| 62 |
}
|
| 63 |
.app-header {
|
| 64 |
-
background: linear-gradient(135deg, #
|
| 65 |
-
padding:
|
| 66 |
border-radius: 16px 16px 0 0;
|
| 67 |
position: relative;
|
| 68 |
color: white;
|
| 69 |
overflow: hidden;
|
| 70 |
}
|
| 71 |
.app-header::before {
|
| 72 |
-
content: "
|
| 73 |
position: absolute;
|
| 74 |
-
font-size:
|
| 75 |
opacity: 0.1;
|
| 76 |
right: -20px;
|
| 77 |
top: -30px;
|
| 78 |
transform: rotate(15deg);
|
| 79 |
}
|
| 80 |
.app-title {
|
| 81 |
-
font-size:
|
| 82 |
-
font-weight:
|
| 83 |
margin: 0;
|
| 84 |
display: flex;
|
| 85 |
align-items: center;
|
|
|
|
| 86 |
}
|
| 87 |
.app-title .safe {
|
| 88 |
-
font-weight:
|
| 89 |
margin-right: 5px;
|
| 90 |
}
|
| 91 |
.app-title .lm {
|
|
@@ -94,7 +99,7 @@ body {
|
|
| 94 |
}
|
| 95 |
.app-title .shield {
|
| 96 |
margin-right: 10px;
|
| 97 |
-
font-size:
|
| 98 |
}
|
| 99 |
.app-subtitle {
|
| 100 |
font-size: 14px;
|
|
@@ -102,37 +107,54 @@ body {
|
|
| 102 |
margin-top: 5px;
|
| 103 |
}
|
| 104 |
.golden-accent {
|
| 105 |
-
border-top:
|
| 106 |
margin: 0;
|
| 107 |
}
|
| 108 |
button, .gradio-button {
|
| 109 |
-
background: linear-gradient(to right, #
|
| 110 |
color: white !important;
|
| 111 |
border: none !important;
|
| 112 |
-
border-radius:
|
| 113 |
-
padding:
|
| 114 |
font-weight: 600 !important;
|
| 115 |
transition: all 0.3s ease !important;
|
|
|
|
| 116 |
}
|
| 117 |
button:hover, .gradio-button:hover {
|
| 118 |
-
transform: translateY(-
|
| 119 |
-
box-shadow: 0
|
| 120 |
}
|
| 121 |
.gradio-dropdown, .gradio-slider, .gradio-textbox, .gradio-checkbox {
|
| 122 |
-
border-radius:
|
| 123 |
border: 1px solid #e1e5eb !important;
|
|
|
|
| 124 |
}
|
| 125 |
.model-select {
|
| 126 |
-
border-left:
|
| 127 |
-
padding-left:
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 128 |
}
|
| 129 |
.footer {
|
| 130 |
-
|
| 131 |
-
color: #666;
|
| 132 |
-
font-size: 12px;
|
| 133 |
-
margin-top: 20px;
|
| 134 |
-
padding: 10px;
|
| 135 |
}
|
|
|
|
|
|
|
|
|
|
|
|
|
| 136 |
"""
|
| 137 |
|
| 138 |
with gr.Blocks(css=css) as demo:
|
|
@@ -140,7 +162,7 @@ with gr.Blocks(css=css) as demo:
|
|
| 140 |
gr.HTML("""
|
| 141 |
<div class="app-header">
|
| 142 |
<h1 class="app-title">
|
| 143 |
-
<span class="shield"
|
| 144 |
<span class="safe">Safe</span>
|
| 145 |
<span class="lm">Playground</span>
|
| 146 |
</h1>
|
|
@@ -205,12 +227,8 @@ with gr.Blocks(css=css) as demo:
|
|
| 205 |
with gr.Row():
|
| 206 |
clear_button = gr.Button("Clear Chat")
|
| 207 |
|
| 208 |
-
#
|
| 209 |
-
gr.HTML(""
|
| 210 |
-
<div class="footer">
|
| 211 |
-
<p>Safe Playground™ | Responsible AI Technology | © 2025</p>
|
| 212 |
-
</div>
|
| 213 |
-
""")
|
| 214 |
|
| 215 |
# Fix 1: Correct event handling for the chatbot interface
|
| 216 |
def user(user_message, history):
|
|
|
|
| 4 |
# Define available models (update with your actual model IDs)
|
| 5 |
model_list = {
|
| 6 |
"Safe LM": "HuggingFaceH4/zephyr-7b-beta", # Replace with your Safe LM model ID
|
| 7 |
+
"Baseline 1": "HuggingFaceH4/zephyr-7b-beta",
|
| 8 |
"Another Model": "HuggingFaceH4/zephyr-7b-beta"
|
| 9 |
}
|
| 10 |
|
|
|
|
| 47 |
print(f"Error calling model API: {e}")
|
| 48 |
yield f"Sorry, there was an error: {str(e)}"
|
| 49 |
|
| 50 |
+
# Custom CSS for branding with lighter blue background, Palatino font
|
| 51 |
css = """
|
| 52 |
+
@import url('https://fonts.googleapis.com/css2?family=EB+Garamond&display=swap');
|
| 53 |
+
|
| 54 |
body {
|
| 55 |
+
background-color: #f8fafd;
|
| 56 |
+
font-family: 'Palatino', 'EB Garamond', 'Times New Roman', serif;
|
| 57 |
+
max-width: 100%;
|
| 58 |
+
overflow-x: hidden;
|
| 59 |
}
|
| 60 |
.gradio-container {
|
| 61 |
background-color: #FFFFFF;
|
| 62 |
border-radius: 16px;
|
| 63 |
+
box-shadow: 0 3px 10px rgba(0,0,0,0.05);
|
| 64 |
+
max-width: 90%;
|
| 65 |
+
margin: 10px auto;
|
| 66 |
}
|
| 67 |
.app-header {
|
| 68 |
+
background: linear-gradient(135deg, #4a90e2, #75c6ef);
|
| 69 |
+
padding: 15px;
|
| 70 |
border-radius: 16px 16px 0 0;
|
| 71 |
position: relative;
|
| 72 |
color: white;
|
| 73 |
overflow: hidden;
|
| 74 |
}
|
| 75 |
.app-header::before {
|
| 76 |
+
content: "🛡️";
|
| 77 |
position: absolute;
|
| 78 |
+
font-size: 100px;
|
| 79 |
opacity: 0.1;
|
| 80 |
right: -20px;
|
| 81 |
top: -30px;
|
| 82 |
transform: rotate(15deg);
|
| 83 |
}
|
| 84 |
.app-title {
|
| 85 |
+
font-size: 24px;
|
| 86 |
+
font-weight: 600;
|
| 87 |
margin: 0;
|
| 88 |
display: flex;
|
| 89 |
align-items: center;
|
| 90 |
+
font-family: 'Palatino', serif;
|
| 91 |
}
|
| 92 |
.app-title .safe {
|
| 93 |
+
font-weight: 800;
|
| 94 |
margin-right: 5px;
|
| 95 |
}
|
| 96 |
.app-title .lm {
|
|
|
|
| 99 |
}
|
| 100 |
.app-title .shield {
|
| 101 |
margin-right: 10px;
|
| 102 |
+
font-size: 22px;
|
| 103 |
}
|
| 104 |
.app-subtitle {
|
| 105 |
font-size: 14px;
|
|
|
|
| 107 |
margin-top: 5px;
|
| 108 |
}
|
| 109 |
.golden-accent {
|
| 110 |
+
border-top: 2px solid #e6c200;
|
| 111 |
margin: 0;
|
| 112 |
}
|
| 113 |
button, .gradio-button {
|
| 114 |
+
background: linear-gradient(to right, #4a90e2, #75c6ef) !important;
|
| 115 |
color: white !important;
|
| 116 |
border: none !important;
|
| 117 |
+
border-radius: 8px !important;
|
| 118 |
+
padding: 8px 16px !important;
|
| 119 |
font-weight: 600 !important;
|
| 120 |
transition: all 0.3s ease !important;
|
| 121 |
+
font-family: 'Palatino', serif !important;
|
| 122 |
}
|
| 123 |
button:hover, .gradio-button:hover {
|
| 124 |
+
transform: translateY(-1px) !important;
|
| 125 |
+
box-shadow: 0 3px 6px rgba(74, 144, 226, 0.2) !important;
|
| 126 |
}
|
| 127 |
.gradio-dropdown, .gradio-slider, .gradio-textbox, .gradio-checkbox {
|
| 128 |
+
border-radius: 8px !important;
|
| 129 |
border: 1px solid #e1e5eb !important;
|
| 130 |
+
font-family: 'Palatino', serif !important;
|
| 131 |
}
|
| 132 |
.model-select {
|
| 133 |
+
border-left: 3px solid #e6c200 !important;
|
| 134 |
+
padding-left: 8px !important;
|
| 135 |
+
}
|
| 136 |
+
.chatbot .assistant-message::before {
|
| 137 |
+
content: "🛡️ ";
|
| 138 |
+
}
|
| 139 |
+
.chatbot .user-message {
|
| 140 |
+
background-color: #f0f7ff !important;
|
| 141 |
+
border-radius: 8px !important;
|
| 142 |
+
}
|
| 143 |
+
.chatbot .assistant-message {
|
| 144 |
+
background-color: #ebf5f7 !important;
|
| 145 |
+
border-radius: 8px !important;
|
| 146 |
+
}
|
| 147 |
+
#chatbot {
|
| 148 |
+
height: 400px !important;
|
| 149 |
+
overflow-y: auto !important;
|
| 150 |
}
|
| 151 |
.footer {
|
| 152 |
+
display: none;
|
|
|
|
|
|
|
|
|
|
|
|
|
| 153 |
}
|
| 154 |
+
#component-0 {
|
| 155 |
+
max-width: 100%;
|
| 156 |
+
}
|
| 157 |
+
|
| 158 |
"""
|
| 159 |
|
| 160 |
with gr.Blocks(css=css) as demo:
|
|
|
|
| 162 |
gr.HTML("""
|
| 163 |
<div class="app-header">
|
| 164 |
<h1 class="app-title">
|
| 165 |
+
<span class="shield">🛡️</span>
|
| 166 |
<span class="safe">Safe</span>
|
| 167 |
<span class="lm">Playground</span>
|
| 168 |
</h1>
|
|
|
|
| 227 |
with gr.Row():
|
| 228 |
clear_button = gr.Button("Clear Chat")
|
| 229 |
|
| 230 |
+
# No footer - removed
|
| 231 |
+
gr.HTML('<div style="height: 20px;"></div>')
|
|
|
|
|
|
|
|
|
|
|
|
|
| 232 |
|
| 233 |
# Fix 1: Correct event handling for the chatbot interface
|
| 234 |
def user(user_message, history):
|