hvoss-techfak commited on
Commit
83aa561
Β·
1 Parent(s): 54cc9d1

There seems to be some crashes yesterday, so I added new logging to make the crashes reproducible.

Browse files
Files changed (2) hide show
  1. app.py +60 -26
  2. requirements.txt +2 -1
app.py CHANGED
@@ -1,14 +1,16 @@
 
1
  import uuid
2
  import os
3
  import logging
4
  import zipfile
5
 
6
  import sentry_sdk
 
7
  from sentry_sdk import capture_exception, push_scope, capture_message
8
  from sentry_sdk.integrations.logging import LoggingIntegration
9
  from sentry_sdk.integrations.starlette import StarletteIntegration
10
  from sentry_sdk.integrations.fastapi import FastApiIntegration
11
- import spaces
12
  dsn = os.getenv("SENTRY_DSN")
13
  if not dsn:
14
  print("WARNING: SENTRY_DSN not set – Sentry disabled")
@@ -36,6 +38,15 @@ else:
36
 
37
  sentry_sdk.capture_message("πŸŽ‰ Sentry is wired up!")
38
 
 
 
 
 
 
 
 
 
 
39
  import gradio, functools
40
  from sentry_sdk import capture_exception, flush
41
 
@@ -310,7 +321,7 @@ if os.path.exists(DEFAULT_MATERIALS_CSV):
310
  else:
311
  initial_df.to_csv(DEFAULT_MATERIALS_CSV, index=False)
312
 
313
- @spaces.GPU(duration=90) # GPU reserved only for this call
314
  def run_autoforge_process(cmd, log_path):
315
  """
316
  Launch the external `autoforge` CLI.
@@ -663,6 +674,7 @@ with gr.Blocks(theme=gr.themes.Soft()) as demo:
663
  def execute_autoforge_script(
664
  current_filaments_df_state_val, input_image, *accordion_param_values
665
  ):
 
666
  # 0. Validate Inputs
667
  if input_image is None:
668
  gr.Error("Input Image is required! Please upload an image.")
@@ -752,12 +764,12 @@ with gr.Blocks(theme=gr.themes.Soft()) as demo:
752
 
753
 
754
  # 3. Run script
755
- log_output = (
756
- f"Starting Autoforge process at "
757
- f"{datetime.now().strftime('%Y-%m-%d %H:%M:%S')}\n"
758
- f"Output directory: {run_output_dir_val}\n"
759
- f"Command: {' '.join(command)}\n\n"
760
- )
761
 
762
  yield create_empty_error_outputs(log_output) # clear UI and show header
763
 
@@ -830,7 +842,7 @@ with gr.Blocks(theme=gr.themes.Soft()) as demo:
830
  if now - last_push >= 1.0: # one-second UI tick
831
  current_preview = _maybe_new_preview()
832
  yield (
833
- log_output,
834
  current_preview,
835
  gr.update(), # placeholder for download widget
836
  )
@@ -880,22 +892,6 @@ with gr.Blocks(theme=gr.themes.Soft()) as demo:
880
  if out_png is None:
881
  log_output += "\nWarning: final_model.png not found in output."
882
 
883
- if os.path.exists(script_input_image_path):
884
- sentry_sdk.add_attachment(
885
- path=script_input_image_path, # file on disk
886
- filename="input_image.png", # how it shows up in Sentry
887
- content_type="image/png",
888
- )
889
- if out_png:
890
- try:
891
- sentry_sdk.add_attachment(
892
- path=out_png, # file on disk
893
- filename="final_image.png", # how it shows up in Sentry
894
- content_type="image/png",
895
- )
896
- except Exception as e: # unreadable or too large
897
- capture_exception(e)
898
-
899
  sentry_sdk.capture_event( # moved inside the same scope
900
  {
901
  "message": "Autoforge process finished",
@@ -905,8 +901,45 @@ with gr.Blocks(theme=gr.themes.Soft()) as demo:
905
  }
906
  )
907
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
908
  yield (
909
- log_output, # progress_output
910
  out_png, # final_image_preview (same as before)
911
  gr.update( # download_results
912
  value=files_to_offer,
@@ -928,6 +961,7 @@ with gr.Blocks(theme=gr.themes.Soft()) as demo:
928
 
929
  css = """ #run_button_full_width { width: 100%; } """
930
  if __name__ == "__main__":
 
931
  if not os.path.exists(DEFAULT_MATERIALS_CSV):
932
  print(f"Creating default filament file: {DEFAULT_MATERIALS_CSV}")
933
  try:
 
1
+ import string
2
  import uuid
3
  import os
4
  import logging
5
  import zipfile
6
 
7
  import sentry_sdk
8
+ import wandb
9
  from sentry_sdk import capture_exception, push_scope, capture_message
