Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,3 +1,10 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
import os
|
| 2 |
import gradio as gr
|
| 3 |
from openai import OpenAI
|
|
@@ -21,14 +28,13 @@ client = OpenAI(
|
|
| 21 |
)
|
| 22 |
|
| 23 |
# --- 3. THEME CUSTOMIZATION ---
|
| 24 |
-
# Using a
|
| 25 |
cheerful_theme = gr.themes.Soft(
|
| 26 |
-
primary_hue=gr.themes.colors.
|
| 27 |
-
secondary_hue=gr.themes.colors.
|
| 28 |
font=gr.themes.GoogleFont("Poppins")
|
| 29 |
)
|
| 30 |
|
| 31 |
-
|
| 32 |
# --- 4. Prepare Context for the Chatbot ---
|
| 33 |
summary = (
|
| 34 |
"I am a 3 years experienced Backend Software Engineer with a strong focus on building scalable, well-architected systems "
|
|
@@ -40,11 +46,9 @@ summary = (
|
|
| 40 |
"using gRPC, Redis, and message queues (e.g., RabbitMQ). I'm passionate about automation, developer "
|
| 41 |
"tools (e.g., n8n, Copilot, Cursor), and mentoring through technical content. As an ALX alumna, I have a "
|
| 42 |
"hands-on mindset and a continuous learning attitude. I am also the author of a technical blog on "
|
| 43 |
-
"software engineering and AI systems: shazaali.substack.com."
|
| 44 |
"I worked on projects like: Mediconsult, E-commerce, and more. So proud of RAG chatbot I built for suplyd.app"
|
| 45 |
-
|
| 46 |
)
|
| 47 |
-
|
| 48 |
linkedin_text = "My LinkedIn Profile: https://www.linkedin.com/in/shazaali/\n\n"
|
| 49 |
try:
|
| 50 |
reader = PdfReader("linkedin.pdf")
|
|
@@ -61,7 +65,7 @@ system_prompt = (
|
|
| 61 |
f"You are given a summary of my background and my LinkedIn profile to use for answering questions. "
|
| 62 |
f"Be professional, friendly, and engaging, as if you are talking to a potential client or future employer. "
|
| 63 |
f"If you don't know the answer based on the provided context, it's better to say so than to invent information. "
|
| 64 |
-
f"Always stay in character as {name}
|
| 65 |
f"\n\n## My Summary:\n{summary}\n\n## My LinkedIn Profile Text:\n{linkedin_text}\n\n## My CV:\n{cv_link}"
|
| 66 |
)
|
| 67 |
|
|
@@ -81,7 +85,7 @@ def chat(message, history):
|
|
| 81 |
try:
|
| 82 |
response = client.chat.completions.create(
|
| 83 |
model="openai/gpt-3.5-turbo",
|
| 84 |
-
max_tokens=
|
| 85 |
messages=messages,
|
| 86 |
temperature=0.7
|
| 87 |
)
|
|
@@ -90,158 +94,94 @@ def chat(message, history):
|
|
| 90 |
print(f"An error occurred: {e}")
|
| 91 |
return "Sorry, I encountered an error while processing your request. Please try again."
|
| 92 |
|
| 93 |
-
# --- 6. Create and Launch the Gradio App
|
| 94 |
|
| 95 |
-
#
|
| 96 |
-
with gr.Blocks(
|
| 97 |
-
|
| 98 |
-
|
| 99 |
-
|
|
|
|
|
|
|
| 100 |
background: linear-gradient(135deg, #f5f7fa 0%, #e4e8ff 100%) !important;
|
| 101 |
}
|
| 102 |
|
| 103 |
-
/*
|
| 104 |
-
.message-wrap { font-size: 20px !important; }
|
| 105 |
-
.user-message { background-color: #f0e6ff !important; border-radius: 18px !important; }
|
| 106 |
-
.bot-message { background-color: #f9f5ff !important; border-radius: 18px !important; }
|
| 107 |
-
|
| 108 |
-
/* Add a subtle bounce animation to messages */
|
| 109 |
-
@keyframes bounce {
|
| 110 |
-
0% { transform: translateY(0); }
|
| 111 |
-
20% { transform: translateY(-10px); }
|
| 112 |
-
40% { transform: translateY(0); }
|
| 113 |
-
}
|
| 114 |
-
.message:last-child {
|
| 115 |
-
animation: bounce 1s ease;
|
| 116 |
-
}
|
| 117 |
-
|
| 118 |
-
/* Make the title and description bigger and more colorful */
|
| 119 |
h1 {
|
| 120 |
-
font-size:
|
| 121 |
font-weight: 700 !important;
|
| 122 |
-
margin-bottom: 16px !important;
|
| 123 |
background: linear-gradient(90deg, #9333ea, #e879f9);
|
| 124 |
-webkit-background-clip: text;
|
| 125 |
-webkit-text-fill-color: transparent;
|
| 126 |
text-shadow: 0px 2px 4px rgba(0,0,0,0.1);
|
| 127 |
-
|
| 128 |
-
|
| 129 |
-
|
| 130 |
-
/* Make buttons bigger and more cheerful */
|
| 131 |
-
button {
|
| 132 |
-
font-size: 18px !important;
|
| 133 |
-
padding: 12px 20px !important;
|
| 134 |
-
border-radius: 12px !important;
|
| 135 |
-
transition: all 0.3s ease !important;
|
| 136 |
-
}
|
| 137 |
-
button:hover {
|
| 138 |
-
transform: translateY(-3px) !important;
|
| 139 |
-
box-shadow: 0 10px 15px -3px rgba(0, 0, 0, 0.1) !important;
|
| 140 |
-
}
|
| 141 |
-
|
| 142 |
-
/* Make input box MUCH bigger and friendlier */
|
| 143 |
-
textarea, .chat-input-row textarea {
|
| 144 |
-
font-size: 24px !important;
|
| 145 |
-
line-height: 1.5 !important;
|
| 146 |
-
padding: 16px !important;
|
| 147 |
-
min-height: 100px !important;
|
| 148 |
-
border-radius: 16px !important;
|
| 149 |
-
border: 2px solid #d8b4fe !important;
|
| 150 |
-
box-shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.1) !important;
|
| 151 |
-
transition: all 0.3s ease !important;
|
| 152 |
-
}
|
| 153 |
-
textarea:focus {
|
| 154 |
-
border-color: #9333ea !important;
|
| 155 |
-
box-shadow: 0 0 0 3px rgba(147, 51, 234, 0.3) !important;
|
| 156 |
}
|
| 157 |
|
| 158 |
-
/*
|
| 159 |
-
.
|
| 160 |
padding: 20px !important;
|
| 161 |
-
|
|
|
|
|
|
|
| 162 |
}
|
| 163 |
-
|
| 164 |
-
|
|
|
|
|
|
|
|
|
|
| 165 |
.examples-panel .gr-button {
|
| 166 |
-
font-size:
|
| 167 |
background-color: #f0e6ff !important;
|
| 168 |
border: 2px solid #d8b4fe !important;
|
| 169 |
-
|
| 170 |
-
padding: 20px 24px !important;
|
| 171 |
transition: all 0.3s ease !important;
|
| 172 |
border-radius: 16px !important;
|
| 173 |
font-weight: 600 !important;
|
| 174 |
-
color: #7e22ce !important;
|
| 175 |
box-shadow: 0 4px 6px rgba(0, 0, 0, 0.05) !important;
|
| 176 |
-
display: block !important;
|
| 177 |
-
width: 100% !important;
|
| 178 |
-
text-align: left !important;
|
| 179 |
}
|
| 180 |
.examples-panel .gr-button:hover {
|
| 181 |
background-color: #e9d5ff !important;
|
| 182 |
transform: scale(1.03) !important;
|
| 183 |
box-shadow: 0 8px 15px rgba(0, 0, 0, 0.1) !important;
|
| 184 |
-
border-color: #a855f7 !important;
|
| 185 |
-
}
|
| 186 |
-
|
| 187 |
-
/* Make the examples section more prominent */
|
| 188 |
-
.examples-panel {
|
| 189 |
-
padding: 20px !important;
|
| 190 |
-
background-color: rgba(255, 255, 255, 0.8) !important;
|
| 191 |
-
border-radius: 20px !important;
|
| 192 |
-
margin-top: 24px !important;
|
| 193 |
-
box-shadow: 0 4px 15px rgba(0, 0, 0, 0.05) !important;
|
| 194 |
-
border: 1px solid #f3e8ff !important;
|
| 195 |
}
|
| 196 |
|
| 197 |
-
/*
|
| 198 |
-
.
|
| 199 |
-
|
| 200 |
-
|
| 201 |
-
|
| 202 |
-
text-align: center !important;
|
| 203 |
-
font-weight: 700 !important;
|
| 204 |
-
}
|
| 205 |
|
| 206 |
-
/*
|
| 207 |
-
|
| 208 |
-
|
| 209 |
-
|
| 210 |
-
.examples-panel .prose h2::after {
|
| 211 |
-
content: " ✨";
|
| 212 |
-
}
|
| 213 |
-
|
| 214 |
-
/* Add more space between chat messages */
|
| 215 |
-
.message {
|
| 216 |
padding: 16px !important;
|
| 217 |
-
|
| 218 |
-
|
|
|
|
| 219 |
}
|
| 220 |
-
|
| 221 |
-
|
| 222 |
-
|
| 223 |
-
|
| 224 |
-
/*
|
| 225 |
-
.gradio-container { padding: 20px !important; }
|
| 226 |
-
|
| 227 |
-
/* Make the submit button more prominent and cheerful */
|
| 228 |
-
.submit-btn {
|
| 229 |
background: linear-gradient(90deg, #9333ea, #d946ef) !important;
|
| 230 |
color: white !important;
|
| 231 |
font-weight: bold !important;
|
| 232 |
-
|
| 233 |
-
font-size: 22px !important;
|
| 234 |
-
padding: 15px 25px !important;
|
| 235 |
}
|
| 236 |
-
.
|
| 237 |
background: linear-gradient(90deg, #7e22ce, #c026d3) !important;
|
| 238 |
transform: translateY(-2px) !important;
|
| 239 |
}
|
| 240 |
""") as interface:
|
| 241 |
gr.ChatInterface(
|
| 242 |
fn=chat,
|
| 243 |
-
title
|
| 244 |
-
|
|
|
|
|
|
|
| 245 |
examples=[
|
| 246 |
["What are your main technical skills?"],
|
| 247 |
["Tell me about your experience with AI and RAG chatbots."],
|
|
@@ -251,4 +191,4 @@ with gr.Blocks(theme=cheerful_theme, css="""
|
|
| 251 |
|
| 252 |
# Now, launch the interface defined within the Blocks context.
|
| 253 |
if __name__ == "__main__":
|
| 254 |
-
interface.launch()
|
|
|
|
| 1 |
+
"""
|
| 2 |
+
ShazaTwin - AI Assistant
|
| 3 |
+
|
| 4 |
+
A Gradio-based chatbot that acts as a digital twin for Shaza Aly,
|
| 5 |
+
answering questions about skills, experience, and background.
|
| 6 |
+
"""
|
| 7 |
+
|
| 8 |
import os
|
| 9 |
import gradio as gr
|
| 10 |
from openai import OpenAI
|
|
|
|
| 28 |
)
|
| 29 |
|
| 30 |
# --- 3. THEME CUSTOMIZATION ---
|
| 31 |
+
# Using a cheerful theme with vibrant colors
|
| 32 |
cheerful_theme = gr.themes.Soft(
|
| 33 |
+
primary_hue=gr.themes.colors.purple,
|
| 34 |
+
secondary_hue=gr.themes.colors.pink,
|
| 35 |
font=gr.themes.GoogleFont("Poppins")
|
| 36 |
)
|
| 37 |
|
|
|
|
| 38 |
# --- 4. Prepare Context for the Chatbot ---
|
| 39 |
summary = (
|
| 40 |
"I am a 3 years experienced Backend Software Engineer with a strong focus on building scalable, well-architected systems "
|
|
|
|
| 46 |
"using gRPC, Redis, and message queues (e.g., RabbitMQ). I'm passionate about automation, developer "
|
| 47 |
"tools (e.g., n8n, Copilot, Cursor), and mentoring through technical content. As an ALX alumna, I have a "
|
| 48 |
"hands-on mindset and a continuous learning attitude. I am also the author of a technical blog on "
|
| 49 |
+
"software engineering and AI systems: shazaali.substack.com. "
|
| 50 |
"I worked on projects like: Mediconsult, E-commerce, and more. So proud of RAG chatbot I built for suplyd.app"
|
|
|
|
| 51 |
)
|
|
|
|
| 52 |
linkedin_text = "My LinkedIn Profile: https://www.linkedin.com/in/shazaali/\n\n"
|
| 53 |
try:
|
| 54 |
reader = PdfReader("linkedin.pdf")
|
|
|
|
| 65 |
f"You are given a summary of my background and my LinkedIn profile to use for answering questions. "
|
| 66 |
f"Be professional, friendly, and engaging, as if you are talking to a potential client or future employer. "
|
| 67 |
f"If you don't know the answer based on the provided context, it's better to say so than to invent information. "
|
| 68 |
+
f"Always stay in character as {name}. Answer in the same language as the user's question without disclosing any private information."
|
| 69 |
f"\n\n## My Summary:\n{summary}\n\n## My LinkedIn Profile Text:\n{linkedin_text}\n\n## My CV:\n{cv_link}"
|
| 70 |
)
|
| 71 |
|
|
|
|
| 85 |
try:
|
| 86 |
response = client.chat.completions.create(
|
| 87 |
model="openai/gpt-3.5-turbo",
|
| 88 |
+
max_tokens=300,
|
| 89 |
messages=messages,
|
| 90 |
temperature=0.7
|
| 91 |
)
|
|
|
|
| 94 |
print(f"An error occurred: {e}")
|
| 95 |
return "Sorry, I encountered an error while processing your request. Please try again."
|
| 96 |
|
| 97 |
+
# --- 6. Create and Launch the Gradio App with Your Custom CSS ---
|
| 98 |
|
| 99 |
+
# The magic happens here: fill_height=True and your refined CSS.
|
| 100 |
+
with gr.Blocks(
|
| 101 |
+
theme=cheerful_theme,
|
| 102 |
+
fill_height=True, # This is crucial for making the app fill the HF Space vertically
|
| 103 |
+
css="""
|
| 104 |
+
/* --- Global Layout & Background --- */
|
| 105 |
+
#root, .gradio-container {
|
| 106 |
background: linear-gradient(135deg, #f5f7fa 0%, #e4e8ff 100%) !important;
|
| 107 |
}
|
| 108 |
|
| 109 |
+
/* --- Titles & Headers --- */
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 110 |
h1 {
|
| 111 |
+
font-size: 42px !important;
|
| 112 |
font-weight: 700 !important;
|
|
|
|
| 113 |
background: linear-gradient(90deg, #9333ea, #e879f9);
|
| 114 |
-webkit-background-clip: text;
|
| 115 |
-webkit-text-fill-color: transparent;
|
| 116 |
text-shadow: 0px 2px 4px rgba(0,0,0,0.1);
|
| 117 |
+
text-align: center !important;
|
| 118 |
+
padding-top: 20px !important;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 119 |
}
|
| 120 |
|
| 121 |
+
/* --- Example Prompts Section --- */
|
| 122 |
+
.examples-panel {
|
| 123 |
padding: 20px !important;
|
| 124 |
+
background-color: rgba(255, 255, 255, 0.7) !important;
|
| 125 |
+
border-radius: 20px !important;
|
| 126 |
+
box-shadow: 0 4px 15px rgba(0, 0, 0, 0.05) !important;
|
| 127 |
}
|
| 128 |
+
.examples-panel .prose h2 {
|
| 129 |
+
font-size: 28px !important; color: #7e22ce !important; text-align: center !important; font-weight: 700 !important;
|
| 130 |
+
}
|
| 131 |
+
.examples-panel .prose h2::before { content: "✨ "; }
|
| 132 |
+
.examples-panel .prose h2::after { content: " ✨"; }
|
| 133 |
.examples-panel .gr-button {
|
| 134 |
+
font-size: 18px !important;
|
| 135 |
background-color: #f0e6ff !important;
|
| 136 |
border: 2px solid #d8b4fe !important;
|
| 137 |
+
color: #7e22ce !important;
|
|
|
|
| 138 |
transition: all 0.3s ease !important;
|
| 139 |
border-radius: 16px !important;
|
| 140 |
font-weight: 600 !important;
|
|
|
|
| 141 |
box-shadow: 0 4px 6px rgba(0, 0, 0, 0.05) !important;
|
|
|
|
|
|
|
|
|
|
| 142 |
}
|
| 143 |
.examples-panel .gr-button:hover {
|
| 144 |
background-color: #e9d5ff !important;
|
| 145 |
transform: scale(1.03) !important;
|
| 146 |
box-shadow: 0 8px 15px rgba(0, 0, 0, 0.1) !important;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 147 |
}
|
| 148 |
|
| 149 |
+
/* --- Chat Area & Messages --- */
|
| 150 |
+
.message-wrap { font-size: 18px !important; } /* Base message font size */
|
| 151 |
+
.message { margin-bottom: 12px !important; } /* Space between messages */
|
| 152 |
+
.user > .message { background-color: #f0e6ff !important; border-radius: 18px !important; }
|
| 153 |
+
.bot > .message { background-color: #f9f5ff !important; border-radius: 18px !important; }
|
|
|
|
|
|
|
|
|
|
| 154 |
|
| 155 |
+
/* --- Input Textbox & Submit Button --- */
|
| 156 |
+
textarea {
|
| 157 |
+
font-size: 20px !important;
|
| 158 |
+
line-height: 1.5 !important;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 159 |
padding: 16px !important;
|
| 160 |
+
border-radius: 16px !important;
|
| 161 |
+
border: 2px solid #d8b4fe !important;
|
| 162 |
+
box-shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.1) !important;
|
| 163 |
}
|
| 164 |
+
textarea:focus {
|
| 165 |
+
border-color: #9333ea !important;
|
| 166 |
+
box-shadow: 0 0 0 3px rgba(147, 51, 234, 0.3) !important;
|
| 167 |
+
}
|
| 168 |
+
.send-button { /* More specific selector for the submit button */
|
|
|
|
|
|
|
|
|
|
|
|
|
| 169 |
background: linear-gradient(90deg, #9333ea, #d946ef) !important;
|
| 170 |
color: white !important;
|
| 171 |
font-weight: bold !important;
|
| 172 |
+
font-size: 20px !important;
|
|
|
|
|
|
|
| 173 |
}
|
| 174 |
+
.send-button:hover {
|
| 175 |
background: linear-gradient(90deg, #7e22ce, #c026d3) !important;
|
| 176 |
transform: translateY(-2px) !important;
|
| 177 |
}
|
| 178 |
""") as interface:
|
| 179 |
gr.ChatInterface(
|
| 180 |
fn=chat,
|
| 181 |
+
# We don't need the title and description here because your CSS h1 is now the main title.
|
| 182 |
+
chatbot=gr.Chatbot(
|
| 183 |
+
label="Talk to me: Shaza Aly",
|
| 184 |
+
),
|
| 185 |
examples=[
|
| 186 |
["What are your main technical skills?"],
|
| 187 |
["Tell me about your experience with AI and RAG chatbots."],
|
|
|
|
| 191 |
|
| 192 |
# Now, launch the interface defined within the Blocks context.
|
| 193 |
if __name__ == "__main__":
|
| 194 |
+
interface.launch()
|