File size: 1,941 Bytes
a0aad55
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
b6c906b
a0aad55
 
 
 
 
 
b6c906b
 
a0aad55
b6c906b
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
54
55
56
57
import gradio as gr
from PIL import Image 
import numpy as np
from seg_llm_function import chat_seg_model
from llm_function import chat_claude , prompt

def final_func(img1 , img2) :
    llm_resp = chat_claude(prompt , img1 , img2)
    seg_resp = chat_seg_model(img1 , img2)
    return llm_resp , seg_resp


# def process_image(image1 , image2):
#     # Convert the input to a PIL Image object if it's not already
#     if isinstance(image, str):
#         image = Image.open(image)
    
#     # Resize the image to fit within a 400x400 pixel box while maintaining aspect ratio
#     max_size = 400
#     width, height = image.size
#     new_width = min(width, max_size)
#     new_height = int(max_size * height / width)
#     image = image.resize((new_width, new_height))
    
#     # Convert the image back to a numpy array for Gradio output
#     return np.array(image)

from ultralytics import YOLO

# 1. Load a YOLOv8 segmentation model (pre-trained weights)
model = YOLO("best.pt")

def display_image(img1 , img2) :
    # if isinstance(img1 , img2 , str) :
    image1 = Image.open(img1) 
    # if isinstance(img2 , str) :
    image2 = Image.open(img2) 
    return image1 , image2


gr.Interface(
    fn=final_func,
    inputs=[gr.Image(type="filepath" , interactive = True), gr.Image(type="filepath" , interactive = True)],
    # outputs=[gr.Image(), gr.Image()],
    # outputs = ["text" , "text"] ,
    outputs = [gr.Markdown(label = "##VLM" , show_copy_button = True, container = True , height = 300) , gr.Markdown(label = "##SEG-VLM" , show_copy_button = True  , container = True , height = 300)],
    title="Blueprint Comparison : VLM & SEG-VLM",
    description="Upload two construstion blueprints to know differences between them." ,
    flagging_mode = "never",
    fill_width = True ,
    submit_btn = "Compare",
    show_progress = "full",
    theme = "soft",
    analytics_enabled = True

).launch(pwa = True , share = True)