oshankagrawal commited on
Commit
086637a
·
verified ·
1 Parent(s): 7f34602

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +105 -0
app.py CHANGED
@@ -0,0 +1,105 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import gradio as gr
2
+ import torch
3
+ from PIL import Image
4
+ from unsloth import FastVisionModel
5
+
6
+
7
+ MODEL_NAME = "sabaridsnfuji/FloorPlanVisionAIAdaptor"
8
+
9
+
10
+ print("Loading model...")
11
+
12
+ model, tokenizer = FastVisionModel.from_pretrained(
13
+ MODEL_NAME,
14
+ load_in_4bit=True,
15
+ use_gradient_checkpointing="unsloth"
16
+ )
17
+
18
+ FastVisionModel.for_inference(model)
19
+
20
+ print("Model loaded successfully!")
21
+ print("CUDA available:", torch.cuda.is_available())
22
+
23
+ if torch.cuda.is_available():
24
+ print("GPU:", torch.cuda.get_device_name(0))
25
+
26
+
27
+ def analyze_floorplan(image, instruction):
28
+
29
+ if image is None:
30
+ return "Please upload a floor plan image."
31
+
32
+ if not instruction:
33
+ instruction = """
34
+ You are an expert in architecture and interior design.
35
+ Analyze the floor plan image carefully.
36
+
37
+ Describe:
38
+ 1. Number of rooms
39
+ 2. Room names
40
+ 3. Approximate layout
41
+ 4. Connections between rooms
42
+ 5. Doors and windows if visible
43
+ 6. Important architectural features
44
+ 7. Any other useful observations
45
+ """
46
+
47
+ messages = [
48
+ {
49
+ "role": "user",
50
+ "content": [
51
+ {"type": "image"},
52
+ {"type": "text", "text": instruction}
53
+ ]
54
+ }
55
+ ]
56
+
57
+ input_text = tokenizer.apply_chat_template(
58
+ messages,
59
+ add_generation_prompt=True
60
+ )
61
+
62
+ inputs = tokenizer(
63
+ image,
64
+ input_text,
65
+ add_special_tokens=False,
66
+ return_tensors="pt"
67
+ ).to("cuda")
68
+
69
+ outputs = model.generate(
70
+ **inputs,
71
+ max_new_tokens=1024,
72
+ use_cache=True
73
+ )
74
+
75
+ generated_text = tokenizer.decode(
76
+ outputs[0],
77
+ skip_special_tokens=True
78
+ )
79
+
80
+ return generated_text
81
+
82
+
83
+ demo = gr.Interface(
84
+ fn=analyze_floorplan,
85
+ inputs=[
86
+ gr.Image(
87
+ type="pil",
88
+ label="Upload Floor Plan"
89
+ ),
90
+ gr.Textbox(
91
+ label="Instruction",
92
+ placeholder="Ask something about the floor plan...",
93
+ value="Analyze this floor plan in detail."
94
+ )
95
+ ],
96
+ outputs=gr.Textbox(
97
+ label="Analysis"
98
+ ),
99
+ title="Floor Plan Vision AI",
100
+ description="AI-powered floor plan analysis using FloorPlanVisionAIAdaptor."
101
+ )
102
+
103
+
104
+ if __name__ == "__main__":
105
+ demo.launch()