File size: 4,248 Bytes
c8016f6
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
2f024ae
 
 
c8016f6
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
2f024ae
c8016f6
 
 
2f024ae
 
 
 
 
 
 
 
c8016f6
2f024ae
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
c8016f6
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
2f024ae
c8016f6
 
 
 
 
 
 
2f024ae
 
 
 
 
c8016f6
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
# 02 - Hugging Face, Secrets, and API Keys

This guide explains where the live website runs and how API keys are managed.

## Where the Website Runs

The live website is a Hugging Face Space:

```text
https://huggingface.co/spaces/UWRFR/UWaterlooRFRChatBot
```

The public app URL is:

```text
https://uwrfr-uwaterloorfrchatbot.hf.space
```

Hugging Face stores:

- The deployed app code.
- Space settings.
- Runtime logs.
- Variables and secrets.
- The mounted storage bucket, if enabled.

## How to See Space Logs

1. Open the Hugging Face Space.
2. Click **Logs** near the top of the Space page.
3. Look for Python errors, missing secrets, API failures, or build errors.

Useful CLI command:

```bash
hf spaces info UWRFR/UWaterlooRFRChatBot
```

This shows the current commit SHA and runtime state.

## Hugging Face Variables and Secrets

Go to:

```text
Hugging Face Space -> Settings -> Variables and secrets
```

Use **Variables** for non-sensitive values.

Use **Secrets** for private values, such as API keys.

Important: Hugging Face does not show the value of an existing secret after it
is saved. You can see that the secret exists, but you cannot reveal the stored
key. If a key is lost or wrong, replace the secret with a new value.

## Required Secrets

For LLM answers:

```text
ANTHROPIC_API_KEY
```

or, if using OpenAI:

```text
OPENAI_API_KEY
OPENAI_MODEL
```

For Google Drive request uploads:

```text
GOOGLE_OAUTH_CLIENT_ID
GOOGLE_OAUTH_CLIENT_SECRET
GOOGLE_OAUTH_REFRESH_TOKEN
```

Optional override for the new case study request intake folder:

```text
RFR_REQUESTS_DRIVE_FOLDER_ID
```

Current request intake folder ID:

```text
10n_-uOCT2GXu_G3r1qi5qJr8hHoy-E_y
```

## What Each Secret Does

### `ANTHROPIC_API_KEY`

Used by the chatbot when the app is configured to answer with Claude.

If this key is missing, expired, or has no credits, the Ask tab can fail.

### `OPENAI_API_KEY`

Used when the app or local pipeline is configured to use OpenAI.

If using OpenAI, also set:

```text
OPENAI_MODEL
```

Example:

```text
gpt-4o-mini
```

### Google Drive Request Upload Secrets

Used by the website to upload New Case Study Requests into Google Drive.

Preferred setup uses OAuth for the shared Google account that should own the
uploaded folders and PDFs, usually:

```text
rfr.rag.uwaterloo@gmail.com
```

Set these Hugging Face secrets:

```text
GOOGLE_OAUTH_CLIENT_ID
GOOGLE_OAUTH_CLIENT_SECRET
GOOGLE_OAUTH_REFRESH_TOKEN
```

Generate the secret values locally:

```bash
python3 -m case_study_pipeline.create_drive_oauth_secrets \
  --credentials-file /path/to/oauth-client.json \
  --space-id UWRFR/UWaterlooRFRChatBot
```

When the browser opens, sign in as `rfr.rag.uwaterloo@gmail.com`. The script
prints the `hf spaces secrets add ...` commands to run.

The older fallback secret is:

```text
GOOGLE_SERVICE_ACCOUNT_JSON
```

That service-account option works best with a Google Shared Drive. It can fail
in normal My Drive folders because service accounts do not have storage quota.

## How to Add or Replace a Secret

1. Open the Hugging Face Space.
2. Click **Settings**.
3. Scroll to **Variables and secrets**.
4. Click **New secret**.
5. Enter the exact name, such as `ANTHROPIC_API_KEY`.
6. Paste the value.
7. Save.
8. Restart or rebuild the Space if needed.

## How to Check Whether a Secret Is the Problem

Open Space logs and look for messages like:

```text
ANTHROPIC_API_KEY is not set
OPENAI_API_KEY is not set
GOOGLE_SERVICE_ACCOUNT_JSON is not set
GOOGLE_OAUTH_REFRESH_TOKEN is not set
credit balance is too low
invalid_api_key
permission denied
```

For Drive upload problems, check:

- The three OAuth secrets exist: `GOOGLE_OAUTH_CLIENT_ID`,
  `GOOGLE_OAUTH_CLIENT_SECRET`, and `GOOGLE_OAUTH_REFRESH_TOKEN`.
- The OAuth token was created by signing in as the account that owns or can edit
  the intake folder.
- The intake folder ID is set correctly with `RFR_REQUESTS_DRIVE_FOLDER_ID`.
- The Space was restarted after the secret was added.

## Do Not Put API Keys in GitHub

Never commit API keys to:

- `README.md`
- `.env`
- Python files
- Markdown docs
- screenshots

Use Hugging Face secrets for the live website.

Use a local `.env` file for your own computer. Do not commit `.env`.