DocUA commited on
Commit
439d893
·
1 Parent(s): b0c6533

refactor: Enhance dependency import robustness with try-except blocks and add version logging for Gradio and HuggingFace Hub.

Browse files
Files changed (2) hide show
  1. app_hf.py +19 -1
  2. requirements.txt +5 -6
app_hf.py CHANGED
@@ -1,4 +1,20 @@
1
- import gradio as gr
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
2
  from transformers import AutoModel, AutoTokenizer, AutoProcessor, AutoModelForImageTextToText
3
  import torch
4
  import os
@@ -20,7 +36,9 @@ warnings.filterwarnings("ignore", message="You are using a model of type .* to i
20
  # Try to import spaces, if not available (local run), create a dummy decorator
21
  try:
22
  import spaces
 
23
  except ImportError:
 
24
  class spaces:
25
  @staticmethod
26
  def GPU(func):
 
1
+ import sys
2
+ import subprocess
3
+
4
+ try:
5
+ import gradio as gr
6
+ print(f"Gradio version: {gr.__version__}")
7
+ except ImportError:
8
+ print("Gradio not installed or failed to import")
9
+ # Attempt fallback or just fail
10
+ raise
11
+
12
+ try:
13
+ import huggingface_hub
14
+ print(f"HuggingFace Hub version: {huggingface_hub.__version__}")
15
+ except ImportError:
16
+ print("HuggingFace Hub not installed")
17
+
18
  from transformers import AutoModel, AutoTokenizer, AutoProcessor, AutoModelForImageTextToText
19
  import torch
20
  import os
 
36
  # Try to import spaces, if not available (local run), create a dummy decorator
37
  try:
38
  import spaces
39
+ print(f"Spaces imported successfully")
40
  except ImportError:
41
+ print("Spaces not found, using dummy decorator")
42
  class spaces:
43
  @staticmethod
44
  def GPU(func):
requirements.txt CHANGED
@@ -1,16 +1,15 @@
1
  torch
2
- transformers>=4.45.0
3
- tokenizers
4
  einops
5
  addict
6
  easydict
7
- accelerate
8
  sentencepiece
9
  pillow
10
  matplotlib
11
  requests
12
  torchvision
13
- gradio>=5.0
14
- huggingface-hub>=0.25.0
15
  pymupdf
16
- spaces
 
1
  torch
2
+ transformers>=4.46.0
3
+ accelerate
4
  einops
5
  addict
6
  easydict
 
7
  sentencepiece
8
  pillow
9
  matplotlib
10
  requests
11
  torchvision
12
+ gradio>=5.1.0
13
+ huggingface-hub>=0.26.0
14
  pymupdf
15
+ spaces>=0.30.0