jeremierostan commited on
Commit
440f4cc
·
verified ·
1 Parent(s): fb16688

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +72 -36
app.py CHANGED
@@ -95,21 +95,21 @@ def chat_with_assistant(message, history):
95
 
96
  return response.content[0].text.strip()
97
 
98
- # CSS for an ISP-looking style
99
  isp_theme = gr.themes.Default().set(
100
- body_background_fill="#F0F8FF", # Light blue background
101
  block_background_fill="#FFFFFF", # White for input blocks
102
- block_title_text_color="#00008B", # Dark blue for text
103
- block_label_background_fill="#FFD700", # Yellow for labels
104
  input_background_fill="#FFFFFF", # White for input fields
105
- button_primary_background_fill="#FF1493", # Pink/Magenta for primary buttons
106
- button_primary_background_fill_hover="#FF69B4", # Lighter pink for hover
107
  button_primary_text_color="#FFFFFF", # White text on buttons
108
- button_secondary_background_fill="#FFD700", # Yellow for secondary buttons
109
- button_secondary_background_fill_hover="#FFA500", # Orange for hover
110
- button_secondary_text_color="#00008B", # Dark blue text for secondary buttons
111
  block_border_width="1px",
112
- block_border_color="#00008B", # Dark blue border
113
  )
114
 
115
  # Custom CSS for logo positioning and disclaimer footer
@@ -121,17 +121,42 @@ custom_css = """
121
  width: 100px;
122
  height: auto;
123
  }
124
-
125
  #disclaimer-footer {
126
  width: 100%;
127
- background-color: #F0F8FF;
128
- color: #00008B;
129
  text-align: center;
130
  padding: 10px 0;
131
  font-size: 14px;
132
- border-top: 1px solid #00008B;
133
  margin-top: 20px;
134
  }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
135
  """
136
 
137
  # Environment variables
@@ -141,22 +166,37 @@ assistant_logo = os.getenv('LOGO')
141
 
142
  # Gradio interface using Blocks
143
  with gr.Blocks(theme=isp_theme, css=custom_css) as iface:
144
- with gr.Row():
145
- logo_html = f"""
146
- <img id='logo-img' src='{assistant_logo}' alt='Assistant Logo' onerror="this.style.display='none';document.getElementById('logo-error').style.display='block';">
147
- <div id='logo-error' style='display:none;'>Logo not found</div>
148
- """
149
- gr.HTML(logo_html)
150
- gr.Markdown(f"# {assistant_title}", elem_classes="title")
 
 
151
  gr.Markdown("Chat with a Historical Figure")
152
-
153
- chatbot = gr.Chatbot(
154
- height=500,
155
- avatar_images=(None, assistant_avatar)
156
- )
157
- msg = gr.Textbox(placeholder="Type your message here...", container=False, scale=7)
158
- clear = gr.ClearButton([msg, chatbot], value="Clear")
159
- undo = gr.Button("Delete Previous")
 
 
 
 
 
 
 
 
 
 
 
 
 
160
 
161
  def user(user_message, history):
162
  return "", history + [[user_message, None]]
@@ -174,13 +214,9 @@ with gr.Blocks(theme=isp_theme, css=custom_css) as iface:
174
  msg.submit(user, [msg, chatbot], [msg, chatbot], queue=False).then(
175
  bot, chatbot, chatbot
176
  )
177
- undo.click(delete_previous, chatbot, chatbot)
178
-
179
- gr.Examples(
180
- examples=["Why were you called the Sun King?", "How well is France doing economically during your reign?"],
181
- inputs=msg
182
  )
183
-
184
- gr.Markdown("You are chatting with an AI assistant. Make sure to evaluate the accuracy of its answers.")
185
 
186
  iface.launch(auth=(username, password))
 
95
 
96
  return response.content[0].text.strip()
97
 
