Spaces:
Running
Running
Sadjad Alikhani
commited on
Update app.py
Browse files
app.py
CHANGED
@@ -34,14 +34,31 @@ class PrintCapture(io.StringIO):
|
|
34 |
# Function to load and display predefined images based on user selection
|
35 |
def display_predefined_images(percentage_idx):
|
36 |
percentage = percentage_values[percentage_idx]
|
37 |
-
raw_image_path = os.path.join(RAW_PATH, f"percentage_{percentage}_complexity_16.png")
|
38 |
embeddings_image_path = os.path.join(EMBEDDINGS_PATH, f"percentage_{percentage}_complexity_16.png")
|
39 |
|
40 |
-
|
41 |
-
|
|
|
|
|
|
|
42 |
|
|
|
|
|
|
|
|
|
|
|
43 |
return raw_image, embeddings_image
|
44 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
45 |
# Function to create random images for LoS/NLoS classification results
|
46 |
def create_random_image(size=(300, 300)):
|
47 |
random_image = np.random.rand(*size, 3) * 255
|
@@ -227,13 +244,6 @@ def process_hdf5_file(uploaded_file, percentage_idx):
|
|
227 |
os.chdir(original_dir)
|
228 |
sys.stdout = sys.__stdout__ # Reset print statements
|
229 |
|
230 |
-
# Function to handle logic based on whether a file is uploaded or not
|
231 |
-
def los_nlos_classification(file, percentage_idx):
|
232 |
-
if file is not None:
|
233 |
-
return process_hdf5_file(file, percentage_idx)
|
234 |
-
else:
|
235 |
-
return display_predefined_images(percentage_idx), None
|
236 |
-
|
237 |
# Define the Gradio interface
|
238 |
with gr.Blocks(css="""
|
239 |
.vertical-slider input[type=range] {
|
|
|
34 |
# Function to load and display predefined images based on user selection
|
35 |
def display_predefined_images(percentage_idx):
|
36 |
percentage = percentage_values[percentage_idx]
|
37 |
+
raw_image_path = os.path.join(RAW_PATH, f"percentage_{percentage}_complexity_16.png")
|
38 |
embeddings_image_path = os.path.join(EMBEDDINGS_PATH, f"percentage_{percentage}_complexity_16.png")
|
39 |
|
40 |
+
# Check if the images exist
|
41 |
+
if os.path.exists(raw_image_path):
|
42 |
+
raw_image = Image.open(raw_image_path)
|
43 |
+
else:
|
44 |
+
raw_image = create_random_image() # Use a fallback random image
|
45 |
|
46 |
+
if os.path.exists(embeddings_image_path):
|
47 |
+
embeddings_image = Image.open(embeddings_image_path)
|
48 |
+
else:
|
49 |
+
embeddings_image = create_random_image() # Use a fallback random image
|
50 |
+
|
51 |
return raw_image, embeddings_image
|
52 |
|
53 |
+
# Updated los_nlos_classification to handle missing outputs properly
|
54 |
+
def los_nlos_classification(file, percentage_idx):
|
55 |
+
if file is not None:
|
56 |
+
raw_cm_image, emb_cm_image, console_output = process_hdf5_file(file, percentage_idx)
|
57 |
+
return raw_cm_image, emb_cm_image, console_output
|
58 |
+
else:
|
59 |
+
raw_image, embeddings_image = display_predefined_images(percentage_idx)
|
60 |
+
return raw_image, embeddings_image, "No file uploaded. Displaying predefined images."
|
61 |
+
|
62 |
# Function to create random images for LoS/NLoS classification results
|
63 |
def create_random_image(size=(300, 300)):
|
64 |
random_image = np.random.rand(*size, 3) * 255
|
|
|
244 |
os.chdir(original_dir)
|
245 |
sys.stdout = sys.__stdout__ # Reset print statements
|
246 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
247 |
# Define the Gradio interface
|
248 |
with gr.Blocks(css="""
|
249 |
.vertical-slider input[type=range] {
|