Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,5 +1,17 @@
|
|
| 1 |
-
import
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 2 |
import torch
|
|
|
|
|
|
|
| 3 |
import numpy as np
|
| 4 |
from PIL import Image
|
| 5 |
import os
|
|
@@ -20,15 +32,6 @@ args = parser.parse_args()
|
|
| 20 |
|
| 21 |
|
| 22 |
|
| 23 |
-
# try:
|
| 24 |
-
# import spaces
|
| 25 |
-
# GPU = spaces.GPU
|
| 26 |
-
# except ImportError:
|
| 27 |
-
# # Define a no-op decorator if running locally
|
| 28 |
-
# def GPU(func):
|
| 29 |
-
# return func
|
| 30 |
-
import spaces
|
| 31 |
-
|
| 32 |
# Create model directories if they don't exist
|
| 33 |
os.makedirs("models", exist_ok=True)
|
| 34 |
os.makedirs("stimuli", exist_ok=True)
|
|
@@ -36,7 +39,7 @@ os.makedirs("stimuli", exist_ok=True)
|
|
| 36 |
# Initialize model
|
| 37 |
model = GenerativeInferenceModel()
|
| 38 |
|
| 39 |
-
@
|
| 40 |
def run_inference(image, model_type, illusion_type, eps_value, num_iterations):
|
| 41 |
# Convert eps to float
|
| 42 |
eps = float(eps_value)
|
|
|
|
| 1 |
+
import os
|
| 2 |
+
|
| 3 |
+
# If running on Hugging Face Spaces, import the GPU decorator
|
| 4 |
+
if "SPACE_ID" in os.environ:
|
| 5 |
+
from spaces.zero.decorator import GPU
|
| 6 |
+
else:
|
| 7 |
+
# Define a dummy GPU decorator when running locally
|
| 8 |
+
def GPU(func):
|
| 9 |
+
return func
|
| 10 |
+
|
| 11 |
+
# Now you can safely import torch and other libraries
|
| 12 |
import torch
|
| 13 |
+
import gradio as gr
|
| 14 |
+
|
| 15 |
import numpy as np
|
| 16 |
from PIL import Image
|
| 17 |
import os
|
|
|
|
| 32 |
|
| 33 |
|
| 34 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 35 |
# Create model directories if they don't exist
|
| 36 |
os.makedirs("models", exist_ok=True)
|
| 37 |
os.makedirs("stimuli", exist_ok=True)
|
|
|
|
| 39 |
# Initialize model
|
| 40 |
model = GenerativeInferenceModel()
|
| 41 |
|
| 42 |
+
@GPU
|
| 43 |
def run_inference(image, model_type, illusion_type, eps_value, num_iterations):
|
| 44 |
# Convert eps to float
|
| 45 |
eps = float(eps_value)
|