ghengx commited on
Commit
ab41980
·
1 Parent(s): fa49cef
Files changed (2) hide show
  1. app.py +30 -12
  2. requirements.txt +1 -0
app.py CHANGED
@@ -2,23 +2,41 @@ import os
2
  import gradio as gr
3
  import warnings
4
 
5
- from huggingface_hub import Repository
6
- from huggingface_hub import login
7
-
8
  warnings.filterwarnings("ignore")
9
 
10
- login(token = os.environ['HF_TOKEN'])
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
11
 
 
12
  from model import AIContentDetector
13
 
14
- repo = Repository(
15
- local_dir="",
16
- repo_type="dataset",
17
- clone_from=os.environ['DATASET'],
18
- token=True
19
- )
20
- repo.git_pull()
21
-
22
  # Initialize the detector
23
  detector = AIContentDetector()
24
 
 
2
  import gradio as gr
3
  import warnings
4
 
 
 
 
5
  warnings.filterwarnings("ignore")
6
 
7
+ # Optional Hugging Face integration
8
+ try:
9
+ from huggingface_hub import Repository, login
10
+
11
+ # Try to login if token is available
12
+ if 'HF_TOKEN' in os.environ and os.environ['HF_TOKEN'].strip():
13
+ login(token=os.environ['HF_TOKEN'])
14
+ print("✅ Logged into Hugging Face")
15
+
16
+ # Try to pull dataset if specified
17
+ if 'DATASET' in os.environ and os.environ['DATASET'].strip():
18
+ try:
19
+ repo = Repository(
20
+ local_dir="",
21
+ repo_type="dataset",
22
+ clone_from=os.environ['DATASET'],
23
+ token=True
24
+ )
25
+ repo.git_pull()
26
+ print("✅ Dataset pulled successfully")
27
+ except Exception as e:
28
+ print(f"⚠️ Warning: Could not pull dataset: {e}")
29
+ else:
30
+ print("ℹ️ No HF_TOKEN found, skipping Hugging Face authentication")
31
+
32
+ except ImportError as e:
33
+ print(f"⚠️ Warning: Could not import Hugging Face Hub: {e}")
34
+ except Exception as e:
35
+ print(f"⚠️ Warning: Hugging Face authentication failed: {e}")
36
 
37
+ # Import the AI detector
38
  from model import AIContentDetector
39
 
 
 
 
 
 
 
 
 
40
  # Initialize the detector
41
  detector = AIContentDetector()
42
 
requirements.txt CHANGED
@@ -14,3 +14,4 @@ boto3>=1.26.0
14
  pydub>=0.25.0
15
  psutil>=5.8.0
16
  pynvml>=11.0.0
 
 
14
  pydub>=0.25.0
15
  psutil>=5.8.0
16
  pynvml>=11.0.0
17
+ huggingface_hub>=0.15.0