Add application files for Hugging Face Space
Browse files- Dockerfile +0 -43
- README.md +1 -0
- hf-space/.gitignore +24 -0
- hf-space/Dockerfile +24 -0
- hf-space/README.md +109 -0
- hf-space/app.py +19 -0
- hf-space/requirements.txt +2 -0
Dockerfile
DELETED
|
@@ -1,43 +0,0 @@
|
|
| 1 |
-
# 1. Build Go Proxy
|
| 2 |
-
FROM golang:1.24-alpine AS builder
|
| 3 |
-
WORKDIR /app
|
| 4 |
-
COPY . .
|
| 5 |
-
RUN go mod download
|
| 6 |
-
RUN CGO_ENABLED=0 GOOS=linux go build -o /app/cliproxy ./cmd/server/
|
| 7 |
-
|
| 8 |
-
# 2. Runtime Environment
|
| 9 |
-
FROM debian:bookworm-slim
|
| 10 |
-
|
| 11 |
-
USER root
|
| 12 |
-
|
| 13 |
-
# Install dependencies including CA certificates which are critical for Go HTTP clients
|
| 14 |
-
RUN apt-get update && apt-get install -y python3-pip curl git procps ca-certificates && rm -rf /var/lib/apt/lists/*
|
| 15 |
-
|
| 16 |
-
# Copy Proxy Binary
|
| 17 |
-
COPY --from=builder /app/cliproxy /usr/local/bin/cliproxy
|
| 18 |
-
|
| 19 |
-
# Copy Configuration & Assets
|
| 20 |
-
COPY config.yaml /etc/cliproxy/config.yaml
|
| 21 |
-
COPY static /etc/cliproxy/static
|
| 22 |
-
|
| 23 |
-
# Ensure management.html exists and is accessible
|
| 24 |
-
RUN ls -la /etc/cliproxy/static/management.html || echo "Management file not found"
|
| 25 |
-
|
| 26 |
-
# Create a robust startup script
|
| 27 |
-
RUN printf '#!/bin/bash\nset -e\n' > /start.sh && \
|
| 28 |
-
printf 'echo "=== STARTUP: Verifying Management Files ==="\n' >> /start.sh && \
|
| 29 |
-
printf 'if [ ! -f "/etc/cliproxy/static/management.html" ]; then\n' >> /start.sh && \
|
| 30 |
-
printf ' echo "Management file missing, downloading fallback..."\n' >> /start.sh && \
|
| 31 |
-
printf ' curl -L -o /etc/cliproxy/static/management.html "https://cpamc.router-for.me/"\n' >> /start.sh && \
|
| 32 |
-
printf 'fi\n' >> /start.sh && \
|
| 33 |
-
printf 'echo "=== STARTUP: Fixing Config ==="\n' >> /start.sh && \
|
| 34 |
-
printf 'sed -i "s/freeapis-proxy:5001/localhost:5001/g" /etc/cliproxy/config.yaml\n' >> /start.sh && \
|
| 35 |
-
printf 'echo "=== STARTUP: Launching FreeAPIs (Background) ==="\n' >> /start.sh && \
|
| 36 |
-
printf 'cd /app/freeapis-proxy && PORT=5001 python3 server.py > /tmp/freeapis.log 2>&1 &\n' >> /start.sh && \
|
| 37 |
-
printf 'echo "=== STARTUP: Launching Go Proxy (Foreground) ==="\n' >> /start.sh && \
|
| 38 |
-
printf 'exec /usr/local/bin/cliproxy -config /etc/cliproxy/config.yaml\n' >> /start.sh && \
|
| 39 |
-
chmod +x /start.sh
|
| 40 |
-
|
| 41 |
-
EXPOSE 7860
|
| 42 |
-
|
| 43 |
-
ENTRYPOINT ["/start.sh"]
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
README.md
CHANGED
|
@@ -14,3 +14,4 @@ English | [Chinese](README_CN.md)
|
|
| 14 |
This is the Plus version of [CLIProxyAPI](https://github.com/router-for-me/CLIProxyAPI), adding support for third-party providers on top of the mainline project.
|
| 15 |
|
| 16 |
Running on Hugging Face Spaces with Puter OS.# trigger
|
|
|
|
|
|
| 14 |
This is the Plus version of [CLIProxyAPI](https://github.com/router-for-me/CLIProxyAPI), adding support for third-party providers on top of the mainline project.
|
| 15 |
|
| 16 |
Running on Hugging Face Spaces with Puter OS.# trigger
|
| 17 |
+
# Force rebuild
|
hf-space/.gitignore
ADDED
|
@@ -0,0 +1,24 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# Virtual environment
|
| 2 |
+
venv/
|
| 3 |
+
__pycache__/
|
| 4 |
+
*.pyc
|
| 5 |
+
*.pyo
|
| 6 |
+
*.pyd
|
| 7 |
+
|
| 8 |
+
# IDE files
|
| 9 |
+
.vscode/
|
| 10 |
+
.idea/
|
| 11 |
+
*.swp
|
| 12 |
+
*.swo
|
| 13 |
+
|
| 14 |
+
# OS files
|
| 15 |
+
.DS_Store
|
| 16 |
+
Thumbs.db
|
| 17 |
+
|
| 18 |
+
# Logs
|
| 19 |
+
*.log
|
| 20 |
+
logs/
|
| 21 |
+
|
| 22 |
+
# Temporary files
|
| 23 |
+
*.tmp
|
| 24 |
+
*.temp
|
hf-space/Dockerfile
ADDED
|
@@ -0,0 +1,24 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# Dockerfile for CLIProxyAPIPlus Hugging Face Space
|
| 2 |
+
# Uses Python 3.9 as base image
|
| 3 |
+
FROM python:3.9
|
| 4 |
+
|
| 5 |
+
# Create and set up a non-root user for security
|
| 6 |
+
RUN useradd -m -u 1000 user
|
| 7 |
+
USER user
|
| 8 |
+
ENV PATH="/home/user/.local/bin:$PATH"
|
| 9 |
+
|
| 10 |
+
# Set working directory
|
| 11 |
+
WORKDIR /app
|
| 12 |
+
|
| 13 |
+
# Copy requirements and install dependencies
|
| 14 |
+
COPY --chown=user ./requirements.txt requirements.txt
|
| 15 |
+
RUN pip install --no-cache-dir --upgrade -r requirements.txt
|
| 16 |
+
|
| 17 |
+
# Copy the application code
|
| 18 |
+
COPY --chown=user . /app
|
| 19 |
+
|
| 20 |
+
# Expose the required port for Hugging Face Spaces (7860)
|
| 21 |
+
EXPOSE 7860
|
| 22 |
+
|
| 23 |
+
# Command to run the FastAPI application
|
| 24 |
+
CMD ["uvicorn", "app:app", "--host", "0.0.0.0", "--port", "7860"]
|
hf-space/README.md
ADDED
|
@@ -0,0 +1,109 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# CLIProxyAPIPlus - Hugging Face Space
|
| 2 |
+
|
| 3 |
+
A simple FastAPI application serving as a demonstration and monitoring endpoint for CLIProxyAPIPlus.
|
| 4 |
+
|
| 5 |
+
## Features
|
| 6 |
+
|
| 7 |
+
- Basic health check endpoint
|
| 8 |
+
- Service information endpoint
|
| 9 |
+
- Simple JSON responses
|
| 10 |
+
- Dockerized for easy deployment on Hugging Face Spaces
|
| 11 |
+
|
| 12 |
+
## Endpoints
|
| 13 |
+
|
| 14 |
+
### GET /
|
| 15 |
+
|
| 16 |
+
Returns a simple greeting message:
|
| 17 |
+
|
| 18 |
+
```json
|
| 19 |
+
{
|
| 20 |
+
"Hello": "World!"
|
| 21 |
+
}
|
| 22 |
+
```
|
| 23 |
+
|
| 24 |
+
### GET /health
|
| 25 |
+
|
| 26 |
+
Returns service health status:
|
| 27 |
+
|
| 28 |
+
```json
|
| 29 |
+
{
|
| 30 |
+
"status": "healthy",
|
| 31 |
+
"service": "CLIProxyAPIPlus"
|
| 32 |
+
}
|
| 33 |
+
```
|
| 34 |
+
|
| 35 |
+
### GET /info
|
| 36 |
+
|
| 37 |
+
Returns detailed service information:
|
| 38 |
+
|
| 39 |
+
```json
|
| 40 |
+
{
|
| 41 |
+
"service": "CLIProxyAPIPlus",
|
| 42 |
+
"description": "A proxy server for CLI models with OpenAI/Gemini/Claude compatible APIs",
|
| 43 |
+
"version": "1.0.0"
|
| 44 |
+
}
|
| 45 |
+
```
|
| 46 |
+
|
| 47 |
+
## Deployment
|
| 48 |
+
|
| 49 |
+
This application is designed to run on Hugging Face Spaces using Docker.
|
| 50 |
+
|
| 51 |
+
### Requirements
|
| 52 |
+
|
| 53 |
+
- Docker
|
| 54 |
+
- Hugging Face account
|
| 55 |
+
- Hugging Face CLI (`hf`)
|
| 56 |
+
|
| 57 |
+
### Local Testing
|
| 58 |
+
|
| 59 |
+
1. Install dependencies:
|
| 60 |
+
|
| 61 |
+
```bash
|
| 62 |
+
pip install -r requirements.txt
|
| 63 |
+
```
|
| 64 |
+
|
| 65 |
+
1. Run the application:
|
| 66 |
+
|
| 67 |
+
```bash
|
| 68 |
+
uvicorn app:app --host 0.0.0.0 --port 7860
|
| 69 |
+
```
|
| 70 |
+
|
| 71 |
+
1. Access the API at `http://localhost:7860`
|
| 72 |
+
|
| 73 |
+
### Docker Deployment
|
| 74 |
+
|
| 75 |
+
1. Build the Docker image:
|
| 76 |
+
|
| 77 |
+
```bash
|
| 78 |
+
docker build -t cliproxyapiplus-space .
|
| 79 |
+
```
|
| 80 |
+
|
| 81 |
+
1. Run the container:
|
| 82 |
+
|
| 83 |
+
```bash
|
| 84 |
+
docker run -p 7860:7860 cliproxyapiplus-space
|
| 85 |
+
```
|
| 86 |
+
|
| 87 |
+
### Hugging Face Spaces Deployment
|
| 88 |
+
|
| 89 |
+
1. Clone this Space:
|
| 90 |
+
|
| 91 |
+
```bash
|
| 92 |
+
git clone https://huggingface.co/spaces/PHhTTPS/cliproxaapiplus
|
| 93 |
+
```
|
| 94 |
+
|
| 95 |
+
1. Add your files and commit:
|
| 96 |
+
|
| 97 |
+
```bash
|
| 98 |
+
git add requirements.txt app.py Dockerfile README.md
|
| 99 |
+
git commit -m "Add CLIProxyAPIPlus Space files"
|
| 100 |
+
git push
|
| 101 |
+
```
|
| 102 |
+
|
| 103 |
+
## Configuration
|
| 104 |
+
|
| 105 |
+
The application runs on port 7860 by default, which is required for Hugging Face Spaces.
|
| 106 |
+
|
| 107 |
+
## License
|
| 108 |
+
|
| 109 |
+
This project is licensed under the same license as the main CLIProxyAPIPlus project.
|
hf-space/app.py
ADDED
|
@@ -0,0 +1,19 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from fastapi import FastAPI
|
| 2 |
+
|
| 3 |
+
app = FastAPI()
|
| 4 |
+
|
| 5 |
+
@app.get("/")
|
| 6 |
+
def greet_json():
|
| 7 |
+
return {"Hello": "World!"}
|
| 8 |
+
|
| 9 |
+
@app.get("/health")
|
| 10 |
+
def health_check():
|
| 11 |
+
return {"status": "healthy", "service": "CLIProxyAPIPlus"}
|
| 12 |
+
|
| 13 |
+
@app.get("/info")
|
| 14 |
+
def service_info():
|
| 15 |
+
return {
|
| 16 |
+
"service": "CLIProxyAPIPlus",
|
| 17 |
+
"description": "A proxy server for CLI models with OpenAI/Gemini/Claude compatible APIs",
|
| 18 |
+
"version": "1.0.0"
|
| 19 |
+
}
|
hf-space/requirements.txt
ADDED
|
@@ -0,0 +1,2 @@
|
|
|
|
|
|
|
|
|
|
| 1 |
+
fastapi
|
| 2 |
+
uvicorn[standard]
|