diff --git a/.gitattributes b/.gitattributes index a6344aac8c09253b3b630fb776ae94478aa0275b..d8dfc202b95c4acbbc2f734bfd6185a9ad410d39 100644 --- a/.gitattributes +++ b/.gitattributes @@ -33,3 +33,4 @@ saved_model/**/* filter=lfs diff=lfs merge=lfs -text *.zip filter=lfs diff=lfs merge=lfs -text *.zst filter=lfs diff=lfs merge=lfs -text *tfevents* filter=lfs diff=lfs merge=lfs -text +node_modules/.bin/esbuild filter=lfs diff=lfs merge=lfs -text diff --git a/.github/workflows/sync-to-hf.yml b/.github/workflows/sync-to-hf.yml new file mode 100644 index 0000000000000000000000000000000000000000..323cbd2a2c363039abbd9e98c81eba31f0f9f965 --- /dev/null +++ b/.github/workflows/sync-to-hf.yml @@ -0,0 +1,19 @@ +name: Sync to Hugging Face hub +on: + push: + branches: [main] + workflow_dispatch: + +jobs: + sync-to-hub: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v3 + with: + fetch-depth: 0 + lfs: true + - name: Push to hub + env: + HF_TOKEN: ${{ secrets.HF_TOKEN }} + run: | + git push --force https://AUXteam:$HF_TOKEN@huggingface.co/spaces/AUXteam/UserSyncInterface main diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000000000000000000000000000000000000..a547bf36d8d11a4f89c59c144f24795749086dd1 --- /dev/null +++ b/.gitignore @@ -0,0 +1,24 @@ +# Logs +logs +*.log +npm-debug.log* +yarn-debug.log* +yarn-error.log* +pnpm-debug.log* +lerna-debug.log* + +node_modules +dist +dist-ssr +*.local + +# Editor directories and files +.vscode/* +!.vscode/extensions.json +.idea +.DS_Store +*.suo +*.ntvs* +*.njsproj +*.sln +*.sw? diff --git a/.hfignore b/.hfignore new file mode 100644 index 0000000000000000000000000000000000000000..7204bedad7f661734ff0e84a49b8268ddbbada28 --- /dev/null +++ b/.hfignore @@ -0,0 +1,5 @@ +node_modules/ +.git/ +test-results/ +.env +.env.local diff --git a/Agent.md b/Agent.md new file mode 100644 index 0000000000000000000000000000000000000000..5fec9e0fcffbdca5e5cd4e186a9f655fadcce3af --- /dev/null +++ b/Agent.md @@ -0,0 +1,81 @@ +# Agent Deployment Information + +This file informs further agents about deployment best practices and tricks for the UserSyncFrontend on Hugging Face Spaces. + +## 1. Deployment Configuration + +### Target Space +- **Profile:** Leon4gr45 +- **Space:** UserSyncFrontend +- **Full Identifier:** Leon4gr45/UserSyncFrontend +- **Frontend Port:** 7860 + +### Deployment Method +- **Docker SDK** + +### Mandatory Endpoints +- `/health`: Returns HTTP 200 when the app is ready. +- `/api-docs`: Documents all available API endpoints. Reachable at `https://leon4gr45-usersyncfrontend.hf.space/api-docs`. + +## 2. API Endpoints + +### /api/craft +- **Method:** POST +- **Purpose:** Run model inference via Blablador API to craft content. +- **Request:** `{"content": "string", "variation": "string"}` +- **Response:** `{"result": "string"}` + +### /api/config +- **Method:** GET +- **Purpose:** Retrieve OAuth configuration. + +### /login +- **Method:** GET +- **Purpose:** Initiate Hugging Face OAuth login flow. + +### /oauth/callback +- **Method:** GET +- **Purpose:** OAuth callback handler. + +### /api/user +- **Method:** GET +- **Purpose:** Get authenticated user information. + +### /api/logout +- **Method:** GET +- **Purpose:** Logout user and clear session. + +### /api/save-data +- **Method:** POST +- **Purpose:** Save simulation data. +- **Request:** `{"type": "string", "data": "any", "user": "string"}` + +### /api/list-data +- **Method:** GET +- **Purpose:** List saved simulation data. + +### /health +- **Method:** GET +- **Purpose:** Health check endpoint. + +## 3. Deployment Workflow + +### Clean Remote Space +```bash +hf repos ls --repo-type space Leon4gr45/UserSyncFrontend +hf repos delete-files Leon4gr45/UserSyncFrontend --repo-type space +``` + +### Standard Deployment Command +```bash +hf upload Leon4gr45/UserSyncFrontend --repo-type=space +``` + +### Monitoring Logs +```bash +# Build logs +curl -N -H "Authorization: Bearer " "https://huggingface.co/api/spaces/Leon4gr45/UserSyncFrontend/logs/build" + +# Run logs +curl -N -H "Authorization: Bearer " "https://huggingface.co/api/spaces/Leon4gr45/UserSyncFrontend/logs/run" +``` diff --git a/App.tsx b/App.tsx new file mode 100644 index 0000000000000000000000000000000000000000..377c09f42457f63b4b3d3807634b345a764ce52b --- /dev/null +++ b/App.tsx @@ -0,0 +1,137 @@ + +import React, { useState, useEffect } from 'react'; +import { X } from 'lucide-react'; +import Navbar from './components/Navbar'; +import Hero from './components/Hero'; +import TrustedBy from './components/TrustedBy'; +import ProductOverview from './components/ProductOverview'; +import InteractiveDemo from './components/InteractiveDemo'; +import UseCases from './components/UseCases'; +import HowItWorks from './components/HowItWorks'; +import Accuracy from './components/Accuracy'; +import Documentation from './components/Documentation'; +import FAQ from './components/FAQ'; +import Footer from './components/Footer'; +import SimulationPage from './components/SimulationPage'; +import ChatPage from './components/ChatPage'; +import ProductGuide from './components/ProductGuide'; + +function App() { + const [currentView, setCurrentView] = useState<'landing' | 'simulation' | 'chat' | 'guide'>('simulation'); + const [user, setUser] = useState(null); + const [simulationResult, setSimulationResult] = useState(null); + + useEffect(() => { + const fetchUser = async () => { + try { + const response = await fetch('/api/user'); + if (response.ok) { + const data = await response.json(); + setUser(data); + } + } catch (error) { + console.error("Failed to fetch user:", error); + } + }; + fetchUser(); + + // Listen for storage changes in case of popup login + const handleStorage = () => fetchUser(); + window.addEventListener('storage', handleStorage); + return () => window.removeEventListener('storage', handleStorage); + }, []); + + const loginWithHF = () => { + // Open in a new tab to pop out of iframe + window.open('/login', '_blank'); + }; + + const handleLogout = async () => { + await fetch('/api/logout'); + setUser(null); + }; + + const startSimulation = () => { + setCurrentView('simulation'); + window.scrollTo(0,0); + }; + + const goBackToLanding = () => { + setCurrentView('landing'); + }; + + const openChat = () => { + setCurrentView('chat'); + }; + + const openGuide = () => { + setCurrentView('guide'); + }; + + const goBackToSimulation = () => { + setCurrentView('simulation'); + }; + + if (currentView === 'guide') { + return ( +
+ + +
+ ); + } + + if (currentView === 'simulation') { + return ( + + ); + } + + if (currentView === 'conversation') { + return ; + } + + if (currentView === 'chat') { + return ( + + ); + } + + return ( +
+ +
+ + + + + + + + + +
+
+
+ ); +} + +export default App; \ No newline at end of file diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..b3076dee837582f41a4eb9a62754527a23746fc7 --- /dev/null +++ b/Dockerfile @@ -0,0 +1,24 @@ +FROM node:20-slim AS build +WORKDIR /app +COPY package*.json ./ +RUN npm install +COPY . . +RUN npm run build + +FROM node:20-slim +WORKDIR /app + +# Use the existing node user +USER node +ENV HOME=/home/node \ + PATH=/home/node/.local/bin:$PATH + +WORKDIR $HOME/app + +COPY --from=build --chown=node:node /app/dist ./dist +COPY --from=build --chown=node:node /app/package*.json ./ +RUN npm install --only=production +COPY --chown=node:node server.cjs ./ + +EXPOSE 7860 +CMD ["node", "server.cjs"] diff --git a/README.md b/README.md index ec4e8476bd2c6181cc09f0f2cac111728d083bf9..867857ec601a19f69a9c5feff08feaa8bed66a2b 100644 --- a/README.md +++ b/README.md @@ -1,10 +1,31 @@ --- title: UserSyncFrontend -emoji: 🐨 -colorFrom: green +emoji: 🔄 +colorFrom: blue colorTo: blue sdk: docker -pinned: false +app_port: 7860 +hf_oauth: true +persistent_storage: true --- -Check out the configuration reference at https://huggingface.co/docs/hub/spaces-config-reference +
+GHBanner +
+ +# Run and deploy your AI Studio app + +This contains everything you need to run your app locally. + +View your app in AI Studio: https://ai.studio/apps/drive/1uBpK_suSmvNgTEgSyU7qMenb62ZRrQwX + +## Run Locally + +**Prerequisites:** Node.js + + +1. Install dependencies: + `npm install` +2. Set the `GEMINI_API_KEY` in [.env.local](.env.local) to your Gemini API key +3. Run the app: + `npm run dev` diff --git a/components/Accuracy.tsx b/components/Accuracy.tsx new file mode 100644 index 0000000000000000000000000000000000000000..34abea45f533fd2c3c9160ddf99336b3d8d82e22 --- /dev/null +++ b/components/Accuracy.tsx @@ -0,0 +1,86 @@ +import React from 'react'; +import { BarChart, Bar, XAxis, YAxis, Tooltip, ResponsiveContainer, Cell } from 'recharts'; + +const data = [ + { name: 'SyncUsers', score: 82, color: '#ffffff' }, // White + { name: 'Claude 3.7 Sonnet', score: 64, color: '#4b5563' }, // Gray-600 + { name: 'Gemini 1.5 pro', score: 63, color: '#4b5563' }, + { name: 'GPT-4o', score: 60, color: '#4b5563' }, + { name: 'GPT-3.5 Turbo', score: 54, color: '#4b5563' }, +]; + +const Accuracy: React.FC = () => { + return ( +
+
+
+
Accuracy
+

