BLUEPRINT-COMP / app.py
Pushpanjali
adding files
b6c906b
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)