Alexey7878 commited on
Commit
927599f
·
verified ·
1 Parent(s): d81e7d7

Update index.html

Browse files
Files changed (1) hide show
  1. index.html +9 -16
index.html CHANGED
@@ -3,7 +3,7 @@
3
  <head>
4
  <meta charset="UTF-8">
5
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
6
- <title>HF API - Генерация</title>
7
  <style>
8
  body { font-family: system-ui, sans-serif; max-width: 600px; margin: 40px auto; padding: 20px; background: #f9fafb; color: #111827; }
9
  h2 { margin-top: 0; }
@@ -41,7 +41,7 @@
41
  </style>
42
  </head>
43
  <body>
44
- <h2>Генерация изображений (HF API)</h2>
45
 
46
  <label for="hf-token">Твой Access Token (hf_...):</label>
47
  <input type="password" id="hf-token" placeholder="Вставь токен">
@@ -70,7 +70,9 @@
70
  const errorContainer = document.getElementById('errorContainer');
71
  const outputImage = document.getElementById('outputImage');
72
 
73
- // Функция для показа полной ошибки
 
 
74
  function showFullError(title, details) {
75
  errorContainer.innerHTML = `
76
  <div class="error-block">
@@ -80,7 +82,6 @@
80
  `;
81
  }
82
 
83
- // Очистка ошибок
84
  function clearError() {
85
  errorContainer.innerHTML = '';
86
  }
@@ -96,7 +97,6 @@
96
  if (!prompt) return showFullError('Ошибка валидации', 'Нужен промпт!');
97
 
98
  btn.disabled = true;
99
- statusText.textContent = 'Отправка запроса на сервера HF...';
100
  outputImage.style.display = 'none';
101
 
102
  if (outputImage.src && outputImage.src.startsWith('blob:')) {
@@ -104,9 +104,10 @@
104
  }
105
 
106
  try {
107
- const apiUrl = `https://api-inference.huggingface.co/models/${model}`;
 
108
 
109
- statusText.textContent = `Запрос к: ${apiUrl}`;
110
 
111
  const response = await fetch(apiUrl, {
112
  method: 'POST',
@@ -118,21 +119,16 @@
118
  body: JSON.stringify({ inputs: prompt })
119
  });
120
 
121
- // Полная информация об ответе
122
  const responseInfo = `Status: ${response.status} ${response.statusText}\nURL: ${apiUrl}`;
123
 
124
  if (!response.ok) {
125
- // Читаем тело ошибки
126
  const errorBody = await response.text();
127
  let errorFormatted = errorBody;
128
 
129
- // Пытаемся распарсить JSON если это JSON
130
  try {
131
  const jsonError = JSON.parse(errorBody);
132
  errorFormatted = JSON.stringify(jsonError, null, 2);
133
- } catch (e) {
134
- // Если не JSON, оставляем как есть
135
- }
136
 
137
  const fullErrorDetails = `${responseInfo}\n\nResponse Body:\n${errorFormatted}`;
138
 
@@ -144,7 +140,6 @@
144
  statusText.textContent = 'Получаем картинку...';
145
  const blob = await response.blob();
146
 
147
- // Проверяем что это действительно картинка
148
  if (!blob.type.startsWith('image/')) {
149
  const textResponse = await blob.text();
150
  showFullError('Неожиданный ответ', `${responseInfo}\n\nОтвет не является изображением:\n${textResponse}`);
@@ -158,7 +153,6 @@
158
  statusText.textContent = '✅ Готово!';
159
 
160
  } catch (error) {
161
- // Логируем в консоль для отладки
162
  console.error('=== ПОЛНАЯ ОШИБКА ===');
163
  console.error(error);
164
  console.trace();
@@ -173,7 +167,6 @@
173
  `Откройте DevTools (F12) → вкладка Network (Сеть) → посмотрите на красный запрос.`
174
  );
175
  } else if (!errorContainer.innerHTML) {
176
- // Если ошибка еще не показана выше
177
  showFullError('Неизвестная ошибка',
178
  `Message: ${error.message}\n` +
179
  `Stack: ${error.stack || 'N/A'}`
 
3
  <head>
4
  <meta charset="UTF-8">
5
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
6
+ <title>HF API - Генерация (Новый API 2026)</title>
7
  <style>
8
  body { font-family: system-ui, sans-serif; max-width: 600px; margin: 40px auto; padding: 20px; background: #f9fafb; color: #111827; }
9
  h2 { margin-top: 0; }
 
41
  </style>
42
  </head>
43
  <body>
44
+ <h2>Генерация изображений (HF API 2026)</h2>
45
 
46
  <label for="hf-token">Твой Access Token (hf_...):</label>
47
  <input type="password" id="hf-token" placeholder="Вставь токен">
 
70
  const errorContainer = document.getElementById('errorContainer');
71
  const outputImage = document.getElementById('outputImage');
72
 
73
+ // НОВЫЙ API ENDPOINT 2026
74
+ const NEW_API_BASE = 'https://router.huggingface.co/hf-inference/models';
75
+
76
  function showFullError(title, details) {
77
  errorContainer.innerHTML = `
78
  <div class="error-block">
 
82
  `;
83
  }
84
 
 
85
  function clearError() {
86
  errorContainer.innerHTML = '';
87
  }
 
97
  if (!prompt) return showFullError('Ошибка валидации', 'Нужен промпт!');
98
 
99
  btn.disabled = true;
 
100
  outputImage.style.display = 'none';
101
 
102
  if (outputImage.src && outputImage.src.startsWith('blob:')) {
 
104
  }
105
 
106
  try {
107
+ // НОВЫЙ URL
108
+ const apiUrl = `${NEW_API_BASE}/${model}`;
109
 
110
+ statusText.textContent = `Запрос к новому API: ${apiUrl}`;
111
 
112
  const response = await fetch(apiUrl, {
113
  method: 'POST',
 
119
  body: JSON.stringify({ inputs: prompt })
120
  });
121
 
 
122
  const responseInfo = `Status: ${response.status} ${response.statusText}\nURL: ${apiUrl}`;
123
 
124
  if (!response.ok) {
 
125
  const errorBody = await response.text();
126
  let errorFormatted = errorBody;
127
 
 
128
  try {
129
  const jsonError = JSON.parse(errorBody);
130
  errorFormatted = JSON.stringify(jsonError, null, 2);
131
+ } catch (e) {}
 
 
132
 
133
  const fullErrorDetails = `${responseInfo}\n\nResponse Body:\n${errorFormatted}`;
134
 
 
140
  statusText.textContent = 'Получаем картинку...';
141
  const blob = await response.blob();
142
 
 
143
  if (!blob.type.startsWith('image/')) {
144
  const textResponse = await blob.text();
145
  showFullError('Неожиданный ответ', `${responseInfo}\n\nОтвет не является изображением:\n${textResponse}`);
 
153
  statusText.textContent = '✅ Готово!';
154
 
155
  } catch (error) {
 
156
  console.error('=== ПОЛНАЯ ОШИБКА ===');
157
  console.error(error);
158
  console.trace();
 
167
  `Откройте DevTools (F12) → вкладка Network (Сеть) → посмотрите на красный запрос.`
168
  );
169
  } else if (!errorContainer.innerHTML) {
 
170
  showFullError('Неизвестная ошибка',
171
  `Message: ${error.message}\n` +
172
  `Stack: ${error.stack || 'N/A'}`