File size: 5,636 Bytes
f8d4638
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
# πŸš€ PaperChat - Complete Deployment Guide

## πŸ“‹ Quick Checklist

- [ ] All files created
- [ ] HF account ready
- [ ] HF Token obtained
- [ ] Space created
- [ ] Files uploaded
- [ ] App running

---

## πŸ“ Project Structure

Create a folder called `paperchat` with these files:

```

paperchat/

β”œβ”€β”€ app.py                 # Main Streamlit application

β”œβ”€β”€ requirements.txt       # Python dependencies

β”œβ”€β”€ README.md             # Hugging Face Spaces config

└── .env                  # Local environment variables (don't upload this!)

```

---

## πŸ”§ Step 1: Local Setup & Testing (Optional but Recommended)

### 1.1 Create virtual environment

```bash

# Create project folder

mkdir paperchat

cd paperchat



# Create virtual environment

python -m venv venv



# Activate it

# On Windows:

venv\Scripts\activate

# On Mac/Linux:

source venv/bin/activate

```

### 1.2 Install dependencies

```bash

pip install -r requirements.txt

```

### 1.3 Set up HF Token

Create a `.env` file:

```bash

# .env file content

HF_TOKEN=hf_your_token_here

```

**Get your token**: https://huggingface.co/settings/tokens

### 1.4 Test locally

```bash

streamlit run app.py

```

Open http://localhost:8501 and test with a sample PDF!

---

## 🌐 Step 2: Deploy to Hugging Face Spaces

### 2.1 Create a new Space

1. Go to https://huggingface.co/spaces
2. Click **"Create new Space"**
3. Fill in:
   - **Space name**: `paperchat` (or your preferred name)
   - **License**: MIT
   - **Select SDK**: Streamlit
   - **Hardware**: CPU (free tier is fine!)
   - **Visibility**: Public

### 2.2 Upload files

**Option A: Via Web Interface**
1. Click "Files" tab in your Space
2. Click "Add file" β†’ "Upload files"
3. Upload: `app.py`, `requirements.txt`, `README.md`
4. Commit changes

**Option B: Via Git (Recommended)**

```bash

# Clone your space

git clone https://huggingface.co/spaces/YOUR_USERNAME/paperchat

cd paperchat



# Copy your files

cp /path/to/app.py .

cp /path/to/requirements.txt .

cp /path/to/README.md .



# Commit and push

git add .

git commit -m "Initial commit"

git push

```

### 2.3 Add HF Token to Secrets

1. Go to your Space settings
2. Click "Settings" β†’ "Repository secrets"
3. Click "Add a secret"
4. Name: `HF_TOKEN`
5. Value: Your Hugging Face token
6. Save

### 2.4 Wait for build

The Space will automatically build and deploy. Watch the logs:
- ⏳ Building... (1-2 minutes)
- βœ… Running! 

---

## βœ… Step 3: Verify Deployment

1. Visit your Space URL: `https://huggingface.co/spaces/YOUR_USERNAME/paperchat`
2. Upload a test PDF (try a short research paper)
3. Ask a question
4. Verify you get an answer

---

## πŸ› Common Issues & Fixes

### Issue 1: "Module not found" error

**Fix**: Check `requirements.txt` has all dependencies

```txt

smolagents

streamlit

pypdf

langchain

langchain-community

sentence-transformers

python-dotenv

rank_bm25

```

### Issue 2: "HF_TOKEN not found"



**Fix**: Add token to Space secrets (Step 2.3)



### Issue 3: App crashes on PDF upload



**Fix**: Usually a memory issue. Try:

- Smaller PDF (< 10 MB)

- Reduce `chunk_size` in app.py to 300

### Issue 4: Slow response times

**Fix**: This is normal for free tier. Upgrade to better hardware in Space settings if needed.

---

## 🎨 Step 4: Customization (Optional)

### Change the model

In `app.py`, modify the agent creation:

```python

agent = CodeAgent(

    tools=[retriever_tool],

    model=InferenceClientModel(model_id="meta-llama/Llama-3.3-70B-Instruct"),

    max_steps=4,

    verbosity_level=0,

)

```

### Change colors/theme

Update `README.md` header:

```yaml

colorFrom: red

colorTo: yellow

```

### Add example papers

Pre-load famous papers in the sidebar for quick demos.

---

## πŸ“Š Step 5: Monitor & Improve

### Track usage

- Check Space analytics in HF dashboard
- Monitor error logs

### Collect feedback

Add a feedback button:

```python

if st.button("πŸ‘ Helpful"):

    st.success("Thanks for your feedback!")

```

### Add features

Ideas:
- Multiple paper comparison
- Export chat as PDF
- Highlight relevant sections
- Paper summarization mode

---

## πŸŽ“ Step 6: Add to Resume/Portfolio

### Resume bullet point

```

β€’ Built PaperChat, an AI-powered research paper Q&A tool using Agentic RAG,

  deployed on Hugging Face Spaces with 100+ users

β€’ Implemented retrieval-augmented generation with BM25 + LLM agents for

  accurate question answering with source citations

```

### Portfolio description

```

PaperChat - Research Paper Q&A Assistant



An intelligent document assistant that helps researchers quickly understand

and extract information from academic papers. Built with smolagents and

deployed on Hugging Face Spaces.



Tech: Python, Streamlit, LangChain, RAG, BM25, LLM Agents

Live Demo: [your-space-url]

```

---

## πŸŽ‰ You're Done!

Your app is now:
- βœ… Live on the internet
- βœ… Accessible to anyone
- βœ… Resume-ready
- βœ… Portfolio-worthy

Share your Space URL with friends, on LinkedIn, or in your resume!

---

## πŸ†˜ Need Help?

- **Hugging Face Docs**: https://huggingface.co/docs/hub/spaces
- **Streamlit Docs**: https://docs.streamlit.io
- **smolagents Docs**: https://github.com/huggingface/smolagents

---

**Pro Tip**: Record a 30-second demo video showing:
1. Upload a paper
2. Ask a question
3. Get an answer

Use this video in your portfolio or LinkedIn post! 🎬