Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -23,130 +23,76 @@ def respond(message, history: list[dict[str, str]]):
|
|
| 23 |
response += msg.choices[0].delta.content
|
| 24 |
yield response
|
| 25 |
|
| 26 |
-
|
|
|
|
| 27 |
custom_css = """
|
| 28 |
.gradio-container {
|
|
|
|
| 29 |
font-family: 'Segoe UI', sans-serif;
|
| 30 |
-
background: #f3f3f9;
|
| 31 |
height: 100vh;
|
| 32 |
}
|
| 33 |
|
| 34 |
-
/*
|
| 35 |
-
.
|
| 36 |
-
|
| 37 |
-
|
| 38 |
-
|
| 39 |
-
|
| 40 |
-
padding: 14px 20px;
|
| 41 |
-
border-radius: 12px 12px 0 0;
|
| 42 |
-
text-align: center;
|
| 43 |
-
box-shadow: 0 2px 10px rgba(0,0,0,0.2);
|
| 44 |
-
}
|
| 45 |
-
|
| 46 |
-
/* Chat window */
|
| 47 |
-
.chatbot {
|
| 48 |
-
height: 70vh !important;
|
| 49 |
-
overflow-y: auto !important;
|
| 50 |
-
background: white;
|
| 51 |
-
padding: 20px;
|
| 52 |
-
border-radius: 0 0 12px 12px;
|
| 53 |
-
box-shadow: 0px 4px 20px rgba(0,0,0,0.05);
|
| 54 |
}
|
| 55 |
|
| 56 |
-
/*
|
| 57 |
-
.user-
|
| 58 |
-
background: linear-gradient(135deg, #7E498B, #9b59b6);
|
| 59 |
-
color: white;
|
| 60 |
-
|
| 61 |
-
|
| 62 |
-
|
| 63 |
-
display: inline-block;
|
| 64 |
-
max-width: 75%;
|
| 65 |
-
float: right;
|
| 66 |
-
clear: both;
|
| 67 |
-
font-size: 15px;
|
| 68 |
animation: fadeIn 0.3s ease-in;
|
| 69 |
}
|
| 70 |
|
| 71 |
-
|
| 72 |
-
|
| 73 |
-
|
| 74 |
-
|
| 75 |
-
border-radius: 18px 18px 18px 0;
|
| 76 |
-
|
| 77 |
-
|
| 78 |
-
|
| 79 |
-
float: left;
|
| 80 |
-
clear: both;
|
| 81 |
-
font-size: 15px;
|
| 82 |
-
box-shadow: 0px 2px 6px rgba(0,0,0,0.1);
|
| 83 |
animation: fadeIn 0.3s ease-in;
|
| 84 |
}
|
| 85 |
|
| 86 |
-
/* Input
|
| 87 |
-
|
| 88 |
-
display: flex;
|
| 89 |
-
gap: 10px;
|
| 90 |
-
margin-top: 12px;
|
| 91 |
-
}
|
| 92 |
-
|
| 93 |
-
.input-area textarea {
|
| 94 |
-
flex: 1;
|
| 95 |
border-radius: 25px !important;
|
| 96 |
-
padding: 12px
|
| 97 |
-
font-size: 15px !important;
|
| 98 |
border: 1px solid #ddd !important;
|
| 99 |
-
resize: none !important;
|
| 100 |
outline: none !important;
|
|
|
|
|
|
|
| 101 |
}
|
| 102 |
|
| 103 |
-
|
|
|
|
|
|
|
| 104 |
background: linear-gradient(135deg, #7E498B, #9b59b6) !important;
|
| 105 |
color: white !important;
|
| 106 |
-
|
| 107 |
-
width: 50px;
|
| 108 |
-
height: 50px;
|
| 109 |
-
font-size: 18px;
|
| 110 |
-
font-weight: bold;
|
| 111 |
transition: 0.3s;
|
| 112 |
}
|
| 113 |
|
| 114 |
-
|
| 115 |
background: #632f73 !important;
|
| 116 |
}
|
| 117 |
|
| 118 |
-
/*
|
| 119 |
@keyframes fadeIn {
|
| 120 |
from {opacity: 0; transform: translateY(10px);}
|
| 121 |
to {opacity: 1; transform: translateY(0);}
|
| 122 |
}
|
| 123 |
"""
|
| 124 |
|
| 125 |
-
with gr.Blocks(css=custom_css) as demo:
|
| 126 |
-
|
| 127 |
-
gr.HTML("<div class='top-bar'>💬 Virtual Chatbot</div>")
|
| 128 |
-
chatbot = gr.Chatbot(elem_classes="chatbot", bubble_full_width=False, show_copy_button=False)
|
| 129 |
-
with gr.Row(elem_classes="input-area"):
|
| 130 |
-
msg = gr.Textbox(placeholder="Type your message...", lines=1)
|
| 131 |
-
send_btn = gr.Button("➤")
|
| 132 |
-
|
| 133 |
-
def user_submit(user_message, chat_history):
|
| 134 |
-
return "", chat_history + [(user_message, None)]
|
| 135 |
-
|
| 136 |
-
def bot_response(chat_history):
|
| 137 |
-
user_message = chat_history[-1][0]
|
| 138 |
-
response = ""
|
| 139 |
-
for partial in respond(user_message, [{"role": "user", "content": h[0]} for h in chat_history[:-1]]):
|
| 140 |
-
response = partial
|
| 141 |
-
chat_history[-1] = (chat_history[-1][0], response)
|
| 142 |
-
return chat_history
|
| 143 |
-
|
| 144 |
-
msg.submit(user_submit, [msg, chatbot], [msg, chatbot]).then(
|
| 145 |
-
bot_response, chatbot, chatbot
|
| 146 |
-
)
|
| 147 |
-
send_btn.click(user_submit, [msg, chatbot], [msg, chatbot]).then(
|
| 148 |
-
bot_response, chatbot, chatbot
|
| 149 |
-
)
|
| 150 |
|
| 151 |
if __name__ == "__main__":
|
| 152 |
demo.launch(share=True)
|
|
|
|
| 23 |
response += msg.choices[0].delta.content
|
| 24 |
yield response
|
| 25 |
|
| 26 |
+
|
| 27 |
+
# 💜 Improved Purple + White/Grey Theme CSS
|
| 28 |
custom_css = """
|
| 29 |
.gradio-container {
|
| 30 |
+
background: linear-gradient(to bottom right, #7E498B, #f5f5f5);
|
| 31 |
font-family: 'Segoe UI', sans-serif;
|
|
|
|
| 32 |
height: 100vh;
|
| 33 |
}
|
| 34 |
|
| 35 |
+
/* Chat box styling */
|
| 36 |
+
.svelte-1ipelgc, .svelte-1f354aw {
|
| 37 |
+
border-radius: 16px !important;
|
| 38 |
+
background: white !important;
|
| 39 |
+
padding: 12px !important;
|
| 40 |
+
box-shadow: 0px 4px 20px rgba(0,0,0,0.08) !important;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 41 |
}
|
| 42 |
|
| 43 |
+
/* User bubble */
|
| 44 |
+
.user.svelte-1ipelgc {
|
| 45 |
+
background: linear-gradient(135deg, #7E498B, #9b59b6) !important;
|
| 46 |
+
color: white !important;
|
| 47 |
+
border-radius: 18px 18px 0 18px !important;
|
| 48 |
+
padding: 10px 14px !important;
|
| 49 |
+
max-width: 80% !important;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 50 |
animation: fadeIn 0.3s ease-in;
|
| 51 |
}
|
| 52 |
|
| 53 |
+
/* Bot bubble */
|
| 54 |
+
.bot.svelte-1ipelgc {
|
| 55 |
+
background: #f1f1f1 !important;
|
| 56 |
+
color: #333 !important;
|
| 57 |
+
border-radius: 18px 18px 18px 0 !important;
|
| 58 |
+
padding: 10px 14px !important;
|
| 59 |
+
max-width: 80% !important;
|
| 60 |
+
box-shadow: 0px 2px 6px rgba(0,0,0,0.05) !important;
|
|
|
|
|
|
|
|
|
|
|
|
|
| 61 |
animation: fadeIn 0.3s ease-in;
|
| 62 |
}
|
| 63 |
|
| 64 |
+
/* Input box */
|
| 65 |
+
textarea {
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 66 |
border-radius: 25px !important;
|
| 67 |
+
padding: 12px 16px !important;
|
|
|
|
| 68 |
border: 1px solid #ddd !important;
|
|
|
|
| 69 |
outline: none !important;
|
| 70 |
+
font-size: 15px !important;
|
| 71 |
+
resize: none !important;
|
| 72 |
}
|
| 73 |
|
| 74 |
+
/* Send button */
|
| 75 |
+
button {
|
| 76 |
+
border-radius: 25px !important;
|
| 77 |
background: linear-gradient(135deg, #7E498B, #9b59b6) !important;
|
| 78 |
color: white !important;
|
| 79 |
+
font-weight: bold !important;
|
|
|
|
|
|
|
|
|
|
|
|
|
| 80 |
transition: 0.3s;
|
| 81 |
}
|
| 82 |
|
| 83 |
+
button:hover {
|
| 84 |
background: #632f73 !important;
|
| 85 |
}
|
| 86 |
|
| 87 |
+
/* Animation */
|
| 88 |
@keyframes fadeIn {
|
| 89 |
from {opacity: 0; transform: translateY(10px);}
|
| 90 |
to {opacity: 1; transform: translateY(0);}
|
| 91 |
}
|
| 92 |
"""
|
| 93 |
|
| 94 |
+
with gr.Blocks(theme=gr.themes.Soft(), css=custom_css) as demo:
|
| 95 |
+
gr.ChatInterface(respond, type="messages")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 96 |
|
| 97 |
if __name__ == "__main__":
|
| 98 |
demo.launch(share=True)
|