10
  from sentry_sdk.integrations.logging import LoggingIntegration
11
  from sentry_sdk.integrations.starlette import StarletteIntegration
12
  from sentry_sdk.integrations.fastapi import FastApiIntegration
13
+ #import spaces
14
  dsn = os.getenv("SENTRY_DSN")
15
  if not dsn:
16
  print("WARNING: SENTRY_DSN not set – Sentry disabled")
 
38
 
39
  sentry_sdk.capture_message("πŸŽ‰ Sentry is wired up!")
40
 
41
+ USE_WANDB = "WANDB_API_KEY" in os.environ
42
+ if USE_WANDB:
43
+ wandb.login(key=os.environ["WANDB_API_KEY"])
44
+
45
+ else:
46
+ print("Warning: WANDB_API_KEY not set. Skipping wandb logging.")
47
+
48
+
49
+
50
  import gradio, functools
51
  from sentry_sdk import capture_exception, flush
52
 
 
321
  else:
322
  initial_df.to_csv(DEFAULT_MATERIALS_CSV, index=False)
323
 
324
+ #@spaces.GPU(duration=90) # GPU reserved only for this call
325
  def run_autoforge_process(cmd, log_path):
326
  """
327
  Launch the external `autoforge` CLI.
 
674
  def execute_autoforge_script(
675
  current_filaments_df_state_val, input_image, *accordion_param_values
676
  ):
677
+
678
  # 0. Validate Inputs
679
  if input_image is None:
680
  gr.Error("Input Image is required! Please upload an image.")
 
764
 
765
 
766
  # 3. Run script
767
+ log_output = [
768
+ f"Starting Autoforge process at ",
769
+ f"{datetime.now().strftime('%Y-%m-%d %H:%M:%S')}\n",
770
+ f"Output directory: {run_output_dir_val}\n",
771
+ f"Command: {' '.join(command)}\n\n",
772
+ ]
773
 
774
  yield create_empty_error_outputs(log_output) # clear UI and show header
775
 
 
842
  if now - last_push >= 1.0: # one-second UI tick
843
  current_preview = _maybe_new_preview()
844
  yield (
845
+ "".join(log_output),
846
  current_preview,
847
  gr.update(), # placeholder for download widget
848
  )
 
892
  if out_png is None:
893
  log_output += "\nWarning: final_model.png not found in output."
894
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
895
  sentry_sdk.capture_event( # moved inside the same scope
896
  {
897
  "message": "Autoforge process finished",
 
901
  }
902
  )
903
 
904
+ if USE_WANDB:
905
+ run = None
906
+ try:
907
+ run = wandb.init(
908
+ project="autoforge",
909
+ name=f"run_{timestamp}",
910
+ notes="Autoforge Web UI run",
911
+ tags=["autoforge", "gradio"],
912
+ )
913
+ wlogs= {"input_image": wandb.Image(script_input_image_path),}
914
+ if out_png:
915
+ wlogs["output_image"] = wandb.Image(out_png)
916
+
917
+ material_csv = pd.read_csv(temp_filament_csv)
918
+ table = wandb.Table(dataframe=material_csv)
919
+ wlogs["materials"] = table
920
+ #log log_output as pandas table
921
+ from wandb import Html
922
+ log_text = "".join(log_output).replace("\r", "\n")
923
+
924
+ def clean_log_strict(text: str) -> str:
925
+ # Keep only printable characters + newline + tab
926
+ allowed = set(string.printable) | {"\n", "\t"}
927
+ return "".join(ch for ch in text if ch in allowed)
928
+
929
+ log_text_cleaned = clean_log_strict(log_text)
930
+ wlogs["log"] = Html(f"<pre>{log_text_cleaned}</pre>")
931
+
932
+
933
+ wandb.log(wlogs)
934
+ except Exception as e:
935
+ #we don't want wandb errors logged in sentry
936
+ print(e)
937
+ finally:
938
+ if run is not None:
939
+ run.finish()
940
+
941
  yield (
942
+ "".join(log_output), # progress_output
943
  out_png, # final_image_preview (same as before)
944
  gr.update( # download_results
945
  value=files_to_offer,
 
961
 
962
  css = """ #run_button_full_width { width: 100%; } """
963
  if __name__ == "__main__":
964
+
965
  if not os.path.exists(DEFAULT_MATERIALS_CSV):
966
  print(f"Creating default filament file: {DEFAULT_MATERIALS_CSV}")
967
  try:
requirements.txt CHANGED
@@ -1,3 +1,4 @@
1
  autoforge==1.7.3
2
  sentry-sdk[huggingface_hub]
3
- sentry-sdk[fastapi]
 
 
1
  autoforge==1.7.3
2
  sentry-sdk[huggingface_hub]
3
+ sentry-sdk[fastapi]
4
+ wandb