asthaaa300
commited on
Update app.py
Browse files
app.py
CHANGED
@@ -6,8 +6,10 @@ from huggingface_hub.inference._generated.types.chat_completion import ChatCompl
|
|
6 |
MODEL = "nomiChroma3.1"
|
7 |
client = InferenceClient("HuggingFaceH4/zephyr-7b-beta")
|
8 |
|
9 |
-
|
10 |
-
|
|
|
|
|
11 |
"""
|
12 |
Generate a response and update chat history.
|
13 |
Uses the new message format with role and content keys.
|
@@ -80,15 +82,88 @@ def handle_example_click(example_query: str):
|
|
80 |
"""Handle example query click by returning the query and empty chat history"""
|
81 |
return example_query, []
|
82 |
|
83 |
-
#
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
84 |
custom_css = """
|
85 |
@import url('https://fonts.googleapis.com/css2?family=Ubuntu:wght@300;400;500;700&display=swap');
|
86 |
-
|
87 |
.gradio-container {
|
88 |
background-color: #1a365d !important;
|
89 |
font-family: 'Ubuntu', -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Oxygen-Sans, Cantarell, "Helvetica Neue", sans-serif !important;
|
|
|
|
|
90 |
}
|
91 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
92 |
.header-container {
|
93 |
text-align: center;
|
94 |
padding: 2rem 0;
|
@@ -97,7 +172,6 @@ custom_css = """
|
|
97 |
position: relative;
|
98 |
z-index: 1;
|
99 |
}
|
100 |
-
|
101 |
.header-title {
|
102 |
color: #ffffff;
|
103 |
font-size: 2.5rem;
|
@@ -105,7 +179,6 @@ custom_css = """
|
|
105 |
font-family: 'Ubuntu', sans-serif !important;
|
106 |
text-shadow: 0 2px 4px rgba(0,0,0,0.2);
|
107 |
}
|
108 |
-
|
109 |
.header-subtitle {
|
110 |
color: #e6f3ff;
|
111 |
font-size: 1.1rem;
|
@@ -113,6 +186,129 @@ custom_css = """
|
|
113 |
font-family: 'Ubuntu', sans-serif !important;
|
114 |
opacity: 0.9;
|
115 |
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
116 |
|
117 |
.maritime-images {
|
118 |
display: grid;
|
@@ -138,28 +334,20 @@ custom_css = """
|
|
138 |
transform: scale(1.02);
|
139 |
}
|
140 |
|
141 |
-
/* Rest of your existing CSS remains exactly the same */
|
142 |
-
.sidebar {
|
143 |
-
background: #ccd9e6 !important;
|
144 |
-
border-radius: 8px !important;
|
145 |
-
padding: 15px !important;
|
146 |
-
border: 1px solid rgba(176, 226, 255, 0.2) !important;
|
147 |
-
height: fit-content !important;
|
148 |
-
position: relative;
|
149 |
-
overflow: hidden;
|
150 |
-
}
|
151 |
-
|
152 |
-
/* ... (rest of your existing CSS) ... */
|
153 |
"""
|
154 |
|
155 |
# Main application
|
156 |
with gr.Blocks(css=custom_css, theme=gr.themes.Base()) as demo:
|
157 |
-
#
|
158 |
-
|
|
|
|
|
|
|
|
|
159 |
<div class="header-container">
|
160 |
<h1 class="header-title">Maritime Legal Compliance</h1>
|
161 |
<div class="maritime-images">
|
162 |
-
<img src="
|
163 |
<img src="/api/placeholder/400/320" alt="Container ship at sea" class="maritime-image">
|
164 |
<img src="/api/placeholder/400/320" alt="Coastal waterway" class="maritime-image">
|
165 |
</div>
|
@@ -167,9 +355,11 @@ with gr.Blocks(css=custom_css, theme=gr.themes.Base()) as demo:
|
|
167 |
<p class="header-subtitle">This chatbot uses Fine-tuned LLAMA-3.1 model personalised specifically to provide assistance with Indian maritime legal queries.</p>
|
168 |
</div>
|
169 |
""")
|
|
|
|
|
170 |
|
171 |
-
# Rest of your application remains exactly the same
|
172 |
with gr.Row():
|
|
|
173 |
with gr.Column(scale=1, elem_classes="sidebar"):
|
174 |
gr.HTML("""
|
175 |
<div class="sidebar-bg">
|
@@ -205,8 +395,10 @@ with gr.Blocks(css=custom_css, theme=gr.themes.Base()) as demo:
|
|
205 |
with gr.Column(elem_classes="example-queries"):
|
206 |
example_buttons = [gr.Button(query, elem_classes="example-query-button") for query in example_queries]
|
207 |
|
208 |
-
gr.HTML("</div>")
|
209 |
|
|
|
|
|
210 |
with gr.Column(scale=3):
|
211 |
chatbot = gr.Chatbot(
|
212 |
height=300,
|
@@ -222,7 +414,7 @@ with gr.Blocks(css=custom_css, theme=gr.themes.Base()) as demo:
|
|
222 |
submit = gr.Button("Send", variant="primary")
|
223 |
clear = gr.Button("Clear")
|
224 |
|
225 |
-
# Event handlers
|
226 |
msg.submit(fn=respond, inputs=[msg, chatbot], outputs=[chatbot, msg])
|
227 |
submit.click(fn=respond, inputs=[msg, chatbot], outputs=[chatbot, msg])
|
228 |
clear.click(fn=lambda: ([], ""), inputs=None, outputs=[chatbot, msg], queue=False)
|
|
|
6 |
MODEL = "nomiChroma3.1"
|
7 |
client = InferenceClient("HuggingFaceH4/zephyr-7b-beta")
|
8 |
|
9 |
+
def respond(
|
10 |
+
message: str,
|
11 |
+
chat_history: list[dict],
|
12 |
+
) -> tuple[list[dict], str]:
|
13 |
"""
|
14 |
Generate a response and update chat history.
|
15 |
Uses the new message format with role and content keys.
|
|
|
82 |
"""Handle example query click by returning the query and empty chat history"""
|
83 |
return example_query, []
|
84 |
|
85 |
+
# SVG Definitions
|
86 |
+
WAVE_SVG = """
|
87 |
+
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 1440 320" preserveAspectRatio="none">
|
88 |
+
<defs>
|
89 |
+
<linearGradient id="waveGradient" x1="0%" y1="0%" x2="100%" y2="0%">
|
90 |
+
<stop offset="0%" style="stop-color:#1a365d;stop-opacity:0.2"/>
|
91 |
+
<stop offset="50%" style="stop-color:#2a4a7d;stop-opacity:0.3"/>
|
92 |
+
<stop offset="100%" style="stop-color:#1a365d;stop-opacity:0.2"/>
|
93 |
+
</linearGradient>
|
94 |
+
</defs>
|
95 |
+
<path fill="url(#waveGradient)" d="M0,192L48,197.3C96,203,192,213,288,229.3C384,245,480,267,576,250.7C672,235,768,181,864,181.3C960,181,1056,235,1152,234.7C1248,235,1344,181,1392,154.7L1440,128L1440,320L1392,320C1344,320,1248,320,1152,320C1056,320,960,320,864,320C768,320,672,320,576,320C480,320,384,320,288,320C192,320,96,320,48,320L0,320Z">
|
96 |
+
<animate attributeName="d"
|
97 |
+
dur="10s"
|
98 |
+
repeatCount="indefinite"
|
99 |
+
values="M0,192L48,197.3C96,203,192,213,288,229.3C384,245,480,267,576,250.7C672,235,768,181,864,181.3C960,181,1056,235,1152,234.7C1248,235,1344,181,1392,154.7L1440,128L1440,320L1392,320C1344,320,1248,320,1152,320C1056,320,960,320,864,320C768,320,672,320,576,320C480,320,384,320,288,320C192,320,96,320,48,320L0,320Z;
|
100 |
+
M0,160L48,181.3C96,203,192,245,288,261.3C384,277,480,267,576,234.7C672,203,768,149,864,138.7C960,128,1056,160,1152,186.7C1248,213,1344,235,1392,245.3L1440,256L1440,320L1392,320C1344,320,1248,320,1152,320C1056,320,960,320,864,320C768,320,672,320,576,320C480,320,384,320,288,320C192,320,96,320,48,320L0,320Z;
|
101 |
+
M0,192L48,197.3C96,203,192,213,288,229.3C384,245,480,267,576,250.7C672,235,768,181,864,181.3C960,181,1056,235,1152,234.7C1248,235,1344,181,1392,154.7L1440,128L1440,320L1392,320C1344,320,1248,320,1152,320C1056,320,960,320,864,320C768,320,672,320,576,320C480,320,384,320,288,320C192,320,96,320,48,320L0,320Z"/>
|
102 |
+
</path>
|
103 |
+
</svg>
|
104 |
+
"""
|
105 |
+
|
106 |
+
MARITIME_ICONS = """
|
107 |
+
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 240 60">
|
108 |
+
<g transform="translate(0,0)">
|
109 |
+
<path d="M20,10 v25 M10,35 h20 M20,10 l-10,10 l10,-10 l10,10"
|
110 |
+
stroke="#e6f3ff"
|
111 |
+
fill="none"
|
112 |
+
stroke-width="2"/>
|
113 |
+
</g>
|
114 |
+
<g transform="translate(60,0)">
|
115 |
+
<path d="M10,30 l5,-15 h30 l5,15 h-40 v5 l40,0 v-5"
|
116 |
+
stroke="#e6f3ff"
|
117 |
+
fill="none"
|
118 |
+
stroke-width="2"/>
|
119 |
+
<path d="M20,15 v-5 h20 v5"
|
120 |
+
stroke="#e6f3ff"
|
121 |
+
fill="none"
|
122 |
+
stroke-width="2"/>
|
123 |
+
</g>
|
124 |
+
<g transform="translate(120,0)">
|
125 |
+
<path d="M25,5 l-7,35 h14 l-7,-35"
|
126 |
+
stroke="#e6f3ff"
|
127 |
+
fill="none"
|
128 |
+
stroke-width="2"/>
|
129 |
+
<path d="M18,15 h14 M18,25 h14"
|
130 |
+
stroke="#e6f3ff"
|
131 |
+
fill="none"
|
132 |
+
stroke-width="2"/>
|
133 |
+
</g>
|
134 |
+
<g transform="translate(180,0)">
|
135 |
+
<circle cx="20" cy="20" r="15"
|
136 |
+
stroke="#e6f3ff"
|
137 |
+
fill="none"
|
138 |
+
stroke-width="2"/>
|
139 |
+
<path d="M20,5 v30 M5,20 h30 M15,15 l10,10 M25,15 l-10,10"
|
140 |
+
stroke="#e6f3ff"
|
141 |
+
fill="none"
|
142 |
+
stroke-width="2"/>
|
143 |
+
</g>
|
144 |
+
</svg>
|
145 |
+
"""
|
146 |
+
|
147 |
custom_css = """
|
148 |
@import url('https://fonts.googleapis.com/css2?family=Ubuntu:wght@300;400;500;700&display=swap');
|
149 |
+
/* Global styles */
|
150 |
.gradio-container {
|
151 |
background-color: #1a365d !important;
|
152 |
font-family: 'Ubuntu', -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Oxygen-Sans, Cantarell, "Helvetica Neue", sans-serif !important;
|
153 |
+
position: relative;
|
154 |
+
overflow: hidden;
|
155 |
}
|
156 |
+
/* Wave Background */
|
157 |
+
.wave-background {
|
158 |
+
position: fixed;
|
159 |
+
bottom: 0;
|
160 |
+
left: 0;
|
161 |
+
width: 100%;
|
162 |
+
height: 100%;
|
163 |
+
z-index: 0;
|
164 |
+
pointer-events: none;
|
165 |
+
}
|
166 |
+
/* Header styling */
|
167 |
.header-container {
|
168 |
text-align: center;
|
169 |
padding: 2rem 0;
|
|
|
172 |
position: relative;
|
173 |
z-index: 1;
|
174 |
}
|
|
|
175 |
.header-title {
|
176 |
color: #ffffff;
|
177 |
font-size: 2.5rem;
|
|
|
179 |
font-family: 'Ubuntu', sans-serif !important;
|
180 |
text-shadow: 0 2px 4px rgba(0,0,0,0.2);
|
181 |
}
|
|
|
182 |
.header-subtitle {
|
183 |
color: #e6f3ff;
|
184 |
font-size: 1.1rem;
|
|
|
186 |
font-family: 'Ubuntu', sans-serif !important;
|
187 |
opacity: 0.9;
|
188 |
}
|
189 |
+
/* Maritime icons styling */
|
190 |
+
.maritime-icons {
|
191 |
+
display: flex;
|
192 |
+
justify-content: center;
|
193 |
+
margin: 1rem 0;
|
194 |
+
gap: 2rem;
|
195 |
+
}
|
196 |
+
.maritime-icon {
|
197 |
+
width: 40px;
|
198 |
+
height: 40px;
|
199 |
+
transition: transform 0.3s ease;
|
200 |
+
}
|
201 |
+
.maritime-icon:hover {
|
202 |
+
transform: scale(1.1);
|
203 |
+
}
|
204 |
+
/* Sidebar styling */
|
205 |
+
.sidebar {
|
206 |
+
background: #ccd9e6 !important;
|
207 |
+
border-radius: 8px !important;
|
208 |
+
padding: 15px !important;
|
209 |
+
border: 1px solid rgba(176, 226, 255, 0.2) !important;
|
210 |
+
height: fit-content !important;
|
211 |
+
position: relative;
|
212 |
+
overflow: hidden;
|
213 |
+
}
|
214 |
+
.sidebar-bg {
|
215 |
+
position: absolute;
|
216 |
+
top: 0;
|
217 |
+
right: 0;
|
218 |
+
bottom: 0;
|
219 |
+
left: 0;
|
220 |
+
opacity: 0.05;
|
221 |
+
pointer-events: none;
|
222 |
+
z-index: 0;
|
223 |
+
}
|
224 |
+
.sidebar-content {
|
225 |
+
position: relative;
|
226 |
+
z-index: 1;
|
227 |
+
}
|
228 |
+
.sidebar-icon {
|
229 |
+
width: 24px;
|
230 |
+
height: 24px;
|
231 |
+
margin-right: 8px;
|
232 |
+
vertical-align: middle;
|
233 |
+
}
|
234 |
+
.sidebar-title {
|
235 |
+
color: #1a365d !important;
|
236 |
+
font-size: 1.1rem !important;
|
237 |
+
margin-bottom: 0.8rem !important;
|
238 |
+
padding-bottom: 0.4rem !important;
|
239 |
+
border-bottom: 2px solid rgba(26, 54, 93, 0.2) !important;
|
240 |
+
font-family: 'Ubuntu', sans-serif !important;
|
241 |
+
display: flex;
|
242 |
+
align-items: center;
|
243 |
+
}
|
244 |
+
.example-query-button {
|
245 |
+
background-color: #b3c6d9 !important;
|
246 |
+
color: #1a365d !important;
|
247 |
+
border: none !important;
|
248 |
+
margin: 3px 0 !important;
|
249 |
+
padding: 6px 10px !important;
|
250 |
+
border-radius: 4px !important;
|
251 |
+
text-align: left !important;
|
252 |
+
width: 100% !important;
|
253 |
+
cursor: pointer !important;
|
254 |
+
transition: background-color 0.3s ease !important;
|
255 |
+
font-size: 0.9rem !important;
|
256 |
+
font-family: 'Ubuntu', sans-serif !important;
|
257 |
+
position: relative;
|
258 |
+
padding-left: 30px !important;
|
259 |
+
}
|
260 |
+
.example-query-button::before {
|
261 |
+
content: "⚓";
|
262 |
+
position: absolute;
|
263 |
+
left: 8px;
|
264 |
+
top: 50%;
|
265 |
+
transform: translateY(-50%);
|
266 |
+
font-size: 12px;
|
267 |
+
opacity: 0.7;
|
268 |
+
}
|
269 |
+
.example-query-button:hover {
|
270 |
+
background-color: #99b3cc !important;
|
271 |
+
}
|
272 |
+
/* Chat container */
|
273 |
+
.chat-container {
|
274 |
+
background: #ccd9e6 !important;
|
275 |
+
border-radius: 8px !important;
|
276 |
+
padding: 15px !important;
|
277 |
+
height: 300px !important;
|
278 |
+
overflow-y: auto !important;
|
279 |
+
border: 1px solid rgba(176, 226, 255, 0.2) !important;
|
280 |
+
backdrop-filter: blur(10px) !important;
|
281 |
+
font-family: 'Ubuntu', sans-serif !important;
|
282 |
+
}
|
283 |
+
/* Message styling */
|
284 |
+
.message.user, .message.bot {
|
285 |
+
padding: 8px 12px !important;
|
286 |
+
margin: 6px 0 !important;
|
287 |
+
border-radius: 6px !important;
|
288 |
+
color: #1a365d !important;
|
289 |
+
font-size: 0.9rem !important;
|
290 |
+
font-family: 'Ubuntu', sans-serif !important;
|
291 |
+
line-height: 1.5 !important;
|
292 |
+
}
|
293 |
+
.message.user {
|
294 |
+
background-color: #b3c6d9 !important;
|
295 |
+
}
|
296 |
+
.message.bot {
|
297 |
+
background-color: #e6f3ff !important;
|
298 |
+
}
|
299 |
+
/* Input and button styling */
|
300 |
+
textarea {
|
301 |
+
background-color: #e6f3ff !important;
|
302 |
+
border: 1px solid rgba(176, 226, 255, 0.3) !important;
|
303 |
+
border-radius: 6px !important;
|
304 |
+
padding: 8px !important;
|
305 |
+
color: #1a365d !important;
|
306 |
+
font-size: 0.9rem !important;
|
307 |
+
font-family: 'Ubuntu', sans-serif !important;
|
308 |
+
}
|
309 |
+
.gr-button {
|
310 |
+
font-family: 'Ubuntu', sans-serif !important;
|
311 |
+
}
|
312 |
|
313 |
.maritime-images {
|
314 |
display: grid;
|
|
|
334 |
transform: scale(1.02);
|
335 |
}
|
336 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
337 |
"""
|
338 |
|
339 |
# Main application
|
340 |
with gr.Blocks(css=custom_css, theme=gr.themes.Base()) as demo:
|
341 |
+
# Header with wave background and maritime icons
|
342 |
+
# Only change this part in your original code, specifically in the header HTML section:
|
343 |
+
gr.HTML(f"""
|
344 |
+
<div class="wave-background">
|
345 |
+
{WAVE_SVG}
|
346 |
+
</div>
|
347 |
<div class="header-container">
|
348 |
<h1 class="header-title">Maritime Legal Compliance</h1>
|
349 |
<div class="maritime-images">
|
350 |
+
<img src="img1.jpg" alt="Modern port with cargo vessels" class="maritime-image">
|
351 |
<img src="/api/placeholder/400/320" alt="Container ship at sea" class="maritime-image">
|
352 |
<img src="/api/placeholder/400/320" alt="Coastal waterway" class="maritime-image">
|
353 |
</div>
|
|
|
355 |
<p class="header-subtitle">This chatbot uses Fine-tuned LLAMA-3.1 model personalised specifically to provide assistance with Indian maritime legal queries.</p>
|
356 |
</div>
|
357 |
""")
|
358 |
+
|
359 |
+
|
360 |
|
|
|
361 |
with gr.Row():
|
362 |
+
# Enhanced sidebar with graphics
|
363 |
with gr.Column(scale=1, elem_classes="sidebar"):
|
364 |
gr.HTML("""
|
365 |
<div class="sidebar-bg">
|
|
|
395 |
with gr.Column(elem_classes="example-queries"):
|
396 |
example_buttons = [gr.Button(query, elem_classes="example-query-button") for query in example_queries]
|
397 |
|
398 |
+
gr.HTML("</div>") # Close sidebar-content
|
399 |
|
400 |
+
# Main chat area
|
401 |
+
# Main chat area
|
402 |
with gr.Column(scale=3):
|
403 |
chatbot = gr.Chatbot(
|
404 |
height=300,
|
|
|
414 |
submit = gr.Button("Send", variant="primary")
|
415 |
clear = gr.Button("Clear")
|
416 |
|
417 |
+
# Event handlers
|
418 |
msg.submit(fn=respond, inputs=[msg, chatbot], outputs=[chatbot, msg])
|
419 |
submit.click(fn=respond, inputs=[msg, chatbot], outputs=[chatbot, msg])
|
420 |
clear.click(fn=lambda: ([], ""), inputs=None, outputs=[chatbot, msg], queue=False)
|