98
+ # CSS for a blue-themed style
99
  isp_theme = gr.themes.Default().set(
100
+ body_background_fill="#E6F3FF", # Light blue background
101
  block_background_fill="#FFFFFF", # White for input blocks
102
+ block_title_text_color="#003366", # Dark blue for text
103
+ block_label_background_fill="#B8D8FF", # Light blue for labels
104
  input_background_fill="#FFFFFF", # White for input fields
105
+ button_primary_background_fill="#0066CC", # Medium blue for primary buttons
106
+ button_primary_background_fill_hover="#0052A3", # Darker blue for hover
107
  button_primary_text_color="#FFFFFF", # White text on buttons
108
+ button_secondary_background_fill="#B8D8FF", # Light blue for secondary buttons
109
+ button_secondary_background_fill_hover="#99C2FF", # Slightly darker blue for hover
110
+ button_secondary_text_color="#003366", # Dark blue text for secondary buttons
111
  block_border_width="1px",
112
+ block_border_color="#0066CC", # Medium blue border
113
  )
114
 
115
  # Custom CSS for logo positioning and disclaimer footer
 
121
  width: 100px;
122
  height: auto;
123
  }
 
124
  #disclaimer-footer {
125
  width: 100%;
126
+ background-color: #B8D8FF;
127
+ color: #003366;
128
  text-align: center;
129
  padding: 10px 0;
130
  font-size: 14px;
131
+ border-top: 1px solid #0066CC;
132
  margin-top: 20px;
133
  }
134
+ .container {
135
+ max-width: 800px;
136
+ margin: 0 auto;
137
+ padding: 20px;
138
+ }
139
+ .title {
140
+ color: #003366;
141
+ margin-bottom: 10px;
142
+ }
143
+ .chatbot {
144
+ border: 1px solid #0066CC;
145
+ border-radius: 5px;
146
+ padding: 10px;
147
+ margin-bottom: 15px;
148
+ }
149
+ .button-row {
150
+ display: flex;
151
+ gap: 10px;
152
+ margin-bottom: 15px;
153
+ }
154
+ .examples-section {
155
+ background-color: #B8D8FF;
156
+ padding: 10px;
157
+ border-radius: 5px;
158
+ margin-top: 15px;
159
+ }
160
  """
161
 
162
  # Environment variables
 
166
 
167
  # Gradio interface using Blocks
168
  with gr.Blocks(theme=isp_theme, css=custom_css) as iface:
169
+ with gr.Column(elem_classes="container"):
170
+ with gr.Row():
171
+ logo_html = f"""
172
+ <img id='logo-img' src='{assistant_logo}' alt='Assistant Logo' onerror="this.style.display='none';document.getElementById('logo-error').style.display='block';">
173
+ <div id='logo-error' style='display:none;'>Logo not found</div>
174
+ """
175
+ gr.HTML(logo_html)
176
+ gr.Markdown(f"# {assistant_title}", elem_classes="title")
177
+
178
  gr.Markdown("Chat with a Historical Figure")
179
+
180
+ chatbot = gr.Chatbot(
181
+ height=500,
182
+ avatar_images=(None, assistant_avatar),
183
+ elem_classes="chatbot"
184
+ )
185
+
186
+ msg = gr.Textbox(placeholder="Type your message here...", container=False, scale=7)
187
+
188
+ with gr.Row(elem_classes="button-row"):
189
+ submit = gr.Button("Submit", variant="primary")
190
+ clear = gr.ClearButton([msg, chatbot], value="Clear", variant="secondary")
191
+ undo = gr.Button("Delete Previous", variant="secondary")
192
+
193
+ gr.Examples(
194
+ examples=["Why were you called the Sun King?", "How well is France doing economically during your reign?"],
195
+ inputs=msg,
196
+ elem_classes="examples-section"
197
+ )
198
+
199
+ gr.HTML("<div id='disclaimer-footer'>You are chatting with an AI assistant. Make sure to evaluate the accuracy of its answers.</div>")
200
 
201
  def user(user_message, history):
202
  return "", history + [[user_message, None]]
 
214
  msg.submit(user, [msg, chatbot], [msg, chatbot], queue=False).then(
215
  bot, chatbot, chatbot
216
  )
217
+ submit.click(user, [msg, chatbot], [msg, chatbot], queue=False).then(
218
+ bot, chatbot, chatbot
 
 
 
219
  )
220
+ undo.click(delete_previous, chatbot, chatbot)
 
221
 
222
  iface.launch(auth=(username, password))