File size: 1,509 Bytes
4716bb5
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
import gradio as gr
from transformers import pipeline

from detection_utils import render_results_in_image, summarize_predictions_natural_language

obj_detector = pipeline(
    task = "object-detection",
    model = "facebook/detr-resnet-50"
)

def get_pipeline_prediction(pil_image):
    pipeline_output = obj_detector(pil_image)
    processed_image = render_results_in_image(
        pil_image, 
        pipeline_output
    )
    detection_summary = summarize_predictions_natural_language(pipeline_output)
    return processed_image, detection_summary

detection_interface = gr.Interface(
    fn = get_pipeline_prediction,
    inputs = gr.Image(
        label = "Input Image",
        type = 'pil'
    ),
    outputs = [gr.Image(
    label = "Output image with predicted instances",
    type = 'pil'
    ),
    gr.Textbox(label="Detection Summary")],
    allow_flagging = 'never'
    
)

# Add Markdown content
markdown_content_detection = gr.Markdown(
    """

    <div style='text-align: center; font-family: "Times New Roman";'>

        <h1 style='color: #FF6347;'>Object Detection with Summary</h1>

        <h3 style='color: #4682B4;'>Model: facebook/detr-resnet-50</h3>

        <h3 style='color: #32CD32;'>Made By: Md. Mahmudun Nabi</h3>

    </div>

    """
)

# Combine the Markdown content and the demo interface
detection_with_markdown = gr.Blocks()
with detection_with_markdown:
    markdown_content_detection.render()
    detection_interface.render()