Update app.py
Browse files
app.py
CHANGED
|
@@ -16,8 +16,6 @@ import tempfile
|
|
| 16 |
import base64
|
| 17 |
import plotly.graph_objects as go
|
| 18 |
from plotly.subplots import make_subplots
|
| 19 |
-
import matplotlib.pyplot as plt
|
| 20 |
-
from matplotlib import cm
|
| 21 |
|
| 22 |
# Load the emotion prediction model
|
| 23 |
def load_emotion_model(model_path):
|
|
@@ -191,18 +189,21 @@ def generate_image(emotion_prediction, transcribed_text):
|
|
| 191 |
# Function to create a visualization with both the equirectangular image and a 3D sphere
|
| 192 |
def create_texture_and_sphere_preview(image):
|
| 193 |
try:
|
|
|
|
|
|
|
|
|
|
| 194 |
# Create a subplot with the equirectangular image and a 3D sphere
|
| 195 |
fig = make_subplots(
|
| 196 |
rows=1, cols=2,
|
| 197 |
subplot_titles=("Equirectangular Texture", "3D Sphere Preview"),
|
| 198 |
-
specs=[[{"type": "image"}, {"type": "scatter3d"}]]
|
|
|
|
| 199 |
)
|
| 200 |
|
| 201 |
-
# Add the equirectangular image
|
| 202 |
-
img_array = np.array(image)
|
| 203 |
fig.add_trace(go.Image(z=img_array), row=1, col=1)
|
| 204 |
|
| 205 |
-
# Create a 3D sphere
|
| 206 |
# Since we can't directly apply the texture, we'll create a colored sphere
|
| 207 |
u = np.linspace(0, 2 * np.pi, 50)
|
| 208 |
v = np.linspace(0, np.pi, 25)
|
|
@@ -230,6 +231,10 @@ def create_texture_and_sphere_preview(image):
|
|
| 230 |
showlegend=False
|
| 231 |
)
|
| 232 |
|
|
|
|
|
|
|
|
|
|
|
|
|
| 233 |
# Update 3D scene settings
|
| 234 |
fig.update_scenes(
|
| 235 |
aspectmode='data',
|
|
@@ -242,78 +247,6 @@ def create_texture_and_sphere_preview(image):
|
|
| 242 |
print("Error creating texture and sphere preview:", e)
|
| 243 |
return go.Figure()
|
| 244 |
|
| 245 |
-
# Function to create a detailed explanation figure
|
| 246 |
-
def create_detailed_preview(image):
|
| 247 |
-
try:
|
| 248 |
-
# Create a more detailed visualization
|
| 249 |
-
fig = make_subplots(
|
| 250 |
-
rows=2, cols=2,
|
| 251 |
-
subplot_titles=(
|
| 252 |
-
"Equirectangular Texture",
|
| 253 |
-
"3D Sphere Preview",
|
| 254 |
-
"Texture Mapping Diagram",
|
| 255 |
-
"How It Works"
|
| 256 |
-
),
|
| 257 |
-
specs=[
|
| 258 |
-
[{"type": "image"}, {"type": "scatter3d"}],
|
| 259 |
-
[{"type": "xy"}, {"type": "xy"}]
|
| 260 |
-
]
|
| 261 |
-
)
|
| 262 |
-
|
| 263 |
-
# Add the equirectangular image
|
| 264 |
-
img_array = np.array(image)
|
| 265 |
-
fig.add_trace(go.Image(z=img_array), row=1, col=1)
|
| 266 |
-
|
| 267 |
-
# Create a 3D sphere
|
| 268 |
-
u = np.linspace(0, 2 * np.pi, 30)
|
| 269 |
-
v = np.linspace(0, np.pi, 15)
|
| 270 |
-
u, v = np.meshgrid(u, v)
|
| 271 |
-
|
| 272 |
-
x = np.sin(v) * np.cos(u)
|
| 273 |
-
y = np.sin(v) * np.sin(u)
|
| 274 |
-
z = np.cos(v)
|
| 275 |
-
|
| 276 |
-
fig.add_trace(go.Surface(
|
| 277 |
-
x=x, y=y, z=z,
|
| 278 |
-
surfacecolor=z,
|
| 279 |
-
colorscale='Viridis',
|
| 280 |
-
showscale=False,
|
| 281 |
-
opacity=0.8
|
| 282 |
-
), row=1, col=2)
|
| 283 |
-
|
| 284 |
-
# Add a diagram showing how equirectangular mapping works
|
| 285 |
-
x_diagram = [0, 1, 1, 0, 0]
|
| 286 |
-
y_diagram = [0, 0, 1, 1, 0]
|
| 287 |
-
fig.add_trace(go.Scatter(x=x_diagram, y=y_diagram, fill="toself"), row=2, col=1)
|
| 288 |
-
|
| 289 |
-
# Add text explanation
|
| 290 |
-
fig.add_annotation(
|
| 291 |
-
x=0.5, y=0.5,
|
| 292 |
-
xref="x domain", yref="y domain",
|
| 293 |
-
text="Equirectangular images wrap around spheres to create 360° environments",
|
| 294 |
-
showarrow=False,
|
| 295 |
-
row=2, col=2
|
| 296 |
-
)
|
| 297 |
-
|
| 298 |
-
# Update layout
|
| 299 |
-
fig.update_layout(
|
| 300 |
-
height=600,
|
| 301 |
-
title_text="360° Environment Creation Process",
|
| 302 |
-
showlegend=False
|
| 303 |
-
)
|
| 304 |
-
|
| 305 |
-
# Update axes for diagram
|
| 306 |
-
fig.update_xaxes(visible=False, row=2, col=1)
|
| 307 |
-
fig.update_yaxes(visible=False, row=2, col=1)
|
| 308 |
-
fig.update_xaxes(visible=False, row=2, col=2)
|
| 309 |
-
fig.update_yaxes(visible=False, row=2, col=2)
|
| 310 |
-
|
| 311 |
-
return fig
|
| 312 |
-
|
| 313 |
-
except Exception as e:
|
| 314 |
-
print("Error creating detailed preview:", e)
|
| 315 |
-
return go.Figure()
|
| 316 |
-
|
| 317 |
# Function to get predictions
|
| 318 |
def get_predictions(audio_input):
|
| 319 |
emotion_prediction = predict_emotion_from_audio(audio_input)
|
|
|
|
| 16 |
import base64
|
| 17 |
import plotly.graph_objects as go
|
| 18 |
from plotly.subplots import make_subplots
|
|
|
|
|
|
|
| 19 |
|
| 20 |
# Load the emotion prediction model
|
| 21 |
def load_emotion_model(model_path):
|
|
|
|
| 189 |
# Function to create a visualization with both the equirectangular image and a 3D sphere
|
| 190 |
def create_texture_and_sphere_preview(image):
|
| 191 |
try:
|
| 192 |
+
# Convert PIL image to numpy array for display
|
| 193 |
+
img_array = np.array(image)
|
| 194 |
+
|
| 195 |
# Create a subplot with the equirectangular image and a 3D sphere
|
| 196 |
fig = make_subplots(
|
| 197 |
rows=1, cols=2,
|
| 198 |
subplot_titles=("Equirectangular Texture", "3D Sphere Preview"),
|
| 199 |
+
specs=[[{"type": "image"}, {"type": "scatter3d"}]],
|
| 200 |
+
horizontal_spacing=0.1
|
| 201 |
)
|
| 202 |
|
| 203 |
+
# Add the equirectangular image to the first subplot
|
|
|
|
| 204 |
fig.add_trace(go.Image(z=img_array), row=1, col=1)
|
| 205 |
|
| 206 |
+
# Create a 3D sphere for the second subplot
|
| 207 |
# Since we can't directly apply the texture, we'll create a colored sphere
|
| 208 |
u = np.linspace(0, 2 * np.pi, 50)
|
| 209 |
v = np.linspace(0, np.pi, 25)
|
|
|
|
| 231 |
showlegend=False
|
| 232 |
)
|
| 233 |
|
| 234 |
+
# Update axes for the image subplot
|
| 235 |
+
fig.update_xaxes(visible=False, row=1, col=1)
|
| 236 |
+
fig.update_yaxes(visible=False, row=1, col=1)
|
| 237 |
+
|
| 238 |
# Update 3D scene settings
|
| 239 |
fig.update_scenes(
|
| 240 |
aspectmode='data',
|
|
|
|
| 247 |
print("Error creating texture and sphere preview:", e)
|
| 248 |
return go.Figure()
|
| 249 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 250 |
# Function to get predictions
|
| 251 |
def get_predictions(audio_input):
|
| 252 |
emotion_prediction = predict_emotion_from_audio(audio_input)
|