openfree commited on
Commit
629e9cd
·
verified ·
1 Parent(s): 2d1b715

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +22 -2
app.py CHANGED
@@ -5,7 +5,27 @@ from datetime import datetime
5
 
6
  # Hugging Face Token
7
  HF_TOKEN = os.getenv("HF_TOKEN")
8
- USERNAME = "openfree" # 특정 사용자 ID 설정
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
9
 
10
  def format_timestamp(timestamp):
11
  if timestamp:
@@ -89,4 +109,4 @@ app = gr.Interface(
89
 
90
  # Launch the Gradio app
91
  if __name__ == "__main__":
92
- app.launch()
 
5
 
6
  # Hugging Face Token
7
  HF_TOKEN = os.getenv("HF_TOKEN")
8
+
9
+ def get_username_from_token():
10
+ """Retrieve the username using the Hugging Face token"""
11
+ if not HF_TOKEN:
12
+ return None
13
+
14
+ headers = {
15
+ "Authorization": f"Bearer {HF_TOKEN}",
16
+ "Accept": "application/json"
17
+ }
18
+
19
+ response = requests.get("https://huggingface.co/api/whoami", headers=headers)
20
+ if response.status_code == 200:
21
+ return response.json().get("name")
22
+ return None
23
+
24
+ # Retrieve the username
25
+ USERNAME = get_username_from_token()
26
+
27
+ if not USERNAME:
28
+ raise ValueError("Error: Could not retrieve username. Check your Hugging Face token.")
29
 
30
  def format_timestamp(timestamp):
31
  if timestamp:
 
109
 
110
  # Launch the Gradio app
111
  if __name__ == "__main__":
112
+ app.launch()