Update app.py
Browse files
app.py
CHANGED
@@ -335,12 +335,18 @@ body {
|
|
335 |
padding-bottom: 0.5rem;
|
336 |
}
|
337 |
|
|
|
|
|
|
|
|
|
|
|
|
|
338 |
.info-box {
|
|
|
339 |
background-color: #E6F3FF;
|
340 |
border: 1px solid var(--secondary-color);
|
341 |
border-radius: 5px;
|
342 |
padding: 1rem;
|
343 |
-
margin-bottom: 1.5rem;
|
344 |
font-size: 0.9rem;
|
345 |
}
|
346 |
|
@@ -350,7 +356,7 @@ body {
|
|
350 |
margin-bottom: 0.5rem;
|
351 |
}
|
352 |
|
353 |
-
.info-box ul {
|
354 |
margin: 0;
|
355 |
padding-left: 1.5rem;
|
356 |
}
|
@@ -373,7 +379,6 @@ body {
|
|
373 |
display: flex;
|
374 |
justify-content: space-between;
|
375 |
align-items: center;
|
376 |
-
flex-wrap: wrap;
|
377 |
}
|
378 |
|
379 |
.groq-badge {
|
@@ -389,7 +394,6 @@ body {
|
|
389 |
.model-info {
|
390 |
color: var(--text-color);
|
391 |
font-size: 0.9rem;
|
392 |
-
margin-top: 0.5rem;
|
393 |
}
|
394 |
"""
|
395 |
|
@@ -406,16 +410,20 @@ with gr.Blocks(css=custom_css, theme=gr.themes.Soft()) as iface:
|
|
406 |
)
|
407 |
|
408 |
with gr.Row():
|
409 |
-
|
410 |
-
|
411 |
-
|
412 |
-
|
413 |
-
|
414 |
-
|
415 |
-
|
416 |
-
|
417 |
-
|
418 |
-
|
|
|
|
|
|
|
|
|
419 |
with gr.Column(scale=1):
|
420 |
gr.HTML(
|
421 |
"""
|
@@ -426,6 +434,12 @@ with gr.Blocks(css=custom_css, theme=gr.themes.Soft()) as iface:
|
|
426 |
<li>Videos: MP4, AVI, MOV, WEBM</li>
|
427 |
</ul>
|
428 |
</div>
|
|
|
|
|
|
|
|
|
|
|
|
|
429 |
<div class="info-box">
|
430 |
<h4>Common Snags:</h4>
|
431 |
<div>
|
@@ -439,22 +453,22 @@ with gr.Blocks(css=custom_css, theme=gr.themes.Soft()) as iface:
|
|
439 |
</div>
|
440 |
"""
|
441 |
)
|
442 |
-
|
443 |
-
|
444 |
-
|
445 |
-
|
446 |
-
|
447 |
-
|
448 |
-
|
449 |
-
|
450 |
-
|
451 |
-
|
452 |
-
|
453 |
-
|
454 |
-
|
455 |
-
|
456 |
-
|
457 |
-
|
458 |
|
459 |
gr.HTML('<h3 class="section-title">Snag Detection Results</h3>')
|
460 |
chatbot = gr.Chatbot(
|
@@ -481,15 +495,40 @@ with gr.Blocks(css=custom_css, theme=gr.themes.Soft()) as iface:
|
|
481 |
gr.HTML(
|
482 |
"""
|
483 |
<div class="footer">
|
484 |
-
<div>
|
485 |
-
|
486 |
-
<div class="model-info">Model: llama-3.2-90b-vision-preview</div>
|
487 |
-
</div>
|
488 |
</div>
|
489 |
"""
|
490 |
)
|
491 |
|
492 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
493 |
|
494 |
# Launch the app
|
495 |
if __name__ == "__main__":
|
|
|
335 |
padding-bottom: 0.5rem;
|
336 |
}
|
337 |
|
338 |
+
.info-row {
|
339 |
+
display: flex;
|
340 |
+
gap: 1rem;
|
341 |
+
margin-bottom: 1.5rem;
|
342 |
+
}
|
343 |
+
|
344 |
.info-box {
|
345 |
+
flex: 1;
|
346 |
background-color: #E6F3FF;
|
347 |
border: 1px solid var(--secondary-color);
|
348 |
border-radius: 5px;
|
349 |
padding: 1rem;
|
|
|
350 |
font-size: 0.9rem;
|
351 |
}
|
352 |
|
|
|
356 |
margin-bottom: 0.5rem;
|
357 |
}
|
358 |
|
359 |
+
.info-box ul, .info-box ol {
|
360 |
margin: 0;
|
361 |
padding-left: 1.5rem;
|
362 |
}
|
|
|
379 |
display: flex;
|
380 |
justify-content: space-between;
|
381 |
align-items: center;
|
|
|
382 |
}
|
383 |
|
384 |
.groq-badge {
|
|
|
394 |
.model-info {
|
395 |
color: var(--text-color);
|
396 |
font-size: 0.9rem;
|
|
|
397 |
}
|
398 |
"""
|
399 |
|
|
|
410 |
)
|
411 |
|
412 |
with gr.Row():
|
413 |
+
gr.HTML('<h3 class="section-title">Upload Files</h3>')
|
414 |
+
|
415 |
+
with gr.Row():
|
416 |
+
file_input = gr.File(
|
417 |
+
label="Upload Construction Site Images or Videos",
|
418 |
+
file_count="multiple",
|
419 |
+
type="filepath",
|
420 |
+
elem_classes="file-upload-container"
|
421 |
+
)
|
422 |
+
|
423 |
+
with gr.Row():
|
424 |
+
analyze_button = gr.Button("🔍 Detect Snags", elem_classes="analyze-button")
|
425 |
+
|
426 |
+
with gr.Row(elem_classes="info-row"):
|
427 |
with gr.Column(scale=1):
|
428 |
gr.HTML(
|
429 |
"""
|
|
|
434 |
<li>Videos: MP4, AVI, MOV, WEBM</li>
|
435 |
</ul>
|
436 |
</div>
|
437 |
+
"""
|
438 |
+
)
|
439 |
+
|
440 |
+
with gr.Column(scale=1):
|
441 |
+
gr.HTML(
|
442 |
+
"""
|
443 |
<div class="info-box">
|
444 |
<h4>Common Snags:</h4>
|
445 |
<div>
|
|
|
453 |
</div>
|
454 |
"""
|
455 |
)
|
456 |
+
|
457 |
+
with gr.Column(scale=1):
|
458 |
+
gr.HTML(
|
459 |
+
"""
|
460 |
+
<div class="info-box">
|
461 |
+
<h4>How to use:</h4>
|
462 |
+
<ol>
|
463 |
+
<li>Upload images or videos of your construction site</li>
|
464 |
+
<li>Click "Detect Snags" to analyze the files</li>
|
465 |
+
<li>Review the detected snags in the chat area</li>
|
466 |
+
<li>Ask follow-up questions about the snags or request more information</li>
|
467 |
+
<li>Download a comprehensive report for your records</li>
|
468 |
+
</ol>
|
469 |
+
</div>
|
470 |
+
"""
|
471 |
+
)
|
472 |
|
473 |
gr.HTML('<h3 class="section-title">Snag Detection Results</h3>')
|
474 |
chatbot = gr.Chatbot(
|
|
|
495 |
gr.HTML(
|
496 |
"""
|
497 |
<div class="footer">
|
498 |
+
<div class="groq-badge">Powered by Groq</div>
|
499 |
+
<div class="model-info">Model: llama-3.2-90b-vision-preview</div>
|
|
|
|
|
500 |
</div>
|
501 |
"""
|
502 |
)
|
503 |
|
504 |
+
def process_files(files):
|
505 |
+
results = []
|
506 |
+
for file in files:
|
507 |
+
result = detect_snags(file)
|
508 |
+
results.append((file.name, result))
|
509 |
+
return results
|
510 |
+
|
511 |
+
def update_chat(history, new_messages):
|
512 |
+
history = history or []
|
513 |
+
for title, content in new_messages:
|
514 |
+
history.append((None, f"File: {title}\n\n{content}"))
|
515 |
+
return history
|
516 |
+
|
517 |
+
analyze_button.click(
|
518 |
+
process_files,
|
519 |
+
inputs=[file_input],
|
520 |
+
outputs=[chatbot],
|
521 |
+
postprocess=lambda x: update_chat(chatbot.value, x)
|
522 |
+
)
|
523 |
+
|
524 |
+
msg.submit(chat_about_snags, [msg, chatbot], [msg, chatbot])
|
525 |
+
clear.click(lambda: None, None, chatbot, queue=False)
|
526 |
+
|
527 |
+
download_button.click(
|
528 |
+
download_snag_report,
|
529 |
+
inputs=[chatbot],
|
530 |
+
outputs=[report_file]
|
531 |
+
)
|
532 |
|
533 |
# Launch the app
|
534 |
if __name__ == "__main__":
|