Update index.html
Browse files- index.html +9 -7
index.html
CHANGED
|
@@ -95,7 +95,7 @@
|
|
| 95 |
<!-- بخش ساخت QR Code -->
|
| 96 |
<div class="container">
|
| 97 |
<h2>ساخت QR Code</h2>
|
| 98 |
-
<textarea id="text-input" placeholder="متن مورد نظر را اینجا وارد کنید..." rows="4"
|
| 99 |
<button id="generate-btn" onclick="generateQRCode()">ساخت کد</button>
|
| 100 |
<div id="generate-result" class="result-box">
|
| 101 |
<div id="generate-loader" class="loader hidden"></div>
|
|
@@ -116,9 +116,7 @@
|
|
| 116 |
</div>
|
| 117 |
|
| 118 |
<script>
|
| 119 |
-
|
| 120 |
-
const API_URL_ROOT = "https://elias207-qrcode.hf.space/";
|
| 121 |
-
const API_BASE_URL = API_URL_ROOT + "gradio_api/";
|
| 122 |
|
| 123 |
function generateSessionHash() { return Math.random().toString(36).substring(2, 11); }
|
| 124 |
|
|
@@ -174,7 +172,8 @@
|
|
| 174 |
const result = await callGradioApi(0, [textInput], sessionHash);
|
| 175 |
|
| 176 |
if (result.output?.data?.[0]?.path) {
|
| 177 |
-
|
|
|
|
| 178 |
qrImage.src = imageUrl;
|
| 179 |
qrImage.classList.remove('hidden');
|
| 180 |
} else {
|
|
@@ -205,14 +204,17 @@
|
|
| 205 |
try {
|
| 206 |
const formData = new FormData();
|
| 207 |
formData.append("files", file);
|
| 208 |
-
|
|
|
|
|
|
|
|
|
|
| 209 |
if (!uploadRes.ok) throw new Error("آپلود فایل ناموفق بود.");
|
| 210 |
|
| 211 |
const uploadResult = await uploadRes.json();
|
| 212 |
const tempFilePath = uploadResult[0];
|
| 213 |
|
| 214 |
const sessionHash = generateSessionHash();
|
| 215 |
-
const fileData = [{"path": tempFilePath, "url":
|
| 216 |
const result = await callGradioApi(1, fileData, sessionHash);
|
| 217 |
|
| 218 |
if (result.output?.data?.[0]) {
|
|
|
|
| 95 |
<!-- بخش ساخت QR Code -->
|
| 96 |
<div class="container">
|
| 97 |
<h2>ساخت QR Code</h2>
|
| 98 |
+
<textarea id="text-input" placeholder="متن مورد نظر را اینجا وارد کنید..." rows="4">این بار درست کار میکند!</textarea>
|
| 99 |
<button id="generate-btn" onclick="generateQRCode()">ساخت کد</button>
|
| 100 |
<div id="generate-result" class="result-box">
|
| 101 |
<div id="generate-loader" class="loader hidden"></div>
|
|
|
|
| 116 |
</div>
|
| 117 |
|
| 118 |
<script>
|
| 119 |
+
const API_BASE_URL = "https://elias207-qrcode.hf.space/gradio_api/";
|
|
|
|
|
|
|
| 120 |
|
| 121 |
function generateSessionHash() { return Math.random().toString(36).substring(2, 11); }
|
| 122 |
|
|
|
|
| 172 |
const result = await callGradioApi(0, [textInput], sessionHash);
|
| 173 |
|
| 174 |
if (result.output?.data?.[0]?.path) {
|
| 175 |
+
// **اصلاح**: آدرس فایل هم باید از مسیر API خوانده شود
|
| 176 |
+
const imageUrl = API_BASE_URL + "file=" + result.output.data[0].path;
|
| 177 |
qrImage.src = imageUrl;
|
| 178 |
qrImage.classList.remove('hidden');
|
| 179 |
} else {
|
|
|
|
| 204 |
try {
|
| 205 |
const formData = new FormData();
|
| 206 |
formData.append("files", file);
|
| 207 |
+
|
| 208 |
+
// *** مهم: اینجا نقطه اصلی اصلاح بود ***
|
| 209 |
+
// آدرس آپلود باید به API_BASE_URL اشاره کند
|
| 210 |
+
const uploadRes = await fetch(API_BASE_URL + "upload", { method: "POST", body: formData });
|
| 211 |
if (!uploadRes.ok) throw new Error("آپلود فایل ناموفق بود.");
|
| 212 |
|
| 213 |
const uploadResult = await uploadRes.json();
|
| 214 |
const tempFilePath = uploadResult[0];
|
| 215 |
|
| 216 |
const sessionHash = generateSessionHash();
|
| 217 |
+
const fileData = [{"path": tempFilePath, "url": API_BASE_URL + "file=" + tempFilePath, "orig_name": file.name}];
|
| 218 |
const result = await callGradioApi(1, fileData, sessionHash);
|
| 219 |
|
| 220 |
if (result.output?.data?.[0]) {
|