π€ Hugging-c-ai β Multi-Provider AI Persona Chat Portal
Forked & heavily upgraded from Open Character AI. Replaces Google OAuth with HuggingFace OAuth, adds multi-provider LLM support (OpenAI, Anthropic, HuggingFace Inference, Groq, MuAPI, custom Gradio Servers), stores uploads in HF Dataset buckets, and supports real-time streaming responses.
π What's New (vs upstream)
| Area | Upstream | Hugging-c-ai |
|---|---|---|
| Auth | Google OAuth + MuAPI API key | HuggingFace OAuth (with repo:write scope) + multi-provider API key (auto-detected) |
| LLM providers | MuAPI gateway only | 6 providers: OpenAI, Anthropic, HuggingFace, Groq, MuAPI, custom Gradio Servers |
| Streaming | β polling every 1.5s | β SSE streaming for OpenAI, Anthropic, HF, Groq |
| Storage | MuAPI CDN only | β HF Dataset bucket (HfFileSystem) β uploads save to user's own HF repo |
| Models | 4 hardcoded options | β 17 models across 5 providers + custom Gradio endpoints |
| Database | PostgreSQL (requires Supabase/Neon) | β SQLite by default (zero setup) β switch to Postgres for prod |
| Credit cost | Flat 2 credits | β Per-model pricing from catalog (1cβ15c) |
| Token tracking | β | β Prompt + completion tokens logged per message |
| Marketplace | β | β
/explore page β browse all public custom characters |
| Deploy button | Vercel clone | β Duplicate to HF Space |
β¨ Core Features
π¬ Multi-Provider Chat Studio (/[character_name]/[id])
- 17 LLM options grouped by provider in the model selector
- Real-time SSE streaming β watch tokens appear as they generate
- Custom Gradio endpoints β connect to any HF Space running a Gradio app
- Per-chat LLM tuning: temperature, max tokens, reasoning mode, streaming toggle
- Vision support for OpenAI GPT-4o, Claude 3.5, Gemini (via MuAPI)
- Token usage tracking (prompt + completion tokens per message)
π€ HuggingFace Authentication
- OAuth2 flow with
openid profile email repo:write readscopes - The user's HF access token is reused for:
- Writing uploads to their own HF dataset repo
- Calling private/gated Gradio Spaces
- HuggingFace Inference API calls
- Fallback: API key auth supports
hf_*,sk-*,sk-ant*,gsk_*,mu_*prefixes β auto-detected
ποΈ HF Dataset Bucket Storage
- Uploads are written to a HF dataset repo (default:
<hf-username>/hugging-c-ai-assets) - Uses
@huggingface/hub'suploadFile/listFiles/downloadFile/deleteFile - The repo is created lazily on first upload if it doesn't exist
- Public resolve URLs (
https://huggingface.co/datasets/<repo>/resolve/main/<path>) are stored in the DB - Falls back to MuAPI upload if no HF token is available
π Gradio Server Support
- Connect to any deployed Gradio app as a custom LLM endpoint
- Format:
gradio:<space-url>orgradio:<space-url>::<api-name> - Uses the user's HF OAuth token to authenticate (so private/gated Spaces work)
- Auto-tries common parameter shapes (chat, predict, single-message)
- Reference: Introducing Gradio Server
π Character Builder & Marketplace
- 15 preset characters (Einstein, Jobs, Sherlock, etc.) ship out of the box
- Visual builder for custom personas β name, avatar, system prompt, greeting, visibility
/explorepage β browse all public custom characters created by the community- Per-character public/private toggle (only visible to creator if private)
π³ Stripe Billing (optional)
- 4 credit pack plans ($5/$10/$20/$50)
- Pay-as-you-go credit balance, instantly updated via Stripe webhooks
- Per-model cost deducted per message; auto-refunded on generation failure
π οΈ Architecture
hugging-c-ai/
βββ prisma/
β βββ schema.prisma # SQLite schema (User, Account, Character, Chat, Message, UserImage, Creation)
βββ src/
β βββ app/
β β βββ page.js # Dashboard / character selection & builder
β β βββ login/page.js # HF OAuth + API key tabs
β β βββ explore/page.js # Public character marketplace
β β βββ pricing/page.js # Stripe credit packs
β β βββ [character_name]/[id]/page.js # Chat studio with streaming + multi-provider model selector
β β βββ api/
β β βββ auth/[...nextauth]/ # NextAuth handler (HF + Credentials)
β β βββ characters/ # GET/POST/PATCH (15 defaults + custom)
β β βββ chats/ # GET/POST chat threads
β β βββ chats/[id]/messages/ # GET/POST messages β calls provider registry (supports SSE streaming)
β β βββ models/ # GET model catalog grouped by provider
β β βββ upload/ # POST file β HF dataset bucket (or MuAPI fallback)
β β βββ images/ # GET user's upload history
β β βββ hf/datasets/ # GET user's HF datasets + files in default repo
β β βββ gradio/ # GET user's HF Spaces Β· POST probe a Gradio app's API
β β βββ user/apikey/ # POST/DELETE custom API key
β β βββ checkout/ # POST planId β Stripe checkout
β β βββ stripe/ # checkout + webhook (legacy inline)
β βββ lib/
β β βββ auth.js # NextAuth config (HF OAuth + Credentials)
β β βββ prisma.js # PrismaClient + libsql adapter (SQLite)
β β βββ config.js # App config + provider key map + Stripe plans
β β βββ stripe.js # Lazy Stripe singleton
β β βββ providers/huggingface.js # HF OAuth2 provider for NextAuth
β β βββ ai/
β β β βββ models.js # 17-model catalog + PROVIDER_META + getModelMeta()
β β β βββ providers.js # callLLM() β single entry point, routes to adapter
β β β βββ openai.js # OpenAI SDK + streaming + vision
β β β βββ anthropic.js # Anthropic SDK + streaming + vision
β β β βββ huggingface.js # HF Inference (chat-completion) + streaming
β β β βββ groq.js # Groq SDK + streaming (ultra-low-latency)
β β β βββ muapi.js # Legacy MuAPI gateway (polling-based)
β β β βββ gradio.js # @gradio/client wrapper for custom Spaces
β β βββ storage/hf.js # HFStorage class β wraps @huggingface/hub
β β βββ services/ # billing.js, user.js (credit ledger)
β βββ components/ # Navbar (HF branding), Footer
βββ prisma.config.ts # Prisma 7 config (datasource URL)
βββ next.config.mjs # Image remotePatterns for HF + muapi CDN
βββ Dockerfile # HF Space Docker build
βββ .env.example # All required env vars
βββ dev.db # SQLite DB (auto-created on first run)
π― Quick Start
1. Install dependencies
git clone https://huggingface.co/NeoPy/hugging-c-ai
cd hugging-c-ai
npm install
2. Configure environment
cp .env.example .env
Open .env and fill in:
- HuggingFace OAuth: create at https://huggingface.co/settings/applications/new (callback URL:
http://localhost:3000/api/auth/callback/huggingface) - At least one AI provider key (OpenAI, Anthropic, Groq, or HF_TOKEN)
- (Optional) Stripe keys if you want to sell credits
3. Initialize the database
npx prisma db push
npx prisma generate
This creates a SQLite file at ./dev.db. No external database required!
4. Run the dev server
npm run dev
Open http://localhost:3000, click Continue with HuggingFace, and start chatting.
π§© Adding a New LLM Provider
The provider abstraction is in src/lib/ai/. To add a new provider:
Create the adapter at
src/lib/ai/<provider>.js:export async function callMyProvider({ model, messages, systemPrompt, temperature, maxTokens, stream, apiKey, onToken }) { // ... call your LLM SDK return { text, usage: { promptTokens, completionTokens } }; }Register it in
src/lib/ai/providers.js:case "myprovider": return callMyProvider({ ... });Add models to the catalog in
src/lib/ai/models.js:{ id: "myprovider:my-model", label: "My Model", provider: "myprovider", cost: 1, supportsStreaming: true, contextWindow: 32_000 }Add env var mapping in
src/lib/ai/providers.jsβresolveApiKey()and insrc/lib/config.js.
That's it β the model appears in the UI selector automatically.
π¨ Themes
Five built-in dark themes via NEXT_PUBLIC_THEME:
slate-indigo(default)cyberpunk(pink/cyan)emerald(green)sunset(orange)midnight(pure B/W)
π Deploy to HuggingFace Spaces
- Click Duplicate to HF Space in the navbar (top-right)
- In your duplicated Space, set the following secrets:
DATABASE_URLβfile:./dev.dbfor SQLite, or a Postgres URLHF_CLIENT_ID,HF_CLIENT_SECRETβ your HF OAuth app (callback URL must point to your Space)NEXTAUTH_SECRETβopenssl rand -base64 32NEXTAUTH_URLβhttps://<your-space>.hf.space- Provider keys:
OPENAI_API_KEY,ANTHROPIC_API_KEY,GROQ_API_KEY,HF_TOKEN(at least one)
- Run
npx prisma db push && npx prisma generateonce (in the Space terminal)
For production at scale, swap SQLite for Postgres by setting DATABASE_URL to a postgresql:// URL and switching the Prisma adapter in src/lib/prisma.js to @prisma/adapter-pg.
π License
MIT. Upstream credit: Open Character AI.