Spaces:
Running
Running
Sadjad Alikhani
commited on
Update app.py
Browse files
app.py
CHANGED
|
@@ -31,25 +31,6 @@ class PrintCapture(io.StringIO):
|
|
| 31 |
def get_output(self):
|
| 32 |
return ''.join(self.output)
|
| 33 |
|
| 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 |
# Function to create random images for LoS/NLoS classification results
|
| 54 |
def create_random_image(size=(300, 300)):
|
| 55 |
random_image = np.random.rand(*size, 3) * 255
|
|
@@ -161,7 +142,8 @@ def run_inference(uploaded_file):
|
|
| 161 |
sys.stdout = sys.__stdout__ # Reset print statements
|
| 162 |
|
| 163 |
# Function to handle classification after inference (using Gradio state)
|
| 164 |
-
def los_nlos_classification(
|
|
|
|
| 165 |
if output_emb is not None and output_raw is not None:
|
| 166 |
train_data_emb, test_data_emb, train_data_raw, test_data_raw, train_labels, test_labels = identical_train_test_split(
|
| 167 |
output_emb.view(len(output_emb), -1),
|
|
@@ -221,7 +203,7 @@ with gr.Blocks(css="""
|
|
| 221 |
# Handle dropdown change for classification
|
| 222 |
percentage_dropdown_los.change(
|
| 223 |
fn=los_nlos_classification,
|
| 224 |
-
inputs=[inference_output
|
| 225 |
outputs=[raw_img_los, embeddings_img_los, output_textbox]
|
| 226 |
)
|
| 227 |
|
|
|
|
| 31 |
def get_output(self):
|
| 32 |
return ''.join(self.output)
|
| 33 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 34 |
# Function to create random images for LoS/NLoS classification results
|
| 35 |
def create_random_image(size=(300, 300)):
|
| 36 |
random_image = np.random.rand(*size, 3) * 255
|
|
|
|
| 142 |
sys.stdout = sys.__stdout__ # Reset print statements
|
| 143 |
|
| 144 |
# Function to handle classification after inference (using Gradio state)
|
| 145 |
+
def los_nlos_classification(inference_output, percentage_idx):
|
| 146 |
+
output_emb, output_raw, labels = inference_output
|
| 147 |
if output_emb is not None and output_raw is not None:
|
| 148 |
train_data_emb, test_data_emb, train_data_raw, test_data_raw, train_labels, test_labels = identical_train_test_split(
|
| 149 |
output_emb.view(len(output_emb), -1),
|
|
|
|
| 203 |
# Handle dropdown change for classification
|
| 204 |
percentage_dropdown_los.change(
|
| 205 |
fn=los_nlos_classification,
|
| 206 |
+
inputs=[inference_output, percentage_dropdown_los],
|
| 207 |
outputs=[raw_img_los, embeddings_img_los, output_textbox]
|
| 208 |
)
|
| 209 |
|