Update README.md
Browse files
README.md
CHANGED
|
@@ -6,15 +6,61 @@ colorTo: red
|
|
| 6 |
sdk: docker
|
| 7 |
app_port: 8501
|
| 8 |
tags:
|
| 9 |
-
- streamlit
|
|
|
|
|
|
|
| 10 |
pinned: false
|
| 11 |
-
short_description: Streamlit
|
| 12 |
license: mit
|
| 13 |
---
|
| 14 |
|
| 15 |
-
#
|
| 16 |
|
| 17 |
-
|
| 18 |
|
| 19 |
-
|
| 20 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 6 |
sdk: docker
|
| 7 |
app_port: 8501
|
| 8 |
tags:
|
| 9 |
+
- streamlit
|
| 10 |
+
- fastapi
|
| 11 |
+
- openrouter
|
| 12 |
pinned: false
|
| 13 |
+
short_description: Streamlit + FastAPI chat UI for OpenRouter
|
| 14 |
license: mit
|
| 15 |
---
|
| 16 |
|
| 17 |
+
# ChatLLM — Streamlit + FastAPI on Hugging Face Spaces
|
| 18 |
|
| 19 |
+
A lightweight chat UI powered by Streamlit (frontend) and FastAPI (backend) that proxies requests to OpenRouter. Runs as a single Docker Space with both services in one container.
|
| 20 |
|
| 21 |
+
Main files
|
| 22 |
+
- `src/app.py` — Streamlit frontend
|
| 23 |
+
- `src/server.py` — FastAPI backend
|
| 24 |
+
- `requirements.txt` — Python deps
|
| 25 |
+
- `Dockerfile` — Multi-service (Streamlit + FastAPI) using s6-overlay
|
| 26 |
+
|
| 27 |
+
Features
|
| 28 |
+
- Client-side API key entry (never stored on server)
|
| 29 |
+
- Optional server-side fallback API key via Space secret
|
| 30 |
+
- System prompt editor and model selector
|
| 31 |
+
- Health checks for frontend and backend
|
| 32 |
+
|
| 33 |
+
Deploy on Hugging Face Spaces (Docker)
|
| 34 |
+
1) Set Space to SDK: Docker.
|
| 35 |
+
2) In Settings → Variables and secrets, add:
|
| 36 |
+
- `BACKEND_URL` = `http://localhost:8000/chat`
|
| 37 |
+
- `OPENROUTER_API_KEY` = `or-xxxxxxxx` (optional; acts as fallback)
|
| 38 |
+
3) Push your repo with `Dockerfile`, `requirements.txt`, and `src/` folder.
|
| 39 |
+
4) Open the Space URL. In the app, expand Settings and paste your key if you didn’t set a server fallback.
|
| 40 |
+
|
| 41 |
+
Local development (optional)
|
| 42 |
+
- Build and run:
|
| 43 |
+
- `docker build -t chatllm .`
|
| 44 |
+
- `docker run --rm -p 8501:8501 -p 8000:8000 -e BACKEND_URL=http://localhost:8000/chat chatllm`
|
| 45 |
+
- Visit `http://localhost:8501`
|
| 46 |
+
|
| 47 |
+
Environment variables
|
| 48 |
+
- `BACKEND_URL` — Where the frontend calls the backend. For single-container Spaces, use `http://localhost:8000/chat`.
|
| 49 |
+
- `OPENROUTER_API_KEY` — Optional server fallback key. If not set, users enter their own key in the UI.
|
| 50 |
+
|
| 51 |
+
Security notes
|
| 52 |
+
- Never commit your API key to the repo.
|
| 53 |
+
- Keys entered in the UI are kept in the browser session and sent only as an `Authorization` header per request.
|
| 54 |
+
|
| 55 |
+
Troubleshooting
|
| 56 |
+
- App loads but chat doesn’t respond:
|
| 57 |
+
- Check Space logs. Ensure backend started (Uvicorn on port 8000).
|
| 58 |
+
- Verify `BACKEND_URL` is set to `http://localhost:8000/chat`.
|
| 59 |
+
- “Missing OpenRouter API key”:
|
| 60 |
+
- Paste your key in the UI Settings, or set `OPENROUTER_API_KEY` as a Space secret.
|
| 61 |
+
- Test endpoints inside container:
|
| 62 |
+
- `curl http://localhost:8501/_stcore/health`
|
| 63 |
+
- `curl http://localhost:8000/docs`
|
| 64 |
+
|
| 65 |
+
License
|
| 66 |
+
- MIT
|