NLong commited on
Commit
f246f0a
·
verified ·
1 Parent(s): edee27e

Upload 10 files

Browse files
Files changed (3) hide show
  1. app.py +16 -1
  2. get_token.py +79 -0
  3. simple_token.py +72 -0
app.py CHANGED
@@ -1468,9 +1468,24 @@ def analyze_news(news_text):
1468
  else:
1469
  support_summary = "⚠️ Các nguồn có ý kiến trái chiều"
1470
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1471
  detailed_analysis = f"""
1472
  <div style="font-family: 'Segoe UI', Arial, sans-serif; line-height: 1.6; color: #333;">
1473
 
 
 
1474
  ## 🔍 **KẾT QUẢ PHÂN TÍCH TIN TỨC**
1475
 
1476
  <div style="background: linear-gradient(135deg, #667eea 0%, #764ba2 100%); color: white; padding: 20px; border-radius: 10px; margin: 20px 0; text-align: center;">
@@ -1694,6 +1709,6 @@ if __name__ == "__main__":
1694
  interface.launch(
1695
  server_name="0.0.0.0",
1696
  server_port=7860, # Standard port for Hugging Face Spaces
1697
- share=False, # Not needed for Hugging Face Spaces
1698
  show_error=True
1699
  )
 
1468
  else:
1469
  support_summary = "⚠️ Các nguồn có ý kiến trái chiều"
1470
 
1471
+ # Add debug info for troubleshooting
1472
+ debug_section = f"""
1473
+ ### 🔧 **Debug Info (for troubleshooting)**
1474
+ <div style="background: #f0f0f0; padding: 10px; border-radius: 5px; margin: 10px 0; border: 1px solid #ccc;">
1475
+ <p><strong>ENABLE_ENHANCED_RAG:</strong> {ENABLE_ENHANCED_RAG}</p>
1476
+ <p><strong>Gemini Max Confidence:</strong> {gemini_max_confidence if 'gemini_max_confidence' in locals() else 'Not calculated'}</p>
1477
+ <p><strong>RAG Threshold:</strong> {RAG_CONFIDENCE_THRESHOLD}</p>
1478
+ <p><strong>Should Save:</strong> {ENABLE_ENHANCED_RAG and gemini_max_confidence >= RAG_CONFIDENCE_THRESHOLD if 'gemini_max_confidence' in locals() else 'Unknown'}</p>
1479
+ <p><strong>Gemini Real %:</strong> {gemini_real_confidence * 100 if 'gemini_real_confidence' in locals() and gemini_real_confidence else 'N/A'}</p>
1480
+ <p><strong>Gemini Fake %:</strong> {gemini_fake_confidence * 100 if 'gemini_fake_confidence' in locals() and gemini_fake_confidence else 'N/A'}</p>
1481
+ </div>
1482
+ """
1483
+
1484
  detailed_analysis = f"""
1485
  <div style="font-family: 'Segoe UI', Arial, sans-serif; line-height: 1.6; color: #333;">
1486
 
1487
+ {debug_section}
1488
+
1489
  ## 🔍 **KẾT QUẢ PHÂN TÍCH TIN TỨC**
1490
 
1491
  <div style="background: linear-gradient(135deg, #667eea 0%, #764ba2 100%); color: white; padding: 20px; border-radius: 10px; margin: 20px 0; text-align: center;">
 
1709
  interface.launch(
1710
  server_name="0.0.0.0",
1711
  server_port=7860, # Standard port for Hugging Face Spaces
1712
+ share=True, # Not needed for Hugging Face Spaces
1713
  show_error=True
1714
  )
