Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -113,29 +113,43 @@ def clear_memory():
|
|
| 113 |
os.remove(MEMORY_FILE)
|
| 114 |
return [], "π§Ή Chat memory cleared! Start fresh."
|
| 115 |
|
| 116 |
-
# π Custom CSS for
|
| 117 |
custom_css = """
|
| 118 |
-
.
|
| 119 |
-
|
| 120 |
-
|
| 121 |
-
.
|
| 122 |
-
.
|
| 123 |
-
.
|
| 124 |
-
.
|
| 125 |
-
.
|
| 126 |
-
.
|
| 127 |
-
.
|
| 128 |
-
.
|
| 129 |
-
.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 130 |
"""
|
| 131 |
|
| 132 |
-
# π¨ Gradio Interface with CSS
|
| 133 |
-
with gr.Blocks(theme=gr.themes.Soft(primary_hue="
|
| 134 |
-
gr.Markdown("# π **EduAI β Your
|
| 135 |
|
| 136 |
with gr.Row():
|
| 137 |
-
# Sidebar
|
| 138 |
-
with gr.Column(scale=1, min_width=
|
| 139 |
gr.Markdown("### π§ **Main Menu**", elem_classes="menu-title")
|
| 140 |
|
| 141 |
with gr.Accordion("π Subject Tutor", open=False):
|
|
@@ -168,7 +182,7 @@ with gr.Blocks(theme=gr.themes.Soft(primary_hue="violet"), css=custom_css) as if
|
|
| 168 |
Helps learners understand **Science, ICT, English, and more** in a simple, friendly way! π¬
|
| 169 |
""", elem_classes="about-text")
|
| 170 |
|
| 171 |
-
# Main Chat Area
|
| 172 |
with gr.Column(scale=4, elem_classes="main-chat"):
|
| 173 |
context_display = gr.Markdown(
|
| 174 |
"π **You are in General Mode.** Ask EduAI anything about your studies!",
|
|
@@ -177,14 +191,14 @@ with gr.Blocks(theme=gr.themes.Soft(primary_hue="violet"), css=custom_css) as if
|
|
| 177 |
|
| 178 |
chatbot = gr.Chatbot(
|
| 179 |
label="EduAI Chat",
|
| 180 |
-
height=
|
| 181 |
render_markdown=True,
|
| 182 |
-
type="messages",
|
| 183 |
latex_delimiters=[{"left": "$$", "right": "$$", "display": True}, {"left": "\\[", "right": "\\]", "display": True}]
|
| 184 |
)
|
| 185 |
|
| 186 |
with gr.Row():
|
| 187 |
-
msg = gr.Textbox(label="Ask EduAI:", placeholder="
|
| 188 |
file_input = gr.File(label="π Upload a study file", file_types=[".pdf", ".docx", ".png", ".jpg"], elem_classes="file-upload")
|
| 189 |
send = gr.Button("Send βοΈ", elem_classes="btn-send")
|
| 190 |
|
|
|
|
| 113 |
os.remove(MEMORY_FILE)
|
| 114 |
return [], "π§Ή Chat memory cleared! Start fresh."
|
| 115 |
|
| 116 |
+
# π Custom CSS for elegant, modern look (enhanced for sophistication)
|
| 117 |
custom_css = """
|
| 118 |
+
@import url('https://fonts.googleapis.com/css2?family=Inter:wght@300;400;500;600;700&display=swap');
|
| 119 |
+
|
| 120 |
+
body { font-family: 'Inter', sans-serif; background: linear-gradient(135deg, #f8fafc, #e2e8f0); color: #334155; }
|
| 121 |
+
.header-title { font-size: 32px; text-align: center; margin-bottom: 20px; font-weight: 700; color: #0f172a; letter-spacing: -0.5px; }
|
| 122 |
+
.sidebar { background: rgba(255, 255, 255, 0.95); backdrop-filter: blur(10px); padding: 20px; border-radius: 16px; box-shadow: 0 4px 12px rgba(0,0,0,0.1); border: 1px solid #e2e8f0; }
|
| 123 |
+
.menu-title { font-size: 20px; font-weight: 600; margin-bottom: 15px; color: #0f172a; }
|
| 124 |
+
.accordion { border-radius: 12px; margin-bottom: 10px; }
|
| 125 |
+
.accordion-header { background: #f1f5f9; border-radius: 12px; padding: 12px; font-weight: 500; transition: all 0.3s ease; }
|
| 126 |
+
.accordion-header:hover { background: #e2e8f0; }
|
| 127 |
+
.main-chat { padding: 20px; background: transparent; }
|
| 128 |
+
.context-box { background: rgba(255, 255, 255, 0.9); backdrop-filter: blur(10px); padding: 15px; border-radius: 12px; box-shadow: 0 2px 8px rgba(0,0,0,0.1); margin-bottom: 15px; border: 1px solid #e2e8f0; font-size: 14px; }
|
| 129 |
+
.chatbox { border-radius: 12px; box-shadow: 0 2px 8px rgba(0,0,0,0.1); background: #ffffff; }
|
| 130 |
+
.chatbox .message.user { background: linear-gradient(135deg, #14b8a6, #06b6d4); color: white; border-radius: 16px; padding: 12px 16px; margin: 8px 0; box-shadow: 0 2px 6px rgba(20, 184, 166, 0.3); animation: fadeIn 0.5s ease-in; }
|
| 131 |
+
.chatbox .message.bot { background: #f8fafc; color: #334155; border-radius: 16px; padding: 12px 16px; margin: 8px 0; box-shadow: 0 1px 4px rgba(0,0,0,0.05); border: 1px solid #e2e8f0; animation: fadeIn 0.5s ease-in; }
|
| 132 |
+
@keyframes fadeIn { from { opacity: 0; transform: translateY(10px); } to { opacity: 1; transform: translateY(0); } }
|
| 133 |
+
.chat-input { border-radius: 20px; padding: 12px 16px; width: 100%; border: 1px solid #d1d5db; transition: all 0.3s ease; }
|
| 134 |
+
.chat-input:focus { outline: none; border-color: #14b8a6; box-shadow: 0 0 0 2px rgba(20, 184, 166, 0.2); }
|
| 135 |
+
.btn-send { background: linear-gradient(135deg, #14b8a6, #06b6d4); color: white; border-radius: 20px; padding: 12px 24px; border: none; font-weight: 500; transition: all 0.3s ease; box-shadow: 0 2px 8px rgba(20, 184, 166, 0.3); }
|
| 136 |
+
.btn-send:hover { transform: scale(1.05); box-shadow: 0 4px 12px rgba(20, 184, 166, 0.4); }
|
| 137 |
+
.btn-clear { background: linear-gradient(135deg, #ef4444, #dc2626); color: white; border-radius: 12px; padding: 8px 16px; border: none; font-weight: 500; transition: all 0.3s ease; }
|
| 138 |
+
.btn-clear:hover { transform: scale(1.05); box-shadow: 0 4px 12px rgba(239, 68, 68, 0.4); }
|
| 139 |
+
.file-upload { border: 2px dashed #14b8a6; border-radius: 12px; padding: 15px; text-align: center; background: #f8fafc; transition: all 0.3s ease; }
|
| 140 |
+
.file-upload:hover { background: #e2e8f0; border-color: #06b6d4; }
|
| 141 |
+
.about-text { font-size: 14px; color: #64748b; line-height: 1.5; }
|
| 142 |
+
.radio { margin: 10px 0; }
|
| 143 |
+
.radio label { font-weight: 400; }
|
| 144 |
"""
|
| 145 |
|
| 146 |
+
# π¨ Gradio Interface with enhanced CSS and layout
|
| 147 |
+
with gr.Blocks(theme=gr.themes.Soft(primary_hue="teal"), css=custom_css) as iface:
|
| 148 |
+
gr.Markdown("# π **EduAI β Your Elegant Study Companion**", elem_classes="header-title")
|
| 149 |
|
| 150 |
with gr.Row():
|
| 151 |
+
# Sidebar (refined for elegance)
|
| 152 |
+
with gr.Column(scale=1, min_width=280, elem_classes="sidebar"):
|
| 153 |
gr.Markdown("### π§ **Main Menu**", elem_classes="menu-title")
|
| 154 |
|
| 155 |
with gr.Accordion("π Subject Tutor", open=False):
|
|
|
|
| 182 |
Helps learners understand **Science, ICT, English, and more** in a simple, friendly way! π¬
|
| 183 |
""", elem_classes="about-text")
|
| 184 |
|
| 185 |
+
# Main Chat Area (enhanced for modern look)
|
| 186 |
with gr.Column(scale=4, elem_classes="main-chat"):
|
| 187 |
context_display = gr.Markdown(
|
| 188 |
"π **You are in General Mode.** Ask EduAI anything about your studies!",
|
|
|
|
| 191 |
|
| 192 |
chatbot = gr.Chatbot(
|
| 193 |
label="EduAI Chat",
|
| 194 |
+
height=550,
|
| 195 |
render_markdown=True,
|
| 196 |
+
type="messages",
|
| 197 |
latex_delimiters=[{"left": "$$", "right": "$$", "display": True}, {"left": "\\[", "right": "\\]", "display": True}]
|
| 198 |
)
|
| 199 |
|
| 200 |
with gr.Row():
|
| 201 |
+
msg = gr.Textbox(label="Ask EduAI:", placeholder="Share your study query...", elem_classes="chat-input")
|
| 202 |
file_input = gr.File(label="π Upload a study file", file_types=[".pdf", ".docx", ".png", ".jpg"], elem_classes="file-upload")
|
| 203 |
send = gr.Button("Send βοΈ", elem_classes="btn-send")
|
| 204 |
|