Update app.py
Browse files
app.py
CHANGED
@@ -246,7 +246,7 @@ body {
|
|
246 |
.container {
|
247 |
max-width: 1200px;
|
248 |
margin: auto;
|
249 |
-
padding:
|
250 |
background-color: white;
|
251 |
border-radius: 10px;
|
252 |
box-shadow: 0 4px 6px rgba(0, 0, 0, 0.1);
|
@@ -254,138 +254,94 @@ body {
|
|
254 |
|
255 |
.header {
|
256 |
text-align: center;
|
257 |
-
margin-bottom:
|
258 |
-
padding-bottom:
|
259 |
border-bottom: 2px solid var(--primary-color);
|
260 |
}
|
261 |
|
262 |
.header h1 {
|
263 |
color: var(--secondary-color);
|
264 |
font-size: 2.5rem;
|
265 |
-
margin-bottom: 0.
|
266 |
}
|
267 |
|
268 |
.subheader {
|
269 |
color: var(--text-color);
|
270 |
-
font-size:
|
271 |
-
line-height: 1.
|
272 |
-
margin-bottom:
|
273 |
-
text-align: center;
|
274 |
}
|
275 |
|
276 |
.main-content {
|
277 |
display: flex;
|
278 |
-
gap:
|
279 |
}
|
280 |
|
281 |
.left-column {
|
282 |
-
flex:
|
283 |
}
|
284 |
|
285 |
.right-column {
|
286 |
-
flex:
|
287 |
}
|
288 |
|
289 |
.file-upload-container {
|
290 |
border: 2px dashed var(--primary-color);
|
291 |
border-radius: 10px;
|
292 |
-
padding: 2rem;
|
293 |
-
text-align: center;
|
294 |
-
margin-bottom: 1.5rem;
|
295 |
-
background-color: #FFF5E6;
|
296 |
-
}
|
297 |
-
|
298 |
-
.analyze-button {
|
299 |
-
background-color: var(--primary-color) !important;
|
300 |
-
color: white !important;
|
301 |
-
font-size: 1.1rem !important;
|
302 |
-
padding: 0.75rem 1.5rem !important;
|
303 |
-
border-radius: 5px !important;
|
304 |
-
width: 100%;
|
305 |
-
transition: background-color 0.3s ease;
|
306 |
-
}
|
307 |
-
|
308 |
-
.analyze-button:hover {
|
309 |
-
background-color: #E85A2A !important;
|
310 |
-
}
|
311 |
-
|
312 |
-
.clear-button, .download-button {
|
313 |
-
background-color: var(--secondary-color) !important;
|
314 |
-
color: white !important;
|
315 |
-
font-size: 1rem !important;
|
316 |
-
padding: 0.5rem 1rem !important;
|
317 |
-
border-radius: 5px !important;
|
318 |
-
transition: background-color 0.3s ease;
|
319 |
-
}
|
320 |
-
|
321 |
-
.clear-button:hover, .download-button:hover {
|
322 |
-
background-color: #003D6E !important;
|
323 |
-
}
|
324 |
-
|
325 |
-
.chatbot {
|
326 |
-
border: 1px solid var(--border-color);
|
327 |
-
border-radius: 10px;
|
328 |
padding: 1rem;
|
329 |
-
|
330 |
-
overflow-y: auto;
|
331 |
-
background-color: white;
|
332 |
-
}
|
333 |
-
|
334 |
-
.chat-input {
|
335 |
-
border: 1px solid var(--border-color);
|
336 |
-
border-radius: 5px;
|
337 |
-
padding: 0.75rem;
|
338 |
-
width: 100%;
|
339 |
-
font-size: 1rem;
|
340 |
-
}
|
341 |
-
|
342 |
-
.section-title {
|
343 |
-
color: var(--secondary-color);
|
344 |
-
font-size: 1.5rem;
|
345 |
-
margin-top: 2rem;
|
346 |
margin-bottom: 1rem;
|
347 |
-
|
348 |
-
padding-bottom: 0.5rem;
|
349 |
}
|
350 |
|
351 |
.info-box {
|
352 |
background-color: #E6F3FF;
|
353 |
border: 1px solid var(--secondary-color);
|
354 |
border-radius: 5px;
|
355 |
-
padding:
|
356 |
-
margin-bottom:
|
357 |
font-size: 0.9rem;
|
358 |
}
|
359 |
|
360 |
.info-box h4 {
|
361 |
color: var(--secondary-color);
|
362 |
margin-top: 0;
|
363 |
-
margin-bottom: 0.
|
364 |
}
|
365 |
|
366 |
.info-box ul, .info-box ol {
|
367 |
margin: 0;
|
368 |
-
padding-left: 1.
|
369 |
}
|
370 |
|
371 |
.tag {
|
372 |
display: inline-block;
|
373 |
background-color: var(--primary-color);
|
374 |
color: white;
|
375 |
-
padding: 0.
|
376 |
border-radius: 3px;
|
377 |
font-size: 0.8rem;
|
378 |
-
margin-right: 0.
|
379 |
-
margin-bottom: 0.
|
380 |
}
|
381 |
|
382 |
-
.
|
383 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
384 |
}
|
385 |
|
386 |
.footer {
|
387 |
-
margin-top:
|
388 |
-
padding-top:
|
389 |
border-top: 2px solid var(--primary-color);
|
390 |
display: flex;
|
391 |
justify-content: flex-start;
|
@@ -395,21 +351,20 @@ body {
|
|
395 |
.groq-badge {
|
396 |
background-color: var(--secondary-color);
|
397 |
color: white;
|
398 |
-
padding: 8px
|
399 |
border-radius: 5px;
|
400 |
font-weight: bold;
|
401 |
-
font-size:
|
402 |
display: inline-block;
|
403 |
-
margin-right:
|
404 |
}
|
405 |
|
406 |
.model-info {
|
407 |
color: var(--text-color);
|
408 |
-
font-size: 0.
|
409 |
}
|
410 |
"""
|
411 |
|
412 |
-
# Create the Gradio interface
|
413 |
with gr.Blocks(css=custom_css, theme=gr.themes.Soft()) as iface:
|
414 |
gr.HTML(
|
415 |
"""
|
@@ -423,7 +378,7 @@ with gr.Blocks(css=custom_css, theme=gr.themes.Soft()) as iface:
|
|
423 |
|
424 |
with gr.Row(elem_classes="main-content"):
|
425 |
with gr.Column(elem_classes="left-column"):
|
426 |
-
gr.
|
427 |
file_input = gr.File(
|
428 |
label="Upload Construction Site Images or Videos",
|
429 |
file_count="multiple",
|
@@ -431,7 +386,7 @@ with gr.Blocks(css=custom_css, theme=gr.themes.Soft()) as iface:
|
|
431 |
elem_classes="file-upload-container"
|
432 |
)
|
433 |
|
434 |
-
with gr.Row(
|
435 |
gr.HTML(
|
436 |
"""
|
437 |
<div class="info-box">
|
@@ -472,28 +427,6 @@ with gr.Blocks(css=custom_css, theme=gr.themes.Soft()) as iface:
|
|
472 |
</div>
|
473 |
"""
|
474 |
)
|
475 |
-
|
476 |
-
gr.HTML('<h3 class="section-title">Snag Detection Results</h3>')
|
477 |
-
chatbot = gr.Chatbot(
|
478 |
-
label="Snag Detection Results and Expert Chat",
|
479 |
-
elem_classes="chatbot",
|
480 |
-
show_share_button=False,
|
481 |
-
show_copy_button=False
|
482 |
-
)
|
483 |
-
|
484 |
-
with gr.Row():
|
485 |
-
msg = gr.Textbox(
|
486 |
-
label="Ask about detected snags or quality issues",
|
487 |
-
placeholder="E.g., 'What are the most critical snags detected?'",
|
488 |
-
show_label=False,
|
489 |
-
elem_classes="chat-input"
|
490 |
-
)
|
491 |
-
|
492 |
-
with gr.Row():
|
493 |
-
clear = gr.Button("🗑️ Clear Chat", elem_classes="clear-button")
|
494 |
-
download_button = gr.Button("📥 Download Report", elem_classes="download-button")
|
495 |
-
|
496 |
-
report_file = gr.File(label="Download Snag Detection Report")
|
497 |
|
498 |
gr.HTML(
|
499 |
"""
|
@@ -505,47 +438,15 @@ with gr.Blocks(css=custom_css, theme=gr.themes.Soft()) as iface:
|
|
505 |
)
|
506 |
|
507 |
def detect_snags(file):
|
508 |
-
#
|
509 |
-
|
510 |
-
|
511 |
-
def chat_about_snags(message, chat_history):
|
512 |
-
# Implement chat functionality here
|
513 |
-
pass
|
514 |
-
|
515 |
-
def generate_snag_report(chat_history):
|
516 |
-
# Implement report generation logic here
|
517 |
-
pass
|
518 |
-
|
519 |
-
def process_files(files):
|
520 |
-
results = []
|
521 |
-
for file in files:
|
522 |
-
result = detect_snags(file)
|
523 |
-
results.append((file.name, result))
|
524 |
-
return results
|
525 |
-
|
526 |
-
def update_chat(history, new_messages):
|
527 |
-
history = history or []
|
528 |
-
for title, content in new_messages:
|
529 |
-
history.append((None, f"File: {title}\n\n{content}"))
|
530 |
-
return history
|
531 |
|
532 |
analyze_button.click(
|
533 |
-
|
534 |
inputs=[file_input],
|
535 |
-
outputs=[
|
536 |
-
postprocess=lambda x: update_chat(chatbot.value, x)
|
537 |
-
)
|
538 |
-
|
539 |
-
msg.submit(chat_about_snags, [msg, chatbot], [msg, chatbot])
|
540 |
-
clear.click(lambda: None, None, chatbot, queue=False)
|
541 |
-
|
542 |
-
download_button.click(
|
543 |
-
generate_snag_report,
|
544 |
-
inputs=[chatbot],
|
545 |
-
outputs=[report_file]
|
546 |
)
|
547 |
|
548 |
-
# Launch the app
|
549 |
if __name__ == "__main__":
|
550 |
try:
|
551 |
iface.launch(debug=True)
|
|
|
246 |
.container {
|
247 |
max-width: 1200px;
|
248 |
margin: auto;
|
249 |
+
padding: 1rem;
|
250 |
background-color: white;
|
251 |
border-radius: 10px;
|
252 |
box-shadow: 0 4px 6px rgba(0, 0, 0, 0.1);
|
|
|
254 |
|
255 |
.header {
|
256 |
text-align: center;
|
257 |
+
margin-bottom: 1rem;
|
258 |
+
padding-bottom: 0.5rem;
|
259 |
border-bottom: 2px solid var(--primary-color);
|
260 |
}
|
261 |
|
262 |
.header h1 {
|
263 |
color: var(--secondary-color);
|
264 |
font-size: 2.5rem;
|
265 |
+
margin-bottom: 0.25rem;
|
266 |
}
|
267 |
|
268 |
.subheader {
|
269 |
color: var(--text-color);
|
270 |
+
font-size: 1rem;
|
271 |
+
line-height: 1.2;
|
272 |
+
margin-bottom: 0.5rem;
|
|
|
273 |
}
|
274 |
|
275 |
.main-content {
|
276 |
display: flex;
|
277 |
+
gap: 1rem;
|
278 |
}
|
279 |
|
280 |
.left-column {
|
281 |
+
flex: 3;
|
282 |
}
|
283 |
|
284 |
.right-column {
|
285 |
+
flex: 2;
|
286 |
}
|
287 |
|
288 |
.file-upload-container {
|
289 |
border: 2px dashed var(--primary-color);
|
290 |
border-radius: 10px;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
291 |
padding: 1rem;
|
292 |
+
text-align: center;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
293 |
margin-bottom: 1rem;
|
294 |
+
background-color: #FFF5E6;
|
|
|
295 |
}
|
296 |
|
297 |
.info-box {
|
298 |
background-color: #E6F3FF;
|
299 |
border: 1px solid var(--secondary-color);
|
300 |
border-radius: 5px;
|
301 |
+
padding: 0.75rem;
|
302 |
+
margin-bottom: 1rem;
|
303 |
font-size: 0.9rem;
|
304 |
}
|
305 |
|
306 |
.info-box h4 {
|
307 |
color: var(--secondary-color);
|
308 |
margin-top: 0;
|
309 |
+
margin-bottom: 0.25rem;
|
310 |
}
|
311 |
|
312 |
.info-box ul, .info-box ol {
|
313 |
margin: 0;
|
314 |
+
padding-left: 1.25rem;
|
315 |
}
|
316 |
|
317 |
.tag {
|
318 |
display: inline-block;
|
319 |
background-color: var(--primary-color);
|
320 |
color: white;
|
321 |
+
padding: 0.15rem 0.3rem;
|
322 |
border-radius: 3px;
|
323 |
font-size: 0.8rem;
|
324 |
+
margin-right: 0.25rem;
|
325 |
+
margin-bottom: 0.25rem;
|
326 |
}
|
327 |
|
328 |
+
.analyze-button {
|
329 |
+
background-color: var(--primary-color) !important;
|
330 |
+
color: white !important;
|
331 |
+
font-size: 1.1rem !important;
|
332 |
+
padding: 0.5rem 1rem !important;
|
333 |
+
border-radius: 5px !important;
|
334 |
+
width: 100%;
|
335 |
+
transition: background-color 0.3s ease;
|
336 |
+
}
|
337 |
+
|
338 |
+
.analyze-button:hover {
|
339 |
+
background-color: #E85A2A !important;
|
340 |
}
|
341 |
|
342 |
.footer {
|
343 |
+
margin-top: 1rem;
|
344 |
+
padding-top: 0.5rem;
|
345 |
border-top: 2px solid var(--primary-color);
|
346 |
display: flex;
|
347 |
justify-content: flex-start;
|
|
|
351 |
.groq-badge {
|
352 |
background-color: var(--secondary-color);
|
353 |
color: white;
|
354 |
+
padding: 4px 8px;
|
355 |
border-radius: 5px;
|
356 |
font-weight: bold;
|
357 |
+
font-size: 0.9rem;
|
358 |
display: inline-block;
|
359 |
+
margin-right: 0.5rem;
|
360 |
}
|
361 |
|
362 |
.model-info {
|
363 |
color: var(--text-color);
|
364 |
+
font-size: 0.8rem;
|
365 |
}
|
366 |
"""
|
367 |
|
|
|
368 |
with gr.Blocks(css=custom_css, theme=gr.themes.Soft()) as iface:
|
369 |
gr.HTML(
|
370 |
"""
|
|
|
378 |
|
379 |
with gr.Row(elem_classes="main-content"):
|
380 |
with gr.Column(elem_classes="left-column"):
|
381 |
+
gr.Markdown("### Upload Files")
|
382 |
file_input = gr.File(
|
383 |
label="Upload Construction Site Images or Videos",
|
384 |
file_count="multiple",
|
|
|
386 |
elem_classes="file-upload-container"
|
387 |
)
|
388 |
|
389 |
+
with gr.Row():
|
390 |
gr.HTML(
|
391 |
"""
|
392 |
<div class="info-box">
|
|
|
427 |
</div>
|
428 |
"""
|
429 |
)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
430 |
|
431 |
gr.HTML(
|
432 |
"""
|
|
|
438 |
)
|
439 |
|
440 |
def detect_snags(file):
|
441 |
+
# Placeholder for snag detection logic
|
442 |
+
return "Snag detection results would appear here."
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
443 |
|
444 |
analyze_button.click(
|
445 |
+
detect_snags,
|
446 |
inputs=[file_input],
|
447 |
+
outputs=[gr.Textbox(label="Detection Results")]
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
448 |
)
|
449 |
|
|
|
450 |
if __name__ == "__main__":
|
451 |
try:
|
452 |
iface.launch(debug=True)
|