File size: 6,546 Bytes
75f5e82
 
cebd780
 
 
75f5e82
cebd780
75f5e82
 
785b4e2
75f5e82
 
cebd780
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
785b4e2
 
 
cebd780
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
---
title: Pak Angels AI Tutor
emoji: 🎓
colorFrom: blue
colorTo: indigo
sdk: gradio
sdk_version: 5.50.0
app_file: app.py
pinned: false
suggested_hardware: zero-a10g
---

# Pak Angels AI Tutor

Pak Angels AI Tutor is an AI-powered learning companion for the Pak Angels AI
Training Program. It helps students, faculty, researchers, professionals,
entrepreneurs, startup founders, AI developers, business leaders, and innovation
teams learn Artificial Intelligence, build practical applications, design
intelligent workflows, automate business processes, and develop AI-powered
startups.

The app is built with Gradio and the official OpenAI Python SDK. It is
prepared for functional testing and demonstration on Hugging Face Spaces.

## Features

- Clean blue-and-white Pak Angels visual identity
- Sidebar navigation with specialized learning modes
- Selected learning-mode label above the conversation area
- Streaming AI responses through the OpenAI Responses API
- Session-based chat history
- Suggested-question buttons for every learning mode
- New Conversation and Clear Chat controls
- Markdown rendering and syntax-highlighted code blocks
- Clear missing-key and OpenAI API error messages
- Privacy notice for sensitive information
- Hugging Face Spaces-compatible environment-variable configuration

## Learning Modules

- Home
- AI-101 Foundations
- Prompt Engineering
- Generative AI
- Agentic AI
- Retrieval-Augmented Generation (RAG)
- Multi-Agent Systems
- AI Workflow Design
- Business Process Automation
- Gradio Development
- AI Startup Mentor
- About Pak Angels

## Local Setup

Local setup is optional. Hugging Face Spaces can run the app directly from these
files.

1. Create a virtual environment:

   ```bash
   python -m venv .venv
   ```

2. Activate the virtual environment:

   ```bash
   source .venv/bin/activate
   ```

3. Install dependencies:

   ```bash
   pip install -r requirements.txt
   ```

4. Configure environment variables:

   ```bash
   cp .env.example .env
   ```

   Add your real key only to `.env` or your shell environment. Do not commit
   `.env`.

5. Run the app:

   ```bash
   python app.py
   ```

## Hugging Face Spaces Deployment

1. Create a Hugging Face account.
2. Create a new Space.
3. Select Gradio as the application SDK if available.
4. Choose the desired visibility.
5. Upload or push all project files from this folder.
6. Open the Space Settings.
7. Go to Variables and secrets.
8. Add a new secret named `OPENAI_API_KEY`.
9. Optionally add `OPENAI_MODEL`.
10. Allow Hugging Face to build the application.
11. Review build logs if deployment fails.
12. Open the Space URL and test all learning modes.

To update the Space, replace the files through the Hugging Face web interface or
push changes through Git. Hugging Face will rebuild the Space after new changes
are uploaded.

### Deploy With the Hugging Face Hub API

This project includes `deploy_to_huggingface.py`, which uploads the current
project folder to a Hugging Face Space using the Hugging Face Hub API.

Install the deployment helper dependency locally:

```bash
python3 -m pip install -r deploy_requirements.txt
```

Set the Hugging Face deployment credentials in your local environment:

```bash
export HF_TOKEN=your_hugging_face_write_token_here
export HF_SPACE_ID=your-username/your-space-name
```

Use your real Hugging Face username and Space name. Do not leave
`your-username/your-space-name` in the command.

Then upload the project to an existing Space:

```bash
python3 deploy_to_huggingface.py
```

If the Space does not exist yet, create it as a Gradio Space and upload in one
step:

```bash
python3 deploy_to_huggingface.py --create
```

You can also pass the Space id directly:

```bash
python3 deploy_to_huggingface.py --space-id your-username/your-space-name --create
```

The script excludes local-only files such as `.env`, `.venv/`, caches, logs, and
compiled Python files. It does not create or upload OpenAI secrets. Add
`OPENAI_API_KEY` separately in the Space settings.

## Required Hugging Face Secret

The required secret name is:

```text
OPENAI_API_KEY
```

Optional:

```text
OPENAI_MODEL
```

Never upload a `.env` file containing a real API key to Hugging Face Spaces.

## Troubleshooting

Missing API key: Add `OPENAI_API_KEY` under Hugging Face Space -> Settings ->
Variables and secrets -> New secret, then restart or rebuild the Space.

Quota exceeded or billing errors: Check OpenAI usage limits, billing settings,
and project access. The app will show a clear message for rate limits and quota
related API failures.

Dependency installation errors: Confirm `requirements.txt` is present in the
Space root folder and that the Space is using Python with Gradio support.

Python version problems: Use a current Hugging Face Gradio environment. The
code uses standard cross-platform Python and avoids Mac-specific paths.

Missing assets: The app does not require local image assets. Optional future
assets should use relative paths and should be committed with the app.

OpenAI API errors: Check the API key, selected model, quota, billing, and build
logs. If using `OPENAI_MODEL`, verify that the account has access to the model.

Gradio startup failures: Make sure `app.py` exists at the Space root. For local
testing, run `python app.py`.

Hugging Face build failures: Review the Space build logs, confirm all required
files are uploaded, and check that only necessary dependencies are listed.

ZeroGPU or GPU startup error: This app does not need GPU hardware. In the Space
Settings, set Hardware to a CPU option such as CPU Basic, then restart the Space.

## Security

- API keys must never be committed to Git.
- API keys must never be placed directly in `app.py`.
- Real secrets must not be placed in `.env.example`.
- Users should not enter confidential, proprietary, financial, medical,
  personal, or otherwise sensitive information into the tutor.

## Architecture

- `app.py`: Gradio interface, navigation, chat state, and page rendering
- `config.py`: environment-variable configuration
- `prompts.py`: learning modules, suggested questions, and specialized tutor instructions
- `openai_service.py`: OpenAI Responses API streaming integration and error handling
- `requirements.txt`: deployment dependencies
- `deploy_to_huggingface.py`: Hugging Face Hub API upload script
- `deploy_requirements.txt`: local-only dependency for the upload script
- `.env.example`: safe placeholder environment variables
- `.gitignore`: local secrets and development artifact exclusions