get_token.py ADDED
@@ -0,0 +1,79 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ #!/usr/bin/env python3
2
+ """
3
+ Simple script to get Google Drive refresh token
4
+ """
5
+
6
+ import os
7
+ import json
8
+ from google.oauth2.credentials import Credentials
9
+ from google_auth_oauthlib.flow import InstalledAppFlow
10
+ from google.auth.transport.requests import Request
11
+
12
+ def get_refresh_token():
13
+ """Get refresh token for Google Drive"""
14
+ print("🔐 Getting Google Drive Refresh Token...")
15
+ print("This will open your browser for authentication")
16
+ print()
17
+
18
+ try:
19
+ SCOPES = ['https://www.googleapis.com/auth/drive.file']
20
+ creds = None
21
+
22
+ # Check if token.json exists
23
+ if os.path.exists('token.json'):
24
+ print("📁 Found existing token.json")
25
+ creds = Credentials.from_authorized_user_file('token.json', SCOPES)
26
+
27
+ # If no valid credentials, request authorization
28
+ if not creds or not creds.valid:
29
+ if creds and creds.expired and creds.refresh_token:
30
+ print("🔄 Refreshing expired token...")
31
+ creds.refresh(Request())
32
+ else:
33
+ print("🌐 Opening browser for authentication...")
34
+ flow = InstalledAppFlow.from_client_secrets_file(
35
+ 'credentials.json', SCOPES)
36
+ creds = flow.run_local_server(port=8080, open_browser=True)
37
+
38
+ # Save credentials for next run
39
+ with open('token.json', 'w') as token:
40
+ token.write(creds.to_json())
41
+ print("💾 Token saved to token.json")
42
+
43
+ # Extract refresh token
44
+ refresh_token = creds.refresh_token
45
+
46
+ if refresh_token:
47
+ print("\n✅ SUCCESS! Refresh token obtained!")
48
+ print(f"🔑 GOOGLE_REFRESH_TOKEN = {refresh_token}")
49
+
50
+ # Also show client info
51
+ with open('credentials.json', 'r') as f:
52
+ creds_data = json.load(f)
53
+
54
+ if 'web' in creds_data:
55
+ client_id = creds_data['web']['client_id']
56
+ client_secret = creds_data['web']['client_secret']
57
+
58
+ print("\n📋 Add these 3 secrets to your HF Space:")
59
+ print(f"GOOGLE_CLIENT_ID = {client_id}")
60
+ print(f"GOOGLE_CLIENT_SECRET = {client_secret}")
61
+ print(f"GOOGLE_REFRESH_TOKEN = {refresh_token}")
62
+
63
+ print("\n🌐 Next steps:")
64
+ print("1. Go to: https://huggingface.co/spaces/NLong/FakeNews_Detector")
65
+ print("2. Click 'Settings' tab")
66
+ print("3. Add the 3 secrets above")
67
+ print("4. Your app will use Google Drive for RAG storage!")
68
+
69
+ return refresh_token
70
+ else:
71
+ print("❌ No refresh token found")
72
+ return None
73
+
74
+ except Exception as e:
75
+ print(f"❌ Error: {e}")
76
+ return None
77
+
78
+ if __name__ == "__main__":
79
+ get_refresh_token()
simple_token.py ADDED
@@ -0,0 +1,72 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ #!/usr/bin/env python3
2
+ """
3
+ Simple token generation with automatic port selection
4
+ """
5
+
6
+ import os
7
+ import json
8
+ from google.oauth2.credentials import Credentials
9
+ from google_auth_oauthlib.flow import InstalledAppFlow
10
+ from google.auth.transport.requests import Request
11
+
12
+ def get_token():
13
+ """Get refresh token with automatic port selection"""
14
+ print("🔐 Getting Google Drive Token...")
15
+
16
+ try:
17
+ SCOPES = ['https://www.googleapis.com/auth/drive.file']
18
+ creds = None
19
+
20
+ # Check if token.json exists
21
+ if os.path.exists('token.json'):
22
+ print("📁 Found existing token.json")
23
+ creds = Credentials.from_authorized_user_file('token.json', SCOPES)
24
+
25
+ # If no valid credentials, request authorization
26
+ if not creds or not creds.valid:
27
+ if creds and creds.expired and creds.refresh_token:
28
+ print("🔄 Refreshing expired token...")
29
+ creds.refresh(Request())
30
+ else:
31
+ print("🌐 Starting OAuth flow...")
32
+ flow = InstalledAppFlow.from_client_secrets_file(
33
+ 'credentials.json', SCOPES)
34
+ # Let it choose an available port automatically
35
+ creds = flow.run_local_server(port=0, open_browser=True)
36
+
37
+ # Save credentials
38
+ with open('token.json', 'w') as token:
39
+ token.write(creds.to_json())
40
+ print("💾 Token saved!")
41
+
42
+ # Get refresh token
43
+ refresh_token = creds.refresh_token
44
+
45
+ if refresh_token:
46
+ print("\n✅ SUCCESS!")
47
+ print(f"🔑 Refresh Token: {refresh_token}")
48
+
49
+ # Show all credentials
50
+ with open('credentials.json', 'r') as f:
51
+ creds_data = json.load(f)
52
+
53
+ if 'web' in creds_data:
54
+ client_id = creds_data['web']['client_id']
55
+ client_secret = creds_data['web']['client_secret']
56
+
57
+ print("\n📋 Add these to your HF Space secrets:")
58
+ print(f"GOOGLE_CLIENT_ID = {client_id}")
59
+ print(f"GOOGLE_CLIENT_SECRET = {client_secret}")
60
+ print(f"GOOGLE_REFRESH_TOKEN = {refresh_token}")
61
+
62
+ return True
63
+ else:
64
+ print("❌ No refresh token found")
65
+ return False
66
+
67
+ except Exception as e:
68
+ print(f"❌ Error: {e}")
69
+ return False
70
+
71
+ if __name__ == "__main__":
72
+ get_token()