+ SyncUsers is 30% more accurate at predicting engagement than standard LLMs. +

+ +
+

Success rate at picking winners from pairs of LinkedIn posts

+
+ + + + + + + {data.map((entry, index) => ( + + ))} + + + + {/* Def for gradient */} + + + + + + + + +
+ {/* Custom Labels overlay for scores since Recharts labels are tricky with layout vertical sometimes */} +
+ {/* Placeholder for accessibility */} +
+
+
+ + {/* Right 3D Visual */} +
+ {/* Abstract 3D Bar representation */} +
+
+
+
+ +
+
+
+
+ +
+ Λ +
+
+
+
+ ); +}; + +export default Accuracy; \ No newline at end of file diff --git a/components/ChatPage.tsx b/components/ChatPage.tsx new file mode 100644 index 0000000000000000000000000000000000000000..a5c865fb5c0fca405ea7a3ee30d19dfca419b20a --- /dev/null +++ b/components/ChatPage.tsx @@ -0,0 +1,466 @@ + +import React, { useState, useRef, useEffect } from 'react'; +import { X, ClipboardList, Linkedin, Instagram, Mail, Layout, Edit3, MonitorPlay, Lightbulb, Image, Plus, Sparkles, Zap, Video, Megaphone, Link as LinkIcon, Loader2, RefreshCw, CheckCircle2, MessageSquare } from 'lucide-react'; +import { GradioService } from '../services/gradioService'; + +// --- Types --- +interface ChatPageProps { + onBack: () => void; + simulationResult: any; + setSimulationResult: (res: any) => void; +} + +// --- Sub-components (Modular Structure) --- + +const ChatButton: React.FC<{ label: string; primary?: boolean; icon?: React.ReactNode; onClick?: () => void; className?: string }> = ({ label, primary, icon, onClick, className = "" }) => ( + +); + +const CategoryCard: React.FC<{ + title: string; + options: { label: string; icon: React.ReactNode }[]; + selectedVariation: string; + onSelect: (label: string) => void; +}> = ({ title, options, selectedVariation, onSelect }) => ( +
+

{title}

+
+ {options.map((option) => ( +
onSelect(option.label)} + className={`group flex items-center gap-3 p-3 rounded-xl cursor-pointer border transition-all duration-200 + ${selectedVariation === option.label + ? 'bg-teal-900/20 border-teal-500/50 text-white' + : 'hover:bg-gray-900/80 border-transparent hover:border-gray-800'}`} + > +
+ {option.icon} +
+ {option.label} +
+ ))} +
+
+); + +const ChatInput: React.FC<{ onSimulate: (msg: string) => void; onHelpMeCraft: (msg: string) => void; isSimulating: boolean }> = ({ onSimulate, onHelpMeCraft, isSimulating }) => { + const [message, setMessage] = useState(''); + const [uploadedFiles, setUploadedFiles] = useState([]); + const fileInputRef = useRef(null); + + const handleUploadClick = () => { + fileInputRef.current?.click(); + }; + + const handleFileChange = (e: React.ChangeEvent) => { + const files = e.target.files; + if (files && files.length > 0) { + const newFiles = Array.from(files); + setUploadedFiles(prev => [...prev, ...newFiles]); + console.log("Selected files:", newFiles.map(f => f.name)); + } + }; + + const removeFile = (index: number) => { + setUploadedFiles(prev => prev.filter((_, i) => i !== index)); + }; + + return ( +
+
+ {uploadedFiles.length > 0 && ( +
+ {uploadedFiles.map((file, idx) => ( +
+ + {file.name} + +
+ ))} +
+ )} +