Spaces:
Running
Running
Sadjad Alikhani
commited on
Update app.py
Browse files
app.py
CHANGED
@@ -1,3 +1,34 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
import torch
|
2 |
from transformers import AutoModel # Assuming you use a transformer-like model in your LWM repo
|
3 |
import numpy as np
|
@@ -50,3 +81,90 @@ def process_python_file(uploaded_file, percentage_idx, complexity_idx):
|
|
50 |
|
51 |
except Exception as e:
|
52 |
return str(e), str(e)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import gradio as gr
|
2 |
+
import os
|
3 |
+
from PIL import Image
|
4 |
+
import numpy as np
|
5 |
+
|
6 |
+
# Paths to the predefined images folder
|
7 |
+
RAW_PATH = os.path.join("images", "raw")
|
8 |
+
EMBEDDINGS_PATH = os.path.join("images", "embeddings")
|
9 |
+
GENERATED_PATH = os.path.join("images", "generated")
|
10 |
+
|
11 |
+
# Specific values for percentage and complexity
|
12 |
+
percentage_values = [10, 30, 50, 70, 100]
|
13 |
+
complexity_values = [16, 32]
|
14 |
+
|
15 |
+
# Function to load and display predefined images based on user selection
|
16 |
+
def display_predefined_images(percentage_idx, complexity_idx):
|
17 |
+
# Map the slider index to the actual value
|
18 |
+
percentage = percentage_values[percentage_idx]
|
19 |
+
complexity = complexity_values[complexity_idx]
|
20 |
+
|
21 |
+
# Generate the paths to the images
|
22 |
+
raw_image_path = os.path.join(RAW_PATH, f"percentage_{percentage}_complexity_{complexity}.png")
|
23 |
+
embeddings_image_path = os.path.join(EMBEDDINGS_PATH, f"percentage_{percentage}_complexity_{complexity}.png")
|
24 |
+
|
25 |
+
# Load images using PIL
|
26 |
+
raw_image = Image.open(raw_image_path)
|
27 |
+
embeddings_image = Image.open(embeddings_image_path)
|
28 |
+
|
29 |
+
# Return the loaded images
|
30 |
+
return raw_image, embeddings_image
|
31 |
+
|
32 |
import torch
|
33 |
from transformers import AutoModel # Assuming you use a transformer-like model in your LWM repo
|
34 |
import numpy as np
|
|
|
81 |
|
82 |
except Exception as e:
|
83 |
return str(e), str(e)
|
84 |
+
|
85 |
+
|
86 |
+
# Function to handle logic based on whether a file is uploaded or not
|
87 |
+
def los_nlos_classification(file, percentage_idx, complexity_idx):
|
88 |
+
if file is not None:
|
89 |
+
# Process the uploaded file and generate new images
|
90 |
+
return process_python_file(file, percentage_idx, complexity_idx)
|
91 |
+
else:
|
92 |
+
# Display predefined images if no file is uploaded
|
93 |
+
return display_predefined_images(percentage_idx, complexity_idx)
|
94 |
+
|
95 |
+
# Define the Gradio interface
|
96 |
+
with gr.Blocks(css="""
|
97 |
+
.vertical-slider input[type=range] {
|
98 |
+
writing-mode: bt-lr; /* IE */
|
99 |
+
-webkit-appearance: slider-vertical; /* WebKit */
|
100 |
+
width: 8px;
|
101 |
+
height: 200px;
|
102 |
+
}
|
103 |
+
.slider-container {
|
104 |
+
display: inline-block;
|
105 |
+
margin-right: 50px;
|
106 |
+
text-align: center;
|
107 |
+
}
|
108 |
+
""") as demo:
|
109 |
+
|
110 |
+
# Contact Section
|
111 |
+
gr.Markdown(
|
112 |
+
"""
|
113 |
+
## Contact
|
114 |
+
<div style="display: flex; align-items: center;">
|
115 |
+
<a target="_blank" href="mailto:info@wirelessmodel.com"><img src="https://img.shields.io/badge/email-info@wirelessmodel.com-blue.svg?logo=gmail " alt="Email"></a>
|
116 |
+
<a target="_blank" href="https://telegram.me/wirelessmodel"><img src="https://img.shields.io/badge/telegram-@wirelessmodel-blue.svg?logo=telegram " alt="Telegram"></a>
|
117 |
+
</div>
|
118 |
+
"""
|
119 |
+
)
|
120 |
+
|
121 |
+
# Tabs for Beam Prediction and LoS/NLoS Classification
|
122 |
+
with gr.Tab("Beam Prediction Task"):
|
123 |
+
gr.Markdown("### Beam Prediction Task")
|
124 |
+
|
125 |
+
# Sliders for percentage and complexity
|
126 |
+
with gr.Row():
|
127 |
+
with gr.Column(elem_id="slider-container"):
|
128 |
+
gr.Markdown("Percentage of Data for Training")
|
129 |
+
percentage_slider_bp = gr.Slider(minimum=0, maximum=4, step=1, value=0, interactive=True, elem_id="vertical-slider")
|
130 |
+
with gr.Column(elem_id="slider-container"):
|
131 |
+
gr.Markdown("Task Complexity")
|
132 |
+
complexity_slider_bp = gr.Slider(minimum=0, maximum=1, step=1, value=0, interactive=True, elem_id="vertical-slider")
|
133 |
+
|
134 |
+
# Image outputs (display the images side by side and set a smaller size for the images)
|
135 |
+
with gr.Row():
|
136 |
+
raw_img_bp = gr.Image(label="Raw Channels", type="pil", width=300, height=300, interactive=False)
|
137 |
+
embeddings_img_bp = gr.Image(label="Embeddings", type="pil", width=300, height=300, interactive=False)
|
138 |
+
|
139 |
+
# Instant image updates when sliders change
|
140 |
+
percentage_slider_bp.change(fn=display_predefined_images, inputs=[percentage_slider_bp, complexity_slider_bp], outputs=[raw_img_bp, embeddings_img_bp])
|
141 |
+
complexity_slider_bp.change(fn=display_predefined_images, inputs=[percentage_slider_bp, complexity_slider_bp], outputs=[raw_img_bp, embeddings_img_bp])
|
142 |
+
|
143 |
+
with gr.Tab("LoS/NLoS Classification Task"):
|
144 |
+
gr.Markdown("### LoS/NLoS Classification Task")
|
145 |
+
|
146 |
+
# File uploader for uploading .py file
|
147 |
+
file_input = gr.File(label="Upload .py File", file_types=[".py"])
|
148 |
+
|
149 |
+
# Sliders for percentage and complexity
|
150 |
+
with gr.Row():
|
151 |
+
with gr.Column(elem_id="slider-container"):
|
152 |
+
gr.Markdown("Percentage of Data for Training")
|
153 |
+
percentage_slider_los = gr.Slider(minimum=0, maximum=4, step=1, value=0, interactive=True, elem_id="vertical-slider")
|
154 |
+
with gr.Column(elem_id="slider-container"):
|
155 |
+
gr.Markdown("Task Complexity")
|
156 |
+
complexity_slider_los = gr.Slider(minimum=0, maximum=1, step=1, value=0, interactive=True, elem_id="vertical-slider")
|
157 |
+
|
158 |
+
# Image outputs (display the images side by side and set a smaller size for the images)
|
159 |
+
with gr.Row():
|
160 |
+
raw_img_los = gr.Image(label="Raw Channels", type="pil", width=300, height=300, interactive=False)
|
161 |
+
embeddings_img_los = gr.Image(label="Embeddings", type="pil", width=300, height=300, interactive=False)
|
162 |
+
|
163 |
+
# Instant image updates based on file upload or slider changes
|
164 |
+
file_input.change(fn=los_nlos_classification, inputs=[file_input, percentage_slider_los, complexity_slider_los], outputs=[raw_img_los, embeddings_img_los])
|
165 |
+
percentage_slider_los.change(fn=los_nlos_classification, inputs=[file_input, percentage_slider_los, complexity_slider_los], outputs=[raw_img_los, embeddings_img_los])
|
166 |
+
complexity_slider_los.change(fn=los_nlos_classification, inputs=[file_input, percentage_slider_los, complexity_slider_los], outputs=[raw_img_los, embeddings_img_los])
|
167 |
+
|
168 |
+
# Launch the app
|
169 |
+
if __name__ == "__main__":
|
170 |
+
demo.launch()
|