Spaces:
Running
Running
File size: 12,885 Bytes
3bdfb08 a2cb1a0 5c36004 10d9df3 95d4297 10d9df3 3bdfb08 10d9df3 5c36004 3bdfb08 10d9df3 3bdfb08 5c36004 3bdfb08 10d9df3 3bdfb08 048209c 3bdfb08 048209c 3bdfb08 048209c 3bdfb08 95d4297 048209c 3bdfb08 048209c 3bdfb08 048209c 3bdfb08 048209c 3bdfb08 048209c 3bdfb08 048209c 3bdfb08 048209c 3bdfb08 048209c 5c36004 048209c 3bdfb08 03c1653 3bdfb08 03c1653 3bdfb08 03c1653 3bdfb08 03c1653 3bdfb08 03c1653 3bdfb08 5c36004 048209c 10d9df3 3bdfb08 10d9df3 048209c 3bdfb08 10d9df3 3bdfb08 10d9df3 3bdfb08 048209c 95d4297 3bdfb08 048209c 5c36004 048209c 03c1653 3bdfb08 03c1653 3bdfb08 048209c 3bdfb08 048209c 3bdfb08 048209c 3bdfb08 048209c 03c1653 3bdfb08 03c1653 3bdfb08 048209c 03c1653 048209c 95d4297 3bdfb08 048209c 3bdfb08 048209c 3bdfb08 048209c 3bdfb08 048209c 3bdfb08 048209c 03c1653 048209c 95d4297 048209c 3bdfb08 03c1653 3bdfb08 048209c 3bdfb08 03c1653 3bdfb08 03c1653 3bdfb08 a2cb1a0 3bdfb08 03c1653 3bdfb08 03c1653 3bdfb08 a2cb1a0 3bdfb08 03c1653 3bdfb08 048209c 10d9df3 3bdfb08 | 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 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 | ```html
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>مشاور مبلمان</title>
<style>
* { box-sizing: border-box; font-family: 'Segoe UI', Tahoma, sans-serif; }
body {
background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
min-height: 100vh;
display: flex;
justify-content: center;
align-items: center;
padding: 20px;
margin: 0;
}
.container {
max-width: 850px;
width: 100%;
background: white;
border-radius: 30px;
padding: 35px;
box-shadow: 0 20px 60px rgba(0,0,0,0.3);
}
h1 { text-align: center; color: #2c3e50; margin-top: 0; }
.subtitle { text-align: center; color: #7f8c8d; margin-bottom: 25px; }
.upload-area {
border: 3px dashed #667eea;
border-radius: 20px;
padding: 40px 20px;
text-align: center;
background: #f8f9fa;
cursor: pointer;
transition: 0.3s;
}
.upload-area:hover { background: #e9ecef; border-color: #764ba2; }
.upload-area input[type="file"] {
display: block;
margin: 15px auto;
padding: 10px;
border: 1px solid #ccc;
border-radius: 10px;
width: 100%;
max-width: 300px;
cursor: pointer;
}
#image-preview {
max-width: 100%;
max-height: 350px;
border-radius: 15px;
margin: 15px 0;
display: none;
box-shadow: 0 5px 15px rgba(0,0,0,0.1);
}
.btn-analyze {
background: #667eea;
color: white;
border: none;
padding: 16px 20px;
border-radius: 50px;
font-size: 1.2rem;
font-weight: bold;
cursor: pointer;
width: 100%;
transition: 0.3s;
margin-top: 10px;
}
.btn-analyze:hover { background: #764ba2; transform: scale(1.01); }
.btn-analyze:disabled { opacity: 0.6; cursor: not-allowed; }
.result-box {
background: #f8f9fa;
padding: 20px;
border-radius: 15px;
margin-top: 20px;
white-space: pre-wrap;
font-family: 'Courier New', monospace;
display: none;
border-right: 5px solid #667eea;
max-height: 500px;
overflow-y: auto;
}
.loading { display: none; text-align: center; padding: 30px 0; }
.spinner {
border: 5px solid #f3f3f3;
border-top: 5px solid #667eea;
border-radius: 50%;
width: 50px;
height: 50px;
animation: spin 1s linear infinite;
margin: 0 auto;
}
@keyframes spin { 0% { transform: rotate(0deg); } 100% { transform: rotate(360deg); } }
.tip {
background: #fff3cd;
padding: 15px;
border-radius: 12px;
margin-top: 20px;
text-align: center;
border: 1px solid #ffc107;
font-size: 0.95rem;
}
.model-selector {
margin: 15px 0;
text-align: center;
}
.model-selector select {
padding: 10px 20px;
border-radius: 30px;
border: 2px solid #667eea;
font-size: 1rem;
background: white;
cursor: pointer;
}
.model-selector select:focus { outline: none; border-color: #764ba2; }
</style>
</head>
<body>
<div class="container">
<h1>🪑 مشاور هوشمند مبلمان</h1>
<p class="subtitle">عکس مبل رو آپلود کن تا هوش مصنوعی تحلیلش کنه</p>
<div class="model-selector">
<label for="modelSelect">🧠 انتخاب هوش مصنوعی:</label>
<select id="modelSelect">
<option value="Salesforce/blip-image-captioning-base">BLIP (توصیف تصویر)</option>
<option value="nlpconnect/vit-gpt2-image-captioning">ViT-GPT2 (توصیف تصویر)</option>
<option value="microsoft/git-base-coco">GIT (توصیف دقیق)</option>
<option value="HuggingFaceH4/zephyr-7b-beta">Zephyr-7B (متنی - قدرتمند)</option>
<option value="mistralai/Mistral-7B-Instruct-v0.3">Mistral-7B (متنی - حرفهای)</option>
</select>
</div>
<div class="upload-area" id="uploadArea">
<label for="fileInput" style="display:block; margin-bottom:10px;">
<span style="font-size:3rem; display:block;">📸</span>
<strong>برای آپلود عکس کلیک کن</strong><br>
<small>یا عکس رو بکش و اینجا رها کن</small>
</label>
<input type="file" id="fileInput" accept="image/*">
</div>
<img id="image-preview" alt="پیشنمایش عکس">
<div class="loading" id="loading">
<div class="spinner"></div>
<p style="margin-top:15px; color:#2c3e50;">🧠 هوش مصنوعی در حال تحلیل عکس...</p>
<small style="color:#7f8c8d;">این کار ممکنه چند ثانیه طول بکشه</small>
</div>
<button class="btn-analyze" id="analyzeBtn">🔍 تحلیل با هوش مصنوعی</button>
<div class="result-box" id="resultBox"></div>
<div class="tip">
💡 <strong>نکته:</strong> میتونی بین مدلهای مختلف یکی رو انتخاب کنی. هرکدوم یه جور تحلیل میکنن.
</div>
</div>
<script>
const HF_TOKEN = "";
const fileInput = document.getElementById('fileInput');
const uploadArea = document.getElementById('uploadArea');
const preview = document.getElementById('image-preview');
const analyzeBtn = document.getElementById('analyzeBtn');
const resultBox = document.getElementById('resultBox');
const loading = document.getElementById('loading');
const modelSelect = document.getElementById('modelSelect');
let selectedFile = null;
let isAnalyzing = false;
fileInput.addEventListener('change', function(e) {
const file = this.files[0];
if (file) {
selectedFile = file;
const reader = new FileReader();
reader.onload = function(e) {
preview.src = e.target.result;
preview.style.display = 'block';
resultBox.style.display = 'none';
};
reader.readAsDataURL(file);
}
});
uploadArea.addEventListener('click', function(e) {
if (e.target.tagName !== 'INPUT') {
fileInput.click();
}
});
uploadArea.addEventListener('dragover', (e) => {
e.preventDefault();
uploadArea.style.borderColor = '#764ba2';
uploadArea.style.background = '#e9ecef';
});
uploadArea.addEventListener('dragleave', () => {
uploadArea.style.borderColor = '#667eea';
uploadArea.style.background = '#f8f9fa';
});
uploadArea.addEventListener('drop', (e) => {
e.preventDefault();
uploadArea.style.borderColor = '#667eea';
uploadArea.style.background = '#f8f9fa';
const file = e.dataTransfer.files[0];
if (file) {
selectedFile = file;
const reader = new FileReader();
reader.onload = function(e) {
preview.src = e.target.result;
preview.style.display = 'block';
resultBox.style.display = 'none';
};
reader.readAsDataURL(file);
fileInput.files = e.dataTransfer.files;
}
});
analyzeBtn.addEventListener('click', async function() {
if (!selectedFile) {
alert('⚠️ لطفاً اول یه عکس انتخاب کن!');
return;
}
if (isAnalyzing) return;
if (!HF_TOKEN) {
resultBox.style.display = 'block';
resultBox.innerHTML = `
❌ **توکن پیدا نشد!**
لطفاً توکن رو در Settings > Repository secrets با اسم HF_TOKEN اضافه کن.
`;
return;
}
const selectedModel = modelSelect.value;
const API_URL = `https://api-inference.huggingface.co/models/${selectedModel}`;
isAnalyzing = true;
analyzeBtn.disabled = true;
analyzeBtn.textContent = '⏳ در حال تحلیل...';
loading.style.display = 'block';
resultBox.style.display = 'none';
try {
const reader = new FileReader();
const base64Image = await new Promise((resolve) => {
reader.onload = (e) => resolve(e.target.result.split(',')[1]);
reader.readAsDataURL(selectedFile);
});
const response = await fetch(API_URL, {
method: 'POST',
headers: {
'Authorization': `Bearer ${HF_TOKEN}`,
'Content-Type': 'application/json'
},
body: JSON.stringify({
inputs: base64Image,
parameters: { max_new_tokens: 500 }
})
});
if (!response.ok) {
const errorText = await response.text();
throw new Error(`خطا: ${response.status} - ${errorText}`);
}
const result = await response.json();
let analysis = "";
if (Array.isArray(result) && result.length > 0) {
if (result[0].generated_text) {
analysis = result[0].generated_text;
} else if (result[0].label) {
analysis = result.map(r => `${r.label}: ${(r.score * 100).toFixed(1)}%`).join('\n');
} else {
analysis = JSON.stringify(result[0], null, 2);
}
} else if (result.generated_text) {
analysis = result.generated_text;
} else if (result.error) {
throw new Error(result.error);
} else {
analysis = JSON.stringify(result, null, 2);
}
loading.style.display = 'none';
resultBox.style.display = 'block';
const modelName = selectedModel.split('/').pop();
resultBox.innerHTML = `
🧠 **تحلیل با مدل:** ${modelName}
📝 **توضیحات:**
${analysis}
🎨 **پیشنهادات طراحی:**
• اگر مبلمان تشخیص داده شده، از پارچه کتان یا مخمل استفاده کن
• رنگهای طوسی، آبی نفتی یا کرم خیلی مناسبن
• برای هماهنگی با دکوراسیون، از رنگهای مکمل استفاده کن
• ابعاد مبل رو با فضای اتاق هماهنگ کن
💡 **نکته:** هر مدل هوش مصنوعی یه جور تحلیل میکنه. میتونی مدلهای مختلف رو امتحان کنی.
`;
} catch (error) {
loading.style.display = 'none';
resultBox.style.display = 'block';
resultBox.innerHTML = `
❌ **خطا در تحلیل**
${error.message}
📌 **راه حل:**
• چند دقیقه دیگه دوباره تلاش کن
• یه مدل دیگه رو انتخاب کن
• مطمئن شو که اینترنت وصل هست
`;
} finally {
isAnalyzing = false;
analyzeBtn.disabled = false;
analyzeBtn.textContent = '🔍 تحلیل با هوش مصنوعی';
}
});
</script>
</body>
</html>
``` |