hvoss-techfak commited on
Commit
039620a
·
verified ·
1 Parent(s): 27736c7

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +33 -36
app.py CHANGED
@@ -8,38 +8,6 @@ import importlib
8
  import sentry_sdk
9
  import wandb
10
  from contextlib import redirect_stdout, redirect_stderr
11
- from sentry_sdk import capture_exception
12
- from sentry_sdk.integrations.logging import LoggingIntegration
13
- from sentry_sdk.integrations.starlette import StarletteIntegration
14
- from sentry_sdk.integrations.fastapi import FastApiIntegration
15
- import spaces
16
- dsn = os.getenv("SENTRY_DSN")
17
- if not dsn:
18
- print("WARNING: SENTRY_DSN not set – Sentry disabled")
19
- else:
20
-
21
- sentry_sdk.init(
22
- dsn=dsn,
23
- traces_sample_rate=0.1,
24
- integrations=[
25
- StarletteIntegration(
26
- failed_request_status_codes={
27
- 400,
28
- 422,
29
- *range(500, 599),
30
- }, # also log 4xx from Gradio
31
- ),
32
- LoggingIntegration(
33
- level=logging.INFO, # breadcrumb level
34
- event_level=logging.ERROR,
35
- ),
36
- FastApiIntegration(),
37
- ],
38
- release=os.getenv("HF_SPACE_VERSION", "dev"),
39
- environment="hf_space",
40
- )
41
-
42
- sentry_sdk.capture_message("🎉 Sentry is wired up!")
43
 
44
  USE_WANDB = "WANDB_API_KEY" in os.environ
45
  if USE_WANDB:
@@ -310,17 +278,46 @@ initial_df = pd.DataFrame(initial_filament_data)
310
 
311
  if os.path.exists(DEFAULT_MATERIALS_CSV):
312
  try:
313
- initial_df = pd.read_csv(DEFAULT_MATERIALS_CSV)
 
 
 
314
  for col in ["Brand", " Name", " TD", " Color"]:
315
- if col not in initial_df.columns:
316
- initial_df[col] = None
317
- initial_df = initial_df[["Brand", " Name", " TD", " Color"]].astype(
 
 
 
318
  {" TD": float, " Color": str}
319
  )
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
320
  except Exception as e:
321
  print(f"Warning: Could not load {DEFAULT_MATERIALS_CSV}: {e}. Using default.")
322
  initial_df = pd.DataFrame(initial_filament_data)
323
  else:
 
 
324
  initial_df.to_csv(DEFAULT_MATERIALS_CSV, index=False)
325
 
326
 
 
8
  import sentry_sdk
9
  import wandb
10
  from contextlib import redirect_stdout, redirect_stderr
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
11
 
12
  USE_WANDB = "WANDB_API_KEY" in os.environ
13
  if USE_WANDB:
 
278
 
279
  if os.path.exists(DEFAULT_MATERIALS_CSV):
280
  try:
281
+ # Load what the user already has
282
+ loaded_df = pd.read_csv(DEFAULT_MATERIALS_CSV)
283
+
284
+ # Make sure the columns we need are present
285
  for col in ["Brand", " Name", " TD", " Color"]:
286
+ if col not in loaded_df.columns:
287
+ # keep it simple, create empty column
288
+ loaded_df[col] = "" if col != " TD" else 0.0
289
+
290
+ # Cast to the types we expect
291
+ loaded_df = loaded_df[["Brand", " Name", " TD", " Color"]].astype(
292
  {" TD": float, " Color": str}
293
  )
294
+
295
+ # Keep a DataFrame version for the rest of the app
296
+ initial_df = loaded_df
297
+
298
+ # Important part:
299
+ # also update the in memory initial_filament_data so later fallbacks
300
+ # do not go back to the hardcoded 6 Generic rows
301
+ initial_filament_data = {
302
+ "Brand": initial_df["Brand"].tolist(),
303
+ " Name": initial_df[" Name"].tolist(),
304
+ " TD": initial_df[" TD"].tolist(),
305
+ " Color": initial_df[" Color"].tolist(),
306
+ }
307
+ # If you want to keep " Owned" around even when CSV did not have it,
308
+ # you can add a default here
309
+ if " Owned" not in initial_df.columns:
310
+ # fill with false by default
311
+ initial_filament_data[" Owned"] = ["false"] * len(initial_df)
312
+ else:
313
+ initial_filament_data[" Owned"] = initial_df[" Owned"].astype(str).tolist()
314
+
315
  except Exception as e:
316
  print(f"Warning: Could not load {DEFAULT_MATERIALS_CSV}: {e}. Using default.")
317
  initial_df = pd.DataFrame(initial_filament_data)
318
  else:
319
+ # CSV does not exist yet, create it from the hardcoded defaults
320
+ initial_df = pd.DataFrame(initial_filament_data)
321
  initial_df.to_csv(DEFAULT_MATERIALS_CSV, index=False)
322
 
323