Update app.py
Browse files
app.py
CHANGED
|
@@ -6,9 +6,8 @@ from groq import Groq
|
|
| 6 |
api_key = os.environ.get("GROQ_API_KEY")
|
| 7 |
client = Groq(api_key=api_key)
|
| 8 |
|
| 9 |
-
# 2. UI Styling
|
| 10 |
custom_css = """
|
| 11 |
-
/* General Container */
|
| 12 |
.gradio-container {
|
| 13 |
max-width: 100% !important;
|
| 14 |
height: 95vh !important;
|
|
@@ -16,7 +15,6 @@ custom_css = """
|
|
| 16 |
padding: 10px 20px !important;
|
| 17 |
}
|
| 18 |
|
| 19 |
-
/* Chatbot Window Height & Border */
|
| 20 |
#chatbot-window {
|
| 21 |
height: 67vh !important;
|
| 22 |
border-radius: 12px;
|
|
@@ -24,41 +22,26 @@ custom_css = """
|
|
| 24 |
background: white;
|
| 25 |
}
|
| 26 |
|
| 27 |
-
/*
|
| 28 |
-
|
| 29 |
-
|
| 30 |
-
|
| 31 |
-
background-color: #8A2BE2 !important; /* BlueViolet Purple */
|
| 32 |
-
border-color: #8A2BE2 !important;
|
| 33 |
-
color: white !important;
|
| 34 |
-
}
|
| 35 |
-
|
| 36 |
-
/* Slider Track/Handle (Temperature) */
|
| 37 |
-
input[type="range"] {
|
| 38 |
-
accent-color: #8A2BE2 !important;
|
| 39 |
-
}
|
| 40 |
-
|
| 41 |
-
/* User Message Bubble (Purple) */
|
| 42 |
-
.user.message {
|
| 43 |
-
background-color: #8A2BE2 !important;
|
| 44 |
-
color: white !important;
|
| 45 |
-
border-radius: 15px 15px 2px 15px !important;
|
| 46 |
}
|
| 47 |
|
| 48 |
-
|
| 49 |
-
|
| 50 |
-
|
| 51 |
-
|
| 52 |
-
|
| 53 |
}
|
| 54 |
|
| 55 |
-
/* --- PURPLE THEME END --- */
|
| 56 |
-
|
| 57 |
-
/* Settings Gear Button */
|
| 58 |
#settings-btn {
|
| 59 |
width: 44px !important;
|
| 60 |
height: 44px !important;
|
| 61 |
min-width: 44px !important;
|
|
|
|
|
|
|
|
|
|
| 62 |
border-radius: 8px !important;
|
| 63 |
background: #f0f0f0 !important;
|
| 64 |
border: 1px solid #ddd !important;
|
|
@@ -77,10 +60,10 @@ input[type="range"] {
|
|
| 77 |
min-width: 300px !important;
|
| 78 |
}
|
| 79 |
|
| 80 |
-
|
| 81 |
-
|
| 82 |
-
|
| 83 |
-
|
| 84 |
"""
|
| 85 |
|
| 86 |
# 3. Secure Chat Logic
|
|
@@ -127,12 +110,14 @@ with gr.Blocks() as demo:
|
|
| 127 |
with gr.Row():
|
| 128 |
# Main Chat Area
|
| 129 |
with gr.Column(scale=4) as chat_col:
|
|
|
|
| 130 |
chatbot = gr.Chatbot(elem_id="chatbot-window")
|
| 131 |
with gr.Row():
|
| 132 |
msg_input = gr.Textbox(
|
| 133 |
placeholder="Ask me anything...",
|
| 134 |
container=False,
|
| 135 |
-
scale=9
|
|
|
|
| 136 |
)
|
| 137 |
submit_btn = gr.Button("Send", variant="primary", scale=1, min_width=80)
|
| 138 |
|
|
@@ -150,31 +135,36 @@ with gr.Blocks() as demo:
|
|
| 150 |
sys_msg = gr.Textbox(
|
| 151 |
value="You are a professional assistant.",
|
| 152 |
label="System Prompt",
|
| 153 |
-
lines=1
|
|
|
|
| 154 |
)
|
| 155 |
|
| 156 |
-
# Support/Developer Links
|
| 157 |
gr.HTML("""
|
| 158 |
<div style="text-align: center; margin-top: 20px; padding-top: 15px; border-top: 1px solid #ddd;">
|
| 159 |
<p style="font-size: 0.85em; color: #555; margin-bottom: 12px;">Connect with the developer</p>
|
| 160 |
<div style="display: flex; justify-content: center; gap: 15px; align-items: center;">
|
| 161 |
-
<a href="https://www.linkedin.com/in/hassan-naseer-web-developer" target="_blank">
|
| 162 |
-
<a href="https://wa.me/923099702809" target="_blank">
|
|
|
|
| 163 |
</div>
|
| 164 |
</div>
|
| 165 |
""")
|
| 166 |
|
| 167 |
-
#
|
| 168 |
def toggle_sidebar(current_state):
|
| 169 |
new_state = not current_state
|
| 170 |
return gr.update(visible=new_state), new_state
|
| 171 |
|
| 172 |
settings_btn.click(toggle_sidebar, [sidebar_state], [sidebar_col, sidebar_state])
|
| 173 |
|
| 174 |
-
#
|
| 175 |
-
dark_btn.click(
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 176 |
|
| 177 |
-
# --- Chat Logic ---
|
| 178 |
def user_turn(msg, hist):
|
| 179 |
if not msg: return "", hist
|
| 180 |
hist.append({"role": "user", "content": msg})
|
|
@@ -196,4 +186,5 @@ with gr.Blocks() as demo:
|
|
| 196 |
)
|
| 197 |
|
| 198 |
if __name__ == "__main__":
|
|
|
|
| 199 |
demo.launch(css=custom_css)
|
|
|
|
| 6 |
api_key = os.environ.get("GROQ_API_KEY")
|
| 7 |
client = Groq(api_key=api_key)
|
| 8 |
|
| 9 |
+
# 2. UI Styling
|
| 10 |
custom_css = """
|
|
|
|
| 11 |
.gradio-container {
|
| 12 |
max-width: 100% !important;
|
| 13 |
height: 95vh !important;
|
|
|
|
| 15 |
padding: 10px 20px !important;
|
| 16 |
}
|
| 17 |
|
|
|
|
| 18 |
#chatbot-window {
|
| 19 |
height: 67vh !important;
|
| 20 |
border-radius: 12px;
|
|
|
|
| 22 |
background: white;
|
| 23 |
}
|
| 24 |
|
| 25 |
+
/* Dark Mode Overrides */
|
| 26 |
+
.dark #chatbot-window {
|
| 27 |
+
background: #1a1a1a !important;
|
| 28 |
+
border-color: #444 !important;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 29 |
}
|
| 30 |
|
| 31 |
+
#system-prompt-container textarea, .scroll-input textarea {
|
| 32 |
+
height: 45px !important;
|
| 33 |
+
max-height: 45px !important;
|
| 34 |
+
overflow-y: auto !important;
|
| 35 |
+
resize: none !important;
|
| 36 |
}
|
| 37 |
|
|
|
|
|
|
|
|
|
|
| 38 |
#settings-btn {
|
| 39 |
width: 44px !important;
|
| 40 |
height: 44px !important;
|
| 41 |
min-width: 44px !important;
|
| 42 |
+
max-width: 44px !important;
|
| 43 |
+
padding: 0 !important;
|
| 44 |
+
margin: 0 !important;
|
| 45 |
border-radius: 8px !important;
|
| 46 |
background: #f0f0f0 !important;
|
| 47 |
border: 1px solid #ddd !important;
|
|
|
|
| 60 |
min-width: 300px !important;
|
| 61 |
}
|
| 62 |
|
| 63 |
+
.dark .sidebar-panel {
|
| 64 |
+
background-color: #2d2d2d !important;
|
| 65 |
+
border-color: #444 !important;
|
| 66 |
+
}
|
| 67 |
"""
|
| 68 |
|
| 69 |
# 3. Secure Chat Logic
|
|
|
|
| 110 |
with gr.Row():
|
| 111 |
# Main Chat Area
|
| 112 |
with gr.Column(scale=4) as chat_col:
|
| 113 |
+
# Fixed: Removed type="messages" as it's the default in Gradio 6
|
| 114 |
chatbot = gr.Chatbot(elem_id="chatbot-window")
|
| 115 |
with gr.Row():
|
| 116 |
msg_input = gr.Textbox(
|
| 117 |
placeholder="Ask me anything...",
|
| 118 |
container=False,
|
| 119 |
+
scale=9,
|
| 120 |
+
elem_classes="scroll-input"
|
| 121 |
)
|
| 122 |
submit_btn = gr.Button("Send", variant="primary", scale=1, min_width=80)
|
| 123 |
|
|
|
|
| 135 |
sys_msg = gr.Textbox(
|
| 136 |
value="You are a professional assistant.",
|
| 137 |
label="System Prompt",
|
| 138 |
+
lines=1,
|
| 139 |
+
elem_id="system-prompt-container"
|
| 140 |
)
|
| 141 |
|
|
|
|
| 142 |
gr.HTML("""
|
| 143 |
<div style="text-align: center; margin-top: 20px; padding-top: 15px; border-top: 1px solid #ddd;">
|
| 144 |
<p style="font-size: 0.85em; color: #555; margin-bottom: 12px;">Connect with the developer</p>
|
| 145 |
<div style="display: flex; justify-content: center; gap: 15px; align-items: center;">
|
| 146 |
+
<a href="https://www.linkedin.com/in/hassan-naseer-web-developer" target="_blank"><svg width="30" height="30" viewBox="0 0 24 24" fill="#0077b5"><path d="M19 0h-14c-2.761 0-5 2.239-5 5v14c0 2.761 2.239 5 5 5h14c2.762 0 5-2.239 5-5v-14c0-2.761-2.239-5-5-5zm-11 19h-3v-11h3v11zm-1.5-12.268c-.966 0-1.75-.79-1.75-1.764s.784-1.764 1.75-1.764 1.75.79 1.75 1.764-.783 1.764-1.75 1.764zm13.5 12.268h-3v-5.604c0-3.368-4-3.113-4 0v5.604h-3v-11h3v1.765c1.396-2.586 7-2.777 7 2.476v6.759z"/></svg></a>
|
| 147 |
+
<a href="https://wa.me/923099702809" target="_blank"><svg width="55" height="55" viewBox="0 0 24 24" fill="#25D366"><path d="M12.031 6.172c-3.181 0-5.767 2.586-5.768 5.766-.001 1.298.38 2.27 1.019 3.287l-.582 2.128 2.182-.573c.978.58 1.911.928 3.145.929 3.178 0 5.767-2.587 5.768-5.766 0-3.18-2.587-5.771-5.764-5.771zm3.392 8.244c-.144.405-.837.774-1.17.824-.299.045-.677.063-1.092-.069-.252-.08-.575-.187-.988-.365-1.739-.751-2.874-2.502-2.961-2.617-.087-.116-.708-.94-.708-1.793 0-.852.448-1.271.607-1.442.159-.171.348-.214.464-.214.116 0 .232.001.333.006.101.005.237-.038.37.284.144.35.493 1.203.536 1.29.043.087.072.188.014.304-.058.116-.087.188-.174.289-.087.101-.184.225-.261.304-.093.097-.19.202-.082.387.108.185.479.791 1.029 1.282.709.633 1.308.83 1.493.922.185.093.294.077.404-.051.11-.128.471-.548.598-.736.127-.188.253-.159.426-.096.173.063 1.096.516 1.284.609.188.093.312.139.356.215.044.076.044.439-.1.844z"/></svg></a>
|
| 148 |
+
<a href="mailto:hk4960498@gmail.com" target="_blank"><svg width="30" height="30" viewBox="0 0 24 24" fill="#555"><path d="M0 3v18h24v-18h-24zm21.518 2l-9.518 7.713-9.518-7.713h19.036zm-19.518 14v-11.817l10 8.104 10-8.104v11.817h-20z"/></svg></a>
|
| 149 |
</div>
|
| 150 |
</div>
|
| 151 |
""")
|
| 152 |
|
| 153 |
+
# Sidebar Toggle Logic
|
| 154 |
def toggle_sidebar(current_state):
|
| 155 |
new_state = not current_state
|
| 156 |
return gr.update(visible=new_state), new_state
|
| 157 |
|
| 158 |
settings_btn.click(toggle_sidebar, [sidebar_state], [sidebar_col, sidebar_state])
|
| 159 |
|
| 160 |
+
# Dark Mode Logic
|
| 161 |
+
dark_btn.click(
|
| 162 |
+
toggle_dark_mode,
|
| 163 |
+
inputs=[dark_state],
|
| 164 |
+
outputs=[dark_btn, dark_state],
|
| 165 |
+
js=toggle_dark_js
|
| 166 |
+
)
|
| 167 |
|
|
|
|
| 168 |
def user_turn(msg, hist):
|
| 169 |
if not msg: return "", hist
|
| 170 |
hist.append({"role": "user", "content": msg})
|
|
|
|
| 186 |
)
|
| 187 |
|
| 188 |
if __name__ == "__main__":
|
| 189 |
+
# Fixed: Moved css to launch()
|
| 190 |
demo.launch(css=custom_css)
|