Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
@@ -8,9 +8,9 @@ from transformers import DetrImageProcessor, DetrForObjectDetection
|
|
8 |
from diffusers import StableDiffusionPipeline
|
9 |
from huggingface_hub import login
|
10 |
import torchvision.transforms as T
|
|
|
11 |
|
12 |
# Load environment variables from .env file
|
13 |
-
from dotenv import load_dotenv
|
14 |
load_dotenv()
|
15 |
|
16 |
# Retrieve Hugging Face token from environment variable
|
@@ -18,6 +18,9 @@ HF_TOKEN = os.getenv("HF_TOKEN")
|
|
18 |
if HF_TOKEN is None:
|
19 |
raise ValueError("Hugging Face token not found in environment variables.")
|
20 |
|
|
|
|
|
|
|
21 |
# Load DETR model for object detection
|
22 |
def load_detr_model():
|
23 |
try:
|
@@ -45,8 +48,8 @@ def detect_objects(image):
|
|
45 |
# Load Stable Diffusion model for image generation
|
46 |
def load_stable_diffusion_model():
|
47 |
try:
|
48 |
-
|
49 |
-
pipeline = StableDiffusionPipeline.from_pretrained("CompVis/stable-diffusion-v1-4").to(
|
50 |
return pipeline, None
|
51 |
except Exception as e:
|
52 |
return None, f"Error loading Stable Diffusion model: {str(e)}"
|
@@ -72,7 +75,6 @@ def process_image(image):
|
|
72 |
return None, detect_error
|
73 |
|
74 |
# Generate a modern redesign of the image based on the detected objects
|
75 |
-
# For simplicity, we'll use a fixed prompt for image generation
|
76 |
prompt = "modern redesign of an interior room"
|
77 |
generated_image, gen_image_error = generate_image(prompt)
|
78 |
if gen_image_error:
|
@@ -97,4 +99,4 @@ try:
|
|
97 |
iface.launch()
|
98 |
except Exception as e:
|
99 |
print(f"Error occurred while launching the interface: {str(e)}")
|
100 |
-
traceback.print_exc()
|
|
|
8 |
from diffusers import StableDiffusionPipeline
|
9 |
from huggingface_hub import login
|
10 |
import torchvision.transforms as T
|
11 |
+
from dotenv import load_dotenv
|
12 |
|
13 |
# Load environment variables from .env file
|
|
|
14 |
load_dotenv()
|
15 |
|
16 |
# Retrieve Hugging Face token from environment variable
|
|
|
18 |
if HF_TOKEN is None:
|
19 |
raise ValueError("Hugging Face token not found in environment variables.")
|
20 |
|
21 |
+
# Login to Hugging Face using the token
|
22 |
+
login(token=HF_TOKEN)
|
23 |
+
|
24 |
# Load DETR model for object detection
|
25 |
def load_detr_model():
|
26 |
try:
|
|
|
48 |
# Load Stable Diffusion model for image generation
|
49 |
def load_stable_diffusion_model():
|
50 |
try:
|
51 |
+
device = "cuda" if torch.cuda.is_available() else "cpu"
|
52 |
+
pipeline = StableDiffusionPipeline.from_pretrained("CompVis/stable-diffusion-v1-4").to(device)
|
53 |
return pipeline, None
|
54 |
except Exception as e:
|
55 |
return None, f"Error loading Stable Diffusion model: {str(e)}"
|
|
|
75 |
return None, detect_error
|
76 |
|
77 |
# Generate a modern redesign of the image based on the detected objects
|
|
|
78 |
prompt = "modern redesign of an interior room"
|
79 |
generated_image, gen_image_error = generate_image(prompt)
|
80 |
if gen_image_error:
|
|
|
99 |
iface.launch()
|
100 |
except Exception as e:
|
101 |
print(f"Error occurred while launching the interface: {str(e)}")
|
102 |
+
traceback.print_exc()
|