keynes42 commited on
Commit
aa427a5
·
verified ·
1 Parent(s): 71bffee

Upload test.ipynb

Browse files
Files changed (1) hide show
  1. test.ipynb +74 -0
test.ipynb ADDED
@@ -0,0 +1,74 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "nbformat": 4,
3
+ "nbformat_minor": 0,
4
+ "metadata": {
5
+ "colab": {
6
+ "provenance": [],
7
+ "toc_visible": true
8
+ },
9
+ "kernelspec": {
10
+ "name": "python3",
11
+ "display_name": "Python 3"
12
+ },
13
+ "language_info": {
14
+ "name": "python"
15
+ }
16
+ },
17
+ "cells": [
18
+ {
19
+ "cell_type": "code",
20
+ "execution_count": null,
21
+ "metadata": {
22
+ "id": "FmZtP1U67iZ0"
23
+ },
24
+ "outputs": [],
25
+ "source": [
26
+ "# test_download.py\n",
27
+ "import requests\n",
28
+ "import os\n",
29
+ "\n",
30
+ "# Get the token from the Space's secrets\n",
31
+ "HF_TOKEN = os.getenv(\"HF_TOKEN\")\n",
32
+ "\n",
33
+ "# The URL for the file from your error message\n",
34
+ "# Using /resolve/main/ for direct raw download\n",
35
+ "FILE_URL = \"https://huggingface.co/datasets/gaia-benchmark/GAIA/blob/main/2023/validation/cca530fc-4052-43b2-b130-b30968d8aa44.png\"\n",
36
+ "\n",
37
+ "if not HF_TOKEN:\n",
38
+ " print(\"❌ Critical Error: HF_TOKEN secret is not set.\")\n",
39
+ "else:\n",
40
+ " print(f\"✅ Token found. Attempting download from: {FILE_URL}\")\n",
41
+ "\n",
42
+ " # Create the authentication header\n",
43
+ " headers = {\"Authorization\": f\"Bearer {HF_TOKEN}\"}\n",
44
+ "\n",
45
+ " try:\n",
46
+ " # Make the request with the headers\n",
47
+ " response = requests.get(FILE_URL, headers=headers, timeout=30)\n",
48
+ "\n",
49
+ " # Print the outcome\n",
50
+ " print(f\"Response Status Code: {response.status_code}\")\n",
51
+ "\n",
52
+ " if response.status_code == 200:\n",
53
+ " print(\"✅ Download successful! The token and URL are correct.\")\n",
54
+ " # Optionally, save the file to check\n",
55
+ " with open(\"test_image.png\", \"wb\") as f:\n",
56
+ " f.write(response.content)\n",
57
+ " print(\"Saved file as test_image.png\")\n",
58
+ " else:\n",
59
+ " print(\"❌ Download failed. Server response:\")\n",
60
+ " print(response.text[:500]) # Print the first 500 chars of the error message\n",
61
+ "\n",
62
+ " except Exception as e:\n",
63
+ " print(f\"An unexpected error occurred: {e}\")"
64
+ ]
65
+ },
66
+ {
67
+ "cell_type": "markdown",
68
+ "source": [],
69
+ "metadata": {
70
+ "id": "PaO_PK9x7lIe"
71
+ }
72
+ }
73
+ ]
74
+ }