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

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +58 -6
app.py CHANGED
@@ -23,17 +23,69 @@ def respond(message, history: list[dict[str, str]]):
23
  response += msg.choices[0].delta.content
24
  yield response
25
 
26
-
27
- # 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
  }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
33
  """
34
 
35
- with gr.Blocks(theme=gr.themes.Soft(), css=custom_css) as demo:
36
- gr.ChatInterface(respond, type="messages")
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
37
 
38
  if __name__ == "__main__":
39
- demo.launch(share=True)
 
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)]
76
+
77
+ def bot_response(chat_history):
78
+ user_message = chat_history[-1][0]
79
+ response = ""
80
+ for partial in respond(user_message, [{"role": "user", "content": h[0]} for h in chat_history[:-1]]):
81
+ response = partial
82
+ chat_history[-1] = (chat_history[-1][0], response)
83
+ return chat_history
84
+
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)