Update run.py
Browse files
run.py
CHANGED
@@ -9,7 +9,43 @@ from datetime import datetime
|
|
9 |
|
10 |
# Google Sheets setup
|
11 |
scope = ["https://spreadsheets.google.com/feeds", "https://www.googleapis.com/auth/drive"]
|
12 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
13 |
client = gspread.authorize(creds)
|
14 |
sheet = client.open("nestolechatbot").sheet1 # Open the sheet
|
15 |
|
|
|
9 |
|
10 |
# Google Sheets setup
|
11 |
scope = ["https://spreadsheets.google.com/feeds", "https://www.googleapis.com/auth/drive"]
|
12 |
+
import json
|
13 |
+
import requests
|
14 |
+
from huggingface_hub import HfApi, HfFolder
|
15 |
+
import os
|
16 |
+
|
17 |
+
api_key = os.getenv("key")
|
18 |
+
# Step 1: Authenticate with Hugging Face Hub
|
19 |
+
api = HfApi()
|
20 |
+
# Replace 'your_token' with your actual Hugging Face API token
|
21 |
+
HfFolder.setup_token(api_token=api_key)
|
22 |
+
|
23 |
+
# Step 2: Specify your Hugging Face username, Space name, and file name
|
24 |
+
username = 'thiloid'
|
25 |
+
space_name = 'envapi'
|
26 |
+
file_name = 'nestolechatbot-5fe2aa26cb52.json'
|
27 |
+
|
28 |
+
# Step 3: Get download URL for the JSON file
|
29 |
+
download_url = f'https://huggingface.co/{username}/{space_name}/resolve/main/{file_name}'
|
30 |
+
|
31 |
+
# Step 4: Download the file content
|
32 |
+
try:
|
33 |
+
response = requests.get(download_url)
|
34 |
+
response.raise_for_status() # Raise an exception for bad responses
|
35 |
+
except requests.exceptions.HTTPError as e:
|
36 |
+
print(f"HTTP error occurred: {e}")
|
37 |
+
exit()
|
38 |
+
|
39 |
+
# Step 5: Load JSON data
|
40 |
+
try:
|
41 |
+
json_data = json.loads(response.content)
|
42 |
+
print("JSON data loaded successfully:")
|
43 |
+
except json.JSONDecodeError as e:
|
44 |
+
print(f"JSON decoding error occurred: {e}")
|
45 |
+
creds = ServiceAccountCredentials.from_json_keyfile_name(json_data, scope)
|
46 |
+
|
47 |
+
|
48 |
+
#creds = ServiceAccountCredentials.from_json_keyfile_name('/home/user/app/chromaold/nestolechatbot-5fe2aa26cb52.json', scope)
|
49 |
client = gspread.authorize(creds)
|
50 |
sheet = client.open("nestolechatbot").sheet1 # Open the sheet
|
51 |
|