Spaces:
Sleeping
Sleeping
File size: 14,517 Bytes
f3d5e99 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 | <!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8"/>
<meta name="viewport" content="width=device-width, initial-scale=1.0"/>
<title>πΎ Crop Classifier API β Developer Portal</title>
<link href="https://fonts.googleapis.com/css2?family=Inter:wght@300;400;500;600;700&family=Fira+Code:wght@400;500&display=swap" rel="stylesheet"/>
<style>
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
:root {
--green: #22c55e;
--green2: #16a34a;
--bg: #0a0f0d;
--card: #111a14;
--border: #1f2e22;
--text: #e2f0e6;
--muted: #6b8f74;
--accent: #bbf7d0;
}
body { font-family: 'Inter', sans-serif; background: var(--bg); color: var(--text);
min-height: 100vh; }
/* ββ Hero ββ */
.hero { text-align: center; padding: 72px 24px 48px; position: relative; overflow: hidden; }
.hero::before {
content: ''; position: absolute; inset: 0;
background: radial-gradient(ellipse 80% 60% at 50% 0%, rgba(34,197,94,.15) 0%, transparent 70%);
pointer-events: none;
}
.badge { display: inline-block; background: rgba(34,197,94,.15); border: 1px solid rgba(34,197,94,.3);
color: var(--green); padding: 4px 14px; border-radius: 99px; font-size: 13px; font-weight: 500;
margin-bottom: 20px; }
.hero h1 { font-size: clamp(2rem, 5vw, 3.2rem); font-weight: 700; line-height: 1.15; margin-bottom: 16px; }
.hero h1 span { color: var(--green); }
.hero p { color: var(--muted); font-size: 1.1rem; max-width: 540px; margin: 0 auto 40px; }
/* ββ Stats bar ββ */
.stats { display: flex; justify-content: center; gap: 40px; flex-wrap: wrap;
padding: 24px; border-top: 1px solid var(--border); border-bottom: 1px solid var(--border);
background: rgba(255,255,255,.02); }
.stat { text-align: center; }
.stat-val { font-size: 1.6rem; font-weight: 700; color: var(--green); }
.stat-lbl { font-size: 12px; color: var(--muted); margin-top: 2px; }
/* ββ Main layout ββ */
.container { max-width: 900px; margin: 0 auto; padding: 48px 24px; }
/* ββ Card ββ */
.card { background: var(--card); border: 1px solid var(--border); border-radius: 16px;
padding: 36px; margin-bottom: 32px; }
.card h2 { font-size: 1.3rem; font-weight: 600; margin-bottom: 8px; }
.card .sub { color: var(--muted); font-size: 14px; margin-bottom: 28px; }
/* ββ Form ββ */
.form-group { margin-bottom: 20px; }
label { display: block; font-size: 14px; font-weight: 500; margin-bottom: 8px; color: var(--accent); }
input { width: 100%; background: rgba(255,255,255,.05); border: 1px solid var(--border);
border-radius: 10px; padding: 13px 16px; color: var(--text); font-size: 15px;
font-family: inherit; outline: none; transition: border-color .2s; }
input:focus { border-color: var(--green); }
input::placeholder { color: var(--muted); }
.btn { width: 100%; background: var(--green); color: #000; border: none; border-radius: 10px;
padding: 14px; font-size: 16px; font-weight: 600; cursor: pointer;
transition: background .2s, transform .1s; font-family: inherit; }
.btn:hover { background: var(--green2); }
.btn:active { transform: scale(0.99); }
.btn:disabled { opacity: .6; cursor: not-allowed; }
/* ββ Result box ββ */
#result { display: none; margin-top: 28px; }
.result-header { display: flex; align-items: center; gap: 10px; margin-bottom: 20px; }
.result-header svg { width: 28px; color: var(--green); flex-shrink: 0; }
.result-header h3 { font-size: 1.1rem; font-weight: 600; }
.key-box { background: rgba(34,197,94,.08); border: 1px solid rgba(34,197,94,.25);
border-radius: 12px; padding: 20px; }
.key-label { font-size: 12px; color: var(--muted); text-transform: uppercase; letter-spacing: .05em;
margin-bottom: 10px; }
.key-display { display: flex; align-items: center; gap: 12px; }
.key-text { font-family: 'Fira Code', monospace; font-size: 15px; color: var(--green);
flex: 1; word-break: break-all; }
.copy-btn { background: rgba(34,197,94,.15); border: 1px solid rgba(34,197,94,.3); color: var(--green);
border-radius: 8px; padding: 8px 16px; font-size: 13px; font-weight: 500;
cursor: pointer; white-space: nowrap; transition: background .2s; font-family: inherit; }
.copy-btn:hover { background: rgba(34,197,94,.25); }
/* ββ Code tabs ββ */
.tabs { display: flex; gap: 4px; margin-bottom: -1px; }
.tab { background: transparent; border: 1px solid var(--border); border-bottom: none;
color: var(--muted); padding: 8px 18px; border-radius: 8px 8px 0 0; font-size: 13px;
cursor: pointer; font-family: inherit; transition: all .15s; }
.tab.active { background: #1a2e1e; color: var(--green); border-color: var(--border); }
.code-panel { display: none; background: #0d1a10; border: 1px solid var(--border);
border-radius: 0 12px 12px 12px; padding: 20px; overflow-x: auto; }
.code-panel.active { display: block; }
pre { font-family: 'Fira Code', monospace; font-size: 13px; line-height: 1.7; color: #c9d9cb; white-space: pre; }
.kw { color: #79c0ff; } .fn { color: #d2a8ff; } .str { color: #a5d6ff; }
.cm { color: #6b8f74; font-style: italic; } .key { color: #ffa657; }
/* Endpoints table */
table { width: 100%; border-collapse: collapse; font-size: 14px; }
th { text-align: left; color: var(--muted); font-weight: 500; padding: 8px 12px;
border-bottom: 1px solid var(--border); }
td { padding: 12px 12px; border-bottom: 1px solid rgba(255,255,255,.05); }
td:first-child { font-family: 'Fira Code', monospace; color: var(--green); font-size: 13px; }
tr:last-child td { border-bottom: none; }
.error-msg { color: #f87171; background: rgba(248,113,113,.1); border: 1px solid rgba(248,113,113,.2);
border-radius: 8px; padding: 12px 16px; font-size: 14px; margin-top: 16px; }
</style>
</head>
<body>
<div class="hero">
<div class="badge">πΎ Free API Β· No Credit Card</div>
<h1>Crop Classifier <span>API</span></h1>
<p>Identify 50 crop varieties from images using AI. Get your free API key in seconds β no approval needed.</p>
</div>
<div class="stats">
<div class="stat"><div class="stat-val">50</div><div class="stat-lbl">Crop Varieties</div></div>
<div class="stat"><div class="stat-val">93.48%</div><div class="stat-lbl">Model Accuracy</div></div>
<div class="stat"><div class="stat-val">Free</div><div class="stat-lbl">Forever</div></div>
<div class="stat"><div class="stat-val"><500ms</div><div class="stat-lbl">Fast Mode Speed</div></div>
</div>
<div class="container">
<!-- Get API Key Card -->
<div class="card">
<h2>π Get Your Free API Key</h2>
<p class="sub">Enter your name and email β your unique key is generated instantly.</p>
<div class="form-group">
<label for="name">Your Name / App Name</label>
<input id="name" type="text" placeholder="e.g. My Farm App" autocomplete="off"/>
</div>
<div class="form-group">
<label for="email">Email Address</label>
<input id="email" type="email" placeholder="you@example.com"/>
</div>
<button class="btn" id="getKeyBtn" onclick="getKey()">Generate API Key β</button>
<div id="errorMsg" class="error-msg" style="display:none;"></div>
<div id="result">
<div class="result-header">
<svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2">
<path d="M22 11.08V12a10 10 0 1 1-5.93-9.14"/><polyline points="22 4 12 14.01 9 11.01"/>
</svg>
<h3 id="resultTitle">Your API key is ready!</h3>
</div>
<div class="key-box">
<div class="key-label">Your API Key</div>
<div class="key-display">
<div class="key-text" id="apiKeyDisplay"></div>
<button class="copy-btn" onclick="copyKey()">Copy</button>
</div>
</div>
</div>
</div>
<!-- Code Examples -->
<div class="card">
<h2>π» Code Examples</h2>
<p class="sub">Copy the code for your language and replace <code style="color:var(--green)">YOUR_API_KEY</code>.</p>
<div class="tabs">
<button class="tab active" onclick="switchTab('js',this)">JavaScript</button>
<button class="tab" onclick="switchTab('py',this)">Python</button>
<button class="tab" onclick="switchTab('curl',this)">cURL</button>
</div>
<div class="code-panel active" id="tab-js"><pre><span class="cm">// Full analysis (crop name, quality, characteristics, explanation)</span>
<span class="kw">const</span> formData = <span class="kw">new</span> <span class="fn">FormData</span>();
formData.<span class="fn">append</span>(<span class="str">"file"</span>, imageFile); <span class="cm">// File from <input type="file"></span>
<span class="kw">const</span> response = <span class="kw">await</span> <span class="fn">fetch</span>(<span class="str">"https://vdx-0-crop-classifier-api.hf.space/predict"</span>, {
<span class="key">method</span>: <span class="str">"POST"</span>,
<span class="key">headers</span>: { <span class="str">"x-api-key"</span>: <span class="str">"YOUR_API_KEY"</span> },
<span class="key">body</span>: formData
});
<span class="kw">const</span> data = <span class="kw">await</span> response.<span class="fn">json</span>();
<span class="cm">// Use final_answer β has everything you need</span>
console.<span class="fn">log</span>(data.final_answer.<span class="key">crop_name</span>); <span class="cm">// "Wheat"</span>
console.<span class="fn">log</span>(data.final_answer.<span class="key">quality</span>); <span class="cm">// "Excellent"</span>
console.<span class="fn">log</span>(data.final_answer.<span class="key">characteristics</span>); <span class="cm">// "Golden stalks..."</span>
console.<span class="fn">log</span>(data.final_answer.<span class="key">explanation</span>); <span class="cm">// "Full description..."</span></pre></div>
<div class="code-panel" id="tab-py"><pre><span class="kw">import</span> requests
<span class="kw">with</span> <span class="fn">open</span>(<span class="str">"crop.jpg"</span>, <span class="str">"rb"</span>) <span class="kw">as</span> f:
response = requests.<span class="fn">post</span>(
<span class="str">"https://vdx-0-crop-classifier-api.hf.space/predict"</span>,
headers={<span class="str">"x-api-key"</span>: <span class="str">"YOUR_API_KEY"</span>},
files={<span class="str">"file"</span>: f}
)
data = response.<span class="fn">json</span>()
answer = data[<span class="str">"final_answer"</span>]
<span class="fn">print</span>(answer[<span class="str">"crop_name"</span>]) <span class="cm"># Wheat</span>
<span class="fn">print</span>(answer[<span class="str">"quality"</span>]) <span class="cm"># Excellent</span>
<span class="fn">print</span>(answer[<span class="str">"characteristics"</span>]) <span class="cm"># Golden stalks...</span>
<span class="fn">print</span>(answer[<span class="str">"explanation"</span>]) <span class="cm"># Full description...</span></pre></div>
<div class="code-panel" id="tab-curl"><pre>curl -X POST <span class="str">"https://vdx-0-crop-classifier-api.hf.space/predict"</span> \
-H <span class="str">"x-api-key: YOUR_API_KEY"</span> \
-F <span class="str">"file=@/path/to/crop.jpg"</span></pre></div>
</div>
<!-- Endpoints table -->
<div class="card">
<h2>π‘ Endpoints</h2>
<p class="sub">Base URL: <code style="color:var(--green)">https://vdx-0-crop-classifier-api.hf.space</code></p>
<table>
<thead><tr><th>Endpoint</th><th>Description</th></tr></thead>
<tbody>
<tr><td>POST /predict</td><td>Full analysis β model + LLaMA AI expert (~10s)</td></tr>
<tr><td>POST /predict/fast</td><td>Model only β instant response (<500ms)</td></tr>
<tr><td>POST /register</td><td>Generate a new API key</td></tr>
<tr><td>GET /crops</td><td>List all 50 supported crop varieties</td></tr>
<tr><td>GET /docs</td><td>Interactive Swagger API documentation</td></tr>
</tbody>
</table>
</div>
</div>
<script>
let generatedKey = "";
async function getKey() {
const name = document.getElementById("name").value.trim();
const email = document.getElementById("email").value.trim();
const err = document.getElementById("errorMsg");
const btn = document.getElementById("getKeyBtn");
err.style.display = "none";
if (!name) { showError("Please enter your name."); return; }
if (!email) { showError("Please enter your email."); return; }
if (!/^[^\s@]+@[^\s@]+\.[^\s@]+$/.test(email)) { showError("Please enter a valid email."); return; }
btn.disabled = true;
btn.textContent = "Generating...";
try {
const res = await fetch("/register", {
method: "POST",
headers: {"Content-Type": "application/json"},
body: JSON.stringify({name, email})
});
const data = await res.json();
if (!res.ok) throw new Error(data.detail?.message || data.detail || "Failed");
generatedKey = data.api_key;
document.getElementById("apiKeyDisplay").textContent = data.api_key;
document.getElementById("resultTitle").textContent =
data.is_new ? `Welcome, ${name}! Your API key is ready.` : `Welcome back, ${name}! Here's your key.`;
document.getElementById("result").style.display = "block";
btn.textContent = "β Key Generated";
} catch(e) {
showError(e.message);
btn.disabled = false;
btn.textContent = "Generate API Key β";
}
}
function showError(msg) {
const err = document.getElementById("errorMsg");
err.textContent = msg;
err.style.display = "block";
}
function copyKey() {
navigator.clipboard.writeText(generatedKey);
const btn = document.querySelector(".copy-btn");
btn.textContent = "Copied!";
setTimeout(() => btn.textContent = "Copy", 2000);
}
function switchTab(lang, el) {
document.querySelectorAll(".tab").forEach(t => t.classList.remove("active"));
document.querySelectorAll(".code-panel").forEach(p => p.classList.remove("active"));
el.classList.add("active");
document.getElementById("tab-"+lang).classList.add("active");
}
document.getElementById("email").addEventListener("keydown", e => {
if (e.key === "Enter") getKey();
});
</script>
</body>
</html>
|