ashen007 commited on
Commit
1dac99a
·
verified ·
1 Parent(s): 9a71880

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +16 -5
app.py CHANGED
@@ -1,12 +1,23 @@
1
  import gradio as gr
2
  from ultralytics import YOLO
3
  from PIL import Image
 
4
  import numpy as np
5
  import os
6
 
7
- # Load the YOLO model - the model will be loaded from the HF repo
8
- model_repo = "ashen007/document-structure-detection"
9
- model = YOLO(model_repo)
 
 
 
 
 
 
 
 
 
 
10
 
11
  # Define your class names - update this with your actual class names
12
  class_names = [
@@ -66,6 +77,6 @@ demo = gr.Interface(
66
  ]
67
  )
68
 
69
- # Launch the app
70
  if __name__ == "__main__":
71
- demo.launch()
 
1
  import gradio as gr
2
  from ultralytics import YOLO
3
  from PIL import Image
4
+ from huggingface_hub import hf_hub_download
5
  import numpy as np
6
  import os
7
 
8
+ # Load the YOLO model - use the proper format for Hugging Face repos
9
+ try:
10
+ # Format for loading from Hugging Face: "hf://username/model_name"
11
+ model_repo = "hf://ashen007/document-structure-detection"
12
+ model = YOLO(model_repo)
13
+ print(f"Successfully loaded model from {model_repo}")
14
+
15
+ except Exception as e:
16
+ model_path = hf_hub_download(
17
+ repo_id="ashen007/document-structure-detection",
18
+ filename="DSD-YOLOv8-v2.pt"
19
+ )
20
+ model = YOLO(model_path)
21
 
22
  # Define your class names - update this with your actual class names
23
  class_names = [
 
77
  ]
78
  )
79
 
80
+ # Launch the app - settings for Hugging Face Spaces
81
  if __name__ == "__main__":
82
+ demo.launch(share=False)