Msaqibsharif commited on
Commit
b17a5ec
·
verified ·
1 Parent(s): 8b827ad

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +29 -10
app.py CHANGED
@@ -1,12 +1,10 @@
1
  import os
2
  import torch
3
- from PIL import Image, ImageDraw
4
- import numpy as np
5
  import gradio as gr
6
  from transformers import DetrImageProcessor, DetrForObjectDetection
7
  from diffusers import StableDiffusionPipeline
8
  from huggingface_hub import login
9
- import torchvision.transforms as T
10
  from dotenv import load_dotenv
11
 
12
  # Load environment variables from .env file
@@ -14,6 +12,7 @@ load_dotenv()
14
 
15
  # Retrieve Hugging Face token from environment variable
16
  HF_TOKEN = os.getenv('HF_TOKEN')
 
17
  if HF_TOKEN is None:
18
  raise ValueError("Hugging Face token not found in environment variables.")
19
 
@@ -32,6 +31,9 @@ def load_detr_model():
32
  detr_model, detr_processor, detr_error = load_detr_model()
33
 
34
  def detect_objects(image):
 
 
 
35
  if detr_model is not None and detr_processor is not None:
36
  try:
37
  inputs = detr_processor(images=image, return_tensors="pt")
@@ -81,6 +83,9 @@ def generate_image(prompt, width, height):
81
  return None, "Stable Diffusion model not loaded. Skipping image generation."
82
 
83
  def process_image(image):
 
 
 
84
  try:
85
  # Detect objects in the provided image
86
  detected_objects, detect_error = detect_objects(image)
@@ -104,15 +109,29 @@ def process_image(image):
104
  except Exception as e:
105
  return None, f"Error in process_image: {str(e)}"
106
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
107
  iface = gr.Interface(
108
  fn=process_image,
109
- inputs=[
110
- gr.Image(type="pil", label="Upload Room Image")
111
- ],
112
- outputs=[
113
- gr.Image(type="pil", label="Redesigned Image"),
114
- gr.Textbox(label="Error Message")
115
- ]
116
  )
117
 
118
  try:
 
1
  import os
2
  import torch
3
+ from PIL import Image
 
4
  import gradio as gr
5
  from transformers import DetrImageProcessor, DetrForObjectDetection
6
  from diffusers import StableDiffusionPipeline
7
  from huggingface_hub import login
 
8
  from dotenv import load_dotenv
9
 
10
  # Load environment variables from .env file
 
12
 
13
  # Retrieve Hugging Face token from environment variable
14
  HF_TOKEN = os.getenv('HF_TOKEN')
15
+
16
  if HF_TOKEN is None:
17
  raise ValueError("Hugging Face token not found in environment variables.")
18
 
 
31
  detr_model, detr_processor, detr_error = load_detr_model()
32
 
33
  def detect_objects(image):
34
+ if image is None:
35
+ return None, "Invalid image: image is None."
36
+
37
  if detr_model is not None and detr_processor is not None:
38
  try:
39
  inputs = detr_processor(images=image, return_tensors="pt")
 
83
  return None, "Stable Diffusion model not loaded. Skipping image generation."
84
 
85
  def process_image(image):
86
+ if image is None:
87
+ return None, "Invalid image: image is None."
88
+
89
  try:
90
  # Detect objects in the provided image
91
  detected_objects, detect_error = detect_objects(image)
 
109
  except Exception as e:
110
  return None, f"Error in process_image: {str(e)}"
111
 
112
+ # Custom CSS for styling
113
+ custom_css = """
114
+ body {
115
+ background-color: black;
116
+ }
117
+
118
+ h1 {
119
+ background: linear-gradient(to right, blue, purple);
120
+ -webkit-background-clip: text;
121
+ color: transparent;
122
+ font-size: 3em;
123
+ text-align: center;
124
+ margin-bottom: 20px;
125
+ }
126
+ """
127
+
128
+ # Creating the Gradio interface with custom styling
129
  iface = gr.Interface(
130
  fn=process_image,
131
+ inputs=[gr.Image(type="pil", label="Upload Room Image")],
132
+ outputs=[gr.Image(type="pil", label="Redesigned Image"), gr.Textbox(label="Error Message")],
133
+ title="Interior Redesign",
134
+ css=custom_css
 
 
 
135
  )
136
 
137
  try: