aimanathar commited on
Commit
04eb9f6
·
verified ·
1 Parent(s): c623aac

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +79 -18
app.py CHANGED
@@ -23,53 +23,112 @@ def respond(message, history: list[dict[str, str]]):
23
  response += msg.choices[0].delta.content
24
  yield response
25
 
26
- # Custom bubble-style CSS
27
  custom_css = """
28
  .gradio-container {
29
- background: #f5f5f5;
30
  font-family: 'Segoe UI', sans-serif;
 
 
31
  }
32
 
 
 
 
 
 
 
 
 
 
 
 
 
 
33
  .chatbot {
34
- height: 600px !important;
35
  overflow-y: auto !important;
36
  background: white;
37
- border-radius: 12px;
38
- padding: 15px;
39
  box-shadow: 0px 4px 20px rgba(0,0,0,0.05);
40
  }
41
 
42
- /* User bubble */
43
  .user-message {
44
- background-color: #7E498B;
45
  color: white;
46
- padding: 10px 14px;
47
  border-radius: 18px 18px 0 18px;
48
  margin: 8px 0;
49
  display: inline-block;
50
- max-width: 80%;
51
  float: right;
52
  clear: both;
 
 
53
  }
54
 
55
- /* Bot bubble */
56
  .bot-message {
57
- background-color: #eeeeee;
58
- color: black;
59
- padding: 10px 14px;
60
  border-radius: 18px 18px 18px 0;
61
  margin: 8px 0;
62
  display: inline-block;
63
- max-width: 80%;
64
  float: left;
65
  clear: both;
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
66
  }
67
  """
68
 
69
  with gr.Blocks(css=custom_css) as demo:
70
- chatbot = gr.Chatbot(elem_classes="chatbot", bubble_full_width=False, show_copy_button=True)
71
- msg = gr.Textbox(placeholder="Type your message...")
72
- clear = gr.Button("Clear Chat")
 
 
 
73
 
74
  def user_submit(user_message, chat_history):
75
  return "", chat_history + [(user_message, None)]
@@ -85,7 +144,9 @@ with gr.Blocks(css=custom_css) as demo:
85
  msg.submit(user_submit, [msg, chatbot], [msg, chatbot]).then(
86
  bot_response, chatbot, chatbot
87
  )
88
- clear.click(lambda: None, None, chatbot)
 
 
89
 
90
  if __name__ == "__main__":
91
  demo.launch(share=True)
 
23
  response += msg.choices[0].delta.content
24
  yield response
25
 
26
+ # 💜 Modern Chatbot CSS
27
  custom_css = """
28
  .gradio-container {
 
29
  font-family: 'Segoe UI', sans-serif;
30
+ background: #f3f3f9;
31
+ height: 100vh;
32
  }
33
 
34
+ /* Top Header */
35
+ .top-bar {
36
+ background: linear-gradient(90deg, #7E498B, #9b59b6);
37
+ color: white;
38
+ font-size: 20px;
39
+ font-weight: 600;
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
+ /* Bubbles */
57
  .user-message {
58
+ background: linear-gradient(135deg, #7E498B, #9b59b6);
59
  color: white;
60
+ padding: 12px 16px;
61
  border-radius: 18px 18px 0 18px;
62
  margin: 8px 0;
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
  .bot-message {
72
+ background: #f1f1f1;
73
+ color: #333;
74
+ padding: 12px 16px;
75
  border-radius: 18px 18px 18px 0;
76
  margin: 8px 0;
77
  display: inline-block;
78
+ max-width: 75%;
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 area */
87
+ .input-area {
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 18px !important;
97
+ font-size: 15px !important;
98
+ border: 1px solid #ddd !important;
99
+ resize: none !important;
100
+ outline: none !important;
101
+ }
102
+
103
+ .input-area button {
104
+ background: linear-gradient(135deg, #7E498B, #9b59b6) !important;
105
+ color: white !important;
106
+ border-radius: 50% !important;
107
+ width: 50px;
108
+ height: 50px;
109
+ font-size: 18px;
110
+ font-weight: bold;
111
+ transition: 0.3s;
112
+ }
113
+
114
+ .input-area button:hover {
115
+ background: #632f73 !important;
116
+ }
117
+
118
+ /* Animations */
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
+ with gr.Column():
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)]
 
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)