File size: 1,228 Bytes
c858478
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
51
52
53
import gradio as gr
import cv2
import numpy as np

from src.pipeline import run_pipeline
from src.scene_graph import build_graph
from src.visualization import visualize_graph
from src.text_generation import graph_to_text   


def process_image(image):
    try:
        
        image_cv = cv2.cvtColor(np.array(image), cv2.COLOR_RGB2BGR)

        
        relations = run_pipeline(image_cv)

        if not relations or len(relations) == 0:
            return image, None, "No relationships detected."

     
        G = build_graph(relations)

       
        fig = visualize_graph(G)

     
        caption = graph_to_text(relations)

        return image, fig, caption

    except Exception as e:
        print("Error:", e)
        return image, None, "Error processing image."


demo = gr.Interface(
    fn=process_image,
    inputs=gr.Image(type="pil"),
    outputs=[
        gr.Image(label="Input Image"),
        gr.Plot(label="Scene Graph"),
        gr.Textbox(label="Generated Description")  
    ],
    title="Scene Graph Generator",
    description="Upload an image → Detect objects → Predict relationships → Generate scene graph + description",
    theme="soft"
)


if __name__ == "__main__":
    demo.launch()