Spaces:
Paused
Paused
Update app.py
Browse files
app.py
CHANGED
|
@@ -5,7 +5,27 @@ from datetime import datetime
|
|
| 5 |
|
| 6 |
# Hugging Face Token
|
| 7 |
HF_TOKEN = os.getenv("HF_TOKEN")
|
| 8 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 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()
|