Spaces:
Configuration error
Configuration error
Download src/leads.py from Brettapps/Trifecta-Lab: direct link, hf CLI and curl.
- Browser
- Download file 2.03 kB
-
https://huggingface.co/spaces/Brettapps/Trifecta-Lab/resolve/main/src/leads.py
- Command line
-
hf download hf://spaces/Brettapps/Trifecta-Lab/src/leads.py
-
curl -L -o leads.py https://huggingface.co/spaces/Brettapps/Trifecta-Lab/resolve/main/src/leads.py
2.03 kB
| """Lead management module""" | |
| from fastapi import APIRouter, HTTPException | |
| from pydantic import BaseModel, Field | |
| from typing import List, Optional | |
| from datetime import datetime | |
| router = APIRouter(prefix="/leads") | |
| class LeadCreate(BaseModel): | |
| company: str | |
| name: Optional[str] = None | |
| email: Optional[str] = None | |
| job_title: str | |
| industry: str | |
| revenue: Optional[str] = None | |
| employees: Optional[int] = None | |
| source: Optional[str] = "organic" | |
| class LeadResponse(BaseModel): | |
| id: int | |
| company: str | |
| job_title: str | |
| score: int | |
| status: str | |
| created_at: str | |
| # In-memory store | |
| _leads_db = {} | |
| _next_id = 1 | |
| async def create_lead(lead: LeadCreate): | |
| global _next_id | |
| # Simple scoring | |
| score = 50 | |
| if lead.revenue: | |
| try: | |
| rev = float(lead.revenue.replace('$', '')) | |
| if rev > 50000000: | |
| score += 30 | |
| elif rev > 10000000: | |
| score += 20 | |
| except: | |
| pass | |
| _leads_db[_next_id] = { | |
| "company": lead.company, | |
| "job_title": lead.job_title, | |
| "score": score, | |
| "status": "new", | |
| "created_at": datetime.utcnow().isoformat() | |
| } | |
| lead_id = _next_id | |
| _next_id += 1 | |
| return LeadResponse( | |
| id=lead_id, | |
| company=lead.company, | |
| job_title=lead.job_title, | |
| score=score, | |
| status="new", | |
| created_at=datetime.utcnow().isoformat() | |
| ) | |
| async def list_leads(status: Optional[str] = None): | |
| results = [] | |
| for lid, data in _leads_db.items(): | |
| if status is None or data["status"] == status: | |
| results.append(LeadResponse( | |
| id=lid, | |
| company=data["company"], | |
| job_title=data["job_title"], | |
| score=data["score"], | |
| status=data["status"], | |
| created_at=data["created_at"] | |
| )) | |
| return results |