jeremierostan
commited on
Commit
•
4363711
1
Parent(s):
146ffc5
Update app.py
Browse files
app.py
CHANGED
@@ -58,7 +58,7 @@ def chat_with_assistant(message, history):
|
|
58 |
Your goal is to help students understand the historical figure better through and engaging conversation.
|
59 |
Use the following as context for your answers.
|
60 |
{context}
|
61 |
-
However, use it seamlessly as background knowledge for a lively discussion. Do not provide citations or adopt a Q&A or academic tone.
|
62 |
|
63 |
Always use appropriate language.
|
64 |
Refuse to answer inappropriate questions or questions unrelated to your role and historical figure.
|
@@ -111,7 +111,7 @@ isp_theme = gr.themes.Default().set(
|
|
111 |
block_border_color="#00008B", # Dark blue border
|
112 |
)
|
113 |
|
114 |
-
# Custom CSS for logo positioning
|
115 |
custom_css = """
|
116 |
#logo-img {
|
117 |
position: absolute;
|
@@ -120,33 +120,62 @@ custom_css = """
|
|
120 |
width: 100px;
|
121 |
height: auto;
|
122 |
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
123 |
"""
|
124 |
|
|
|
125 |
assistant_avatar = os.getenv('AVATAR')
|
126 |
assistant_title = os.getenv('TITLE')
|
127 |
-
|
128 |
-
|
129 |
-
|
130 |
-
|
|
|
|
|
|
|
|
|
|
|
131 |
height=500,
|
132 |
avatar_images=(None, assistant_avatar)
|
133 |
-
)
|
134 |
-
|
135 |
-
|
136 |
-
|
137 |
-
theme=isp_theme,
|
138 |
-
retry_btn=None,
|
139 |
-
undo_btn="Delete Previous",
|
140 |
-
clear_btn="Clear",
|
141 |
-
css=custom_css,
|
142 |
-
)
|
143 |
|
144 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
145 |
|
146 |
-
|
147 |
-
|
148 |
-
disclaimer_text = "You are chatting with an AI assistant. Make sure to evaluate the accuracy of its answers."
|
149 |
-
disclaimer_html = f'<div id="disclaimer-footer">{disclaimer_text}</div>'
|
150 |
-
iface.attachments.append(logo_html)
|
151 |
|
152 |
iface.launch(auth=(username, password))
|
|
|
58 |
Your goal is to help students understand the historical figure better through and engaging conversation.
|
59 |
Use the following as context for your answers.
|
60 |
{context}
|
61 |
+
However, use it seamlessly as background knowledge for a lively discussion and combine it with your own information. Do not provide citations or adopt a Q&A or academic tone.
|
62 |
|
63 |
Always use appropriate language.
|
64 |
Refuse to answer inappropriate questions or questions unrelated to your role and historical figure.
|
|
|
111 |
block_border_color="#00008B", # Dark blue border
|
112 |
)
|
113 |
|
114 |
+
# Custom CSS for logo positioning and disclaimer footer
|
115 |
custom_css = """
|
116 |
#logo-img {
|
117 |
position: absolute;
|
|
|
120 |
width: 100px;
|
121 |
height: auto;
|
122 |
}
|
123 |
+
|
124 |
+
#disclaimer-footer {
|
125 |
+
width: 100%;
|
126 |
+
background-color: #F0F8FF;
|
127 |
+
color: #00008B;
|
128 |
+
text-align: center;
|
129 |
+
padding: 10px 0;
|
130 |
+
font-size: 14px;
|
131 |
+
border-top: 1px solid #00008B;
|
132 |
+
margin-top: 20px;
|
133 |
+
}
|
134 |
"""
|
135 |
|
136 |
+
# Environment variables
|
137 |
assistant_avatar = os.getenv('AVATAR')
|
138 |
assistant_title = os.getenv('TITLE')
|
139 |
+
assistant_logo = os.getenv('LOGO')
|
140 |
+
|
141 |
+
# Gradio interface using Blocks
|
142 |
+
with gr.Blocks(theme=isp_theme, css=custom_css) as iface:
|
143 |
+
gr.HTML(f"<img id='logo-img' src='{assistant_logo}' alt='Assistant Logo'>")
|
144 |
+
gr.Markdown(f"# {assistant_title}")
|
145 |
+
gr.Markdown("Chat with a Historical Figure")
|
146 |
+
|
147 |
+
chatbot = gr.Chatbot(
|
148 |
height=500,
|
149 |
avatar_images=(None, assistant_avatar)
|
150 |
+
)
|
151 |
+
msg = gr.Textbox(placeholder="Type your message here...", container=False, scale=7)
|
152 |
+
clear = gr.ClearButton([msg, chatbot], value="Clear")
|
153 |
+
undo = gr.Button("Delete Previous")
|
|
|
|
|
|
|
|
|
|
|
|
|
154 |
|
155 |
+
def user(user_message, history):
|
156 |
+
return "", history + [[user_message, None]]
|
157 |
+
|
158 |
+
def bot(history):
|
159 |
+
bot_message = chat_with_assistant(history[-1][0], history[:-1])
|
160 |
+
history[-1][1] = bot_message
|
161 |
+
return history
|
162 |
+
|
163 |
+
def delete_previous(history):
|
164 |
+
if len(history) > 0:
|
165 |
+
return history[:-1]
|
166 |
+
return history
|
167 |
+
|
168 |
+
msg.submit(user, [msg, chatbot], [msg, chatbot], queue=False).then(
|
169 |
+
bot, chatbot, chatbot
|
170 |
+
)
|
171 |
+
undo.click(delete_previous, chatbot, chatbot)
|
172 |
+
|
173 |
+
gr.Examples(
|
174 |
+
examples=["Why were you called the Sun King?", "How well is France doing economically during your reign?"],
|
175 |
+
inputs=msg
|
176 |
+
)
|
177 |
|
178 |
+
disclaimer_text = "You are chatting with an AI assistant. Make sure to evaluate the accuracy of its answers."
|
179 |
+
gr.HTML(f"<div id='disclaimer-footer'>{disclaimer_text}</div>")
|
|
|
|
|
|
|
180 |
|
181 |
iface.launch(auth=(username, password))
|