Spaces:
Sleeping
Sleeping
fix
Browse files- app/app_revised.py +21 -3
- app/static/js/app-device.js +61 -29
- requirements.txt +1 -0
app/app_revised.py
CHANGED
|
@@ -3,17 +3,22 @@ RAG κ²μ μ±λ΄ μΉ μ ν리μΌμ΄μ
(μ₯μΉ κ΄λ¦¬ κΈ°λ₯ ν΅ν©)
|
|
| 3 |
"""
|
| 4 |
|
| 5 |
import os
|
|
|
|
| 6 |
import logging
|
|
|
|
| 7 |
import threading
|
| 8 |
-
|
| 9 |
-
from flask import Flask, send_from_directory
|
|
|
|
|
|
|
| 10 |
from dotenv import load_dotenv
|
| 11 |
from functools import wraps
|
|
|
|
| 12 |
|
| 13 |
# λ‘κ±° μ€μ
|
| 14 |
logging.basicConfig(
|
| 15 |
format='%(asctime)s - %(name)s - %(levelname)s - %(message)s',
|
| 16 |
-
level=logging.DEBUG
|
| 17 |
)
|
| 18 |
logger = logging.getLogger(__name__)
|
| 19 |
|
|
@@ -57,6 +62,9 @@ except ImportError as e:
|
|
| 57 |
# Flask μ± μ΄κΈ°ν
|
| 58 |
app = Flask(__name__)
|
| 59 |
|
|
|
|
|
|
|
|
|
|
| 60 |
# μΈμ
μ€μ
|
| 61 |
app.secret_key = os.getenv('FLASK_SECRET_KEY', 'rag_chatbot_fixed_secret_key_12345')
|
| 62 |
|
|
@@ -226,6 +234,16 @@ def initialize_app():
|
|
| 226 |
# λΌμ°νΈ λ±λ‘
|
| 227 |
register_all_routes()
|
| 228 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 229 |
logger.info("μ± μ΄κΈ°ν μλ£")
|
| 230 |
|
| 231 |
|
|
|
|
| 3 |
"""
|
| 4 |
|
| 5 |
import os
|
| 6 |
+
import json
|
| 7 |
import logging
|
| 8 |
+
import tempfile
|
| 9 |
import threading
|
| 10 |
+
import datetime
|
| 11 |
+
from flask import Flask, request, jsonify, render_template, send_from_directory, session, redirect, url_for
|
| 12 |
+
from flask_cors import CORS
|
| 13 |
+
from werkzeug.utils import secure_filename
|
| 14 |
from dotenv import load_dotenv
|
| 15 |
from functools import wraps
|
| 16 |
+
from datetime import timedelta
|
| 17 |
|
| 18 |
# λ‘κ±° μ€μ
|
| 19 |
logging.basicConfig(
|
| 20 |
format='%(asctime)s - %(name)s - %(levelname)s - %(message)s',
|
| 21 |
+
level=logging.DEBUG # INFOμμ DEBUGλ‘ λ³κ²½νμ¬ λ μμΈν λ‘κ·Έ νμΈ
|
| 22 |
)
|
| 23 |
logger = logging.getLogger(__name__)
|
| 24 |
|
|
|
|
| 62 |
# Flask μ± μ΄κΈ°ν
|
| 63 |
app = Flask(__name__)
|
| 64 |
|
| 65 |
+
# CORS μ€μ μΆκ°
|
| 66 |
+
CORS(app, supports_credentials=True, resources={r"/api/*": {"origins": "*"}})
|
| 67 |
+
|
| 68 |
# μΈμ
μ€μ
|
| 69 |
app.secret_key = os.getenv('FLASK_SECRET_KEY', 'rag_chatbot_fixed_secret_key_12345')
|
| 70 |
|
|
|
|
| 234 |
# λΌμ°νΈ λ±λ‘
|
| 235 |
register_all_routes()
|
| 236 |
|
| 237 |
+
# 404 μ€λ₯ νΈλ€λ¬ μΆκ°
|
| 238 |
+
@app.errorhandler(404)
|
| 239 |
+
def not_found(e):
|
| 240 |
+
# JSON νμμΌλ‘ 404 μ€λ₯ μλ΅
|
| 241 |
+
return jsonify({
|
| 242 |
+
"success": False,
|
| 243 |
+
"error": "Endpoint not found",
|
| 244 |
+
"message": str(e)
|
| 245 |
+
}), 404
|
| 246 |
+
|
| 247 |
logger.info("μ± μ΄κΈ°ν μλ£")
|
| 248 |
|
| 249 |
|
app/static/js/app-device.js
CHANGED
|
@@ -257,7 +257,16 @@ const DeviceControl = {
|
|
| 257 |
method: 'GET'
|
| 258 |
});
|
| 259 |
|
| 260 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 261 |
|
| 262 |
if (response.ok && data.success) {
|
| 263 |
// μν νμΈ μ±κ³΅
|
|
@@ -310,7 +319,19 @@ const DeviceControl = {
|
|
| 310 |
method: 'GET'
|
| 311 |
});
|
| 312 |
|
| 313 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 314 |
|
| 315 |
if (response.ok && data.success) {
|
| 316 |
// λͺ©λ‘ μ‘°ν μ±κ³΅
|
|
@@ -458,7 +479,19 @@ const DeviceControl = {
|
|
| 458 |
body: JSON.stringify({})
|
| 459 |
}, 15000); // 15μ΄ νμμμ (μ€νμ μκ°μ΄ λ 걸릴 μ μμ)
|
| 460 |
|
| 461 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 462 |
|
| 463 |
if (response.ok && data.success) {
|
| 464 |
// μ€ν μ±κ³΅
|
|
@@ -466,11 +499,14 @@ const DeviceControl = {
|
|
| 466 |
this.showExecuteResult('success', `μ€ν μ±κ³΅: ${data.message || 'νλ‘κ·Έλ¨μ΄ μ±κ³΅μ μΌλ‘ μ€νλμμ΅λλ€.'}`);
|
| 467 |
|
| 468 |
// μμ€ν
μλ¦Ό
|
| 469 |
-
AppUtils.addSystemNotification(`νλ‘κ·Έλ¨ μ€ν μ±κ³΅: ${
|
| 470 |
} else {
|
| 471 |
// μ€ν μ€ν¨
|
| 472 |
console.error('νλ‘κ·Έλ¨ μ€ν μ€ν¨:', data);
|
| 473 |
this.showExecuteResult('error', `μ€ν μ€ν¨: ${data.error || 'μ μ μλ μ€λ₯'}`);
|
|
|
|
|
|
|
|
|
|
| 474 |
}
|
| 475 |
} catch (error) {
|
| 476 |
// μμΈ λ°μ
|
|
@@ -481,37 +517,15 @@ const DeviceControl = {
|
|
| 481 |
} else {
|
| 482 |
this.showExecuteResult('error', `νλ‘κ·Έλ¨ μ€ν μ€ μ€λ₯ λ°μ: ${error.message}`);
|
| 483 |
}
|
|
|
|
|
|
|
|
|
|
| 484 |
} finally {
|
| 485 |
// λ²νΌ λ€μ νμ±ν
|
| 486 |
this.elements.executeProgramBtn.disabled = false;
|
| 487 |
}
|
| 488 |
},
|
| 489 |
|
| 490 |
-
// μ νλ νλ‘κ·Έλ¨ μ΄λ¦ κ°μ Έμ€κΈ°
|
| 491 |
-
getSelectedProgramName: function() {
|
| 492 |
-
const dropdown = this.elements.programSelectDropdown;
|
| 493 |
-
const selectedOption = dropdown.options[dropdown.selectedIndex];
|
| 494 |
-
return selectedOption ? selectedOption.textContent : 'μ μ μλ νλ‘κ·Έλ¨';
|
| 495 |
-
},
|
| 496 |
-
|
| 497 |
-
// νλ‘κ·Έλ¨ λͺ©λ‘ μ€λ₯ νμ
|
| 498 |
-
showProgramsError: function(errorMessage) {
|
| 499 |
-
this.elements.programsList.innerHTML = `
|
| 500 |
-
<div class="error-message">
|
| 501 |
-
<i class="fas fa-exclamation-circle"></i> ${errorMessage}
|
| 502 |
-
<button class="retry-button" id="retryLoadProgramsBtn">
|
| 503 |
-
<i class="fas fa-sync"></i> λ€μ μλ
|
| 504 |
-
</button>
|
| 505 |
-
</div>
|
| 506 |
-
`;
|
| 507 |
-
|
| 508 |
-
// μ¬μλ λ²νΌ μ΄λ²€νΈ 리μ€λ
|
| 509 |
-
document.getElementById('retryLoadProgramsBtn').addEventListener('click', () => {
|
| 510 |
-
console.log('νλ‘κ·Έλ¨ λͺ©λ‘ μ¬μλ λ²νΌ ν΄λ¦');
|
| 511 |
-
this.loadProgramsList();
|
| 512 |
-
});
|
| 513 |
-
},
|
| 514 |
-
|
| 515 |
// μ€ν κ²°κ³Ό νμ
|
| 516 |
showExecuteResult: function(status, message) {
|
| 517 |
const resultElement = this.elements.executeResult;
|
|
@@ -542,6 +556,24 @@ const DeviceControl = {
|
|
| 542 |
default:
|
| 543 |
resultElement.textContent = message;
|
| 544 |
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 545 |
}
|
| 546 |
};
|
| 547 |
|
|
|
|
| 257 |
method: 'GET'
|
| 258 |
});
|
| 259 |
|
| 260 |
+
// μλ΅ μν μ½λ λ‘κΉ
|
| 261 |
+
console.log(`μ₯μΉ μν νμΈ μλ΅ μν: ${response.status}`);
|
| 262 |
+
|
| 263 |
+
let data;
|
| 264 |
+
try {
|
| 265 |
+
data = await response.json();
|
| 266 |
+
} catch (jsonError) {
|
| 267 |
+
console.error('JSON νμ± μ€λ₯:', jsonError, await response.text());
|
| 268 |
+
throw new Error(`μλ² μλ΅μ μ²λ¦¬ν μ μμ΅λλ€: ${jsonError.message}`);
|
| 269 |
+
}
|
| 270 |
|
| 271 |
if (response.ok && data.success) {
|
| 272 |
// μν νμΈ μ±κ³΅
|
|
|
|
| 319 |
method: 'GET'
|
| 320 |
});
|
| 321 |
|
| 322 |
+
// μλ΅ μν μ½λ λ‘κΉ
|
| 323 |
+
console.log(`νλ‘κ·Έλ¨ λͺ©λ‘ μ‘°ν μλ΅ μν: ${response.status}`);
|
| 324 |
+
|
| 325 |
+
let data;
|
| 326 |
+
try {
|
| 327 |
+
data = await response.json();
|
| 328 |
+
} catch (jsonError) {
|
| 329 |
+
console.error('JSON νμ± μ€λ₯:', jsonError);
|
| 330 |
+
// μλ΅ λ΄μ©μ ν
μ€νΈλ‘ νμΈ
|
| 331 |
+
const responseText = await response.text();
|
| 332 |
+
console.error('μλ΅ ν
μ€νΈ:', responseText);
|
| 333 |
+
throw new Error(`μλ² μλ΅μ μ²λ¦¬ν μ μμ΅λλ€: ${jsonError.message}`);
|
| 334 |
+
}
|
| 335 |
|
| 336 |
if (response.ok && data.success) {
|
| 337 |
// λͺ©λ‘ μ‘°ν μ±κ³΅
|
|
|
|
| 479 |
body: JSON.stringify({})
|
| 480 |
}, 15000); // 15μ΄ νμμμ (μ€νμ μκ°μ΄ λ 걸릴 μ μμ)
|
| 481 |
|
| 482 |
+
// μλ΅ μν μ½λ λ‘κΉ
|
| 483 |
+
console.log(`νλ‘κ·Έλ¨ μ€ν μλ΅ μν: ${response.status}`);
|
| 484 |
+
|
| 485 |
+
let data;
|
| 486 |
+
try {
|
| 487 |
+
data = await response.json();
|
| 488 |
+
} catch (jsonError) {
|
| 489 |
+
console.error('JSON νμ± μ€λ₯:', jsonError);
|
| 490 |
+
// μλ΅ λ΄μ©μ ν
μ€νΈλ‘ νμΈ
|
| 491 |
+
const responseText = await response.text();
|
| 492 |
+
console.error('μλ΅ ν
μ€νΈ:', responseText);
|
| 493 |
+
throw new Error(`μλ² μλ΅μ μ²λ¦¬ν μ μμ΅λλ€: ${jsonError.message}`);
|
| 494 |
+
}
|
| 495 |
|
| 496 |
if (response.ok && data.success) {
|
| 497 |
// μ€ν μ±κ³΅
|
|
|
|
| 499 |
this.showExecuteResult('success', `μ€ν μ±κ³΅: ${data.message || 'νλ‘κ·Έλ¨μ΄ μ±κ³΅μ μΌλ‘ μ€νλμμ΅λλ€.'}`);
|
| 500 |
|
| 501 |
// μμ€ν
μλ¦Ό
|
| 502 |
+
AppUtils.addSystemNotification(`νλ‘κ·Έλ¨ μ€ν μ±κ³΅: ${data.message || 'νλ‘κ·Έλ¨μ΄ μ±κ³΅μ μΌλ‘ μ€νλμμ΅λλ€.'}`);
|
| 503 |
} else {
|
| 504 |
// μ€ν μ€ν¨
|
| 505 |
console.error('νλ‘κ·Έλ¨ μ€ν μ€ν¨:', data);
|
| 506 |
this.showExecuteResult('error', `μ€ν μ€ν¨: ${data.error || 'μ μ μλ μ€λ₯'}`);
|
| 507 |
+
|
| 508 |
+
// μλ¬ λ©μμ§
|
| 509 |
+
AppUtils.addErrorMessage(`νλ‘κ·Έλ¨ μ€ν μ€ν¨: ${data.error || 'μ μ μλ μ€λ₯'}`);
|
| 510 |
}
|
| 511 |
} catch (error) {
|
| 512 |
// μμΈ λ°μ
|
|
|
|
| 517 |
} else {
|
| 518 |
this.showExecuteResult('error', `νλ‘κ·Έλ¨ μ€ν μ€ μ€λ₯ λ°μ: ${error.message}`);
|
| 519 |
}
|
| 520 |
+
|
| 521 |
+
// μλ¬ λ©μμ§
|
| 522 |
+
AppUtils.addErrorMessage(`νλ‘κ·Έλ¨ μ€ν μ€ μ€λ₯ λ°μ: ${error.message}`);
|
| 523 |
} finally {
|
| 524 |
// λ²νΌ λ€μ νμ±ν
|
| 525 |
this.elements.executeProgramBtn.disabled = false;
|
| 526 |
}
|
| 527 |
},
|
| 528 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 529 |
// μ€ν κ²°κ³Ό νμ
|
| 530 |
showExecuteResult: function(status, message) {
|
| 531 |
const resultElement = this.elements.executeResult;
|
|
|
|
| 556 |
default:
|
| 557 |
resultElement.textContent = message;
|
| 558 |
}
|
| 559 |
+
},
|
| 560 |
+
|
| 561 |
+
// νλ‘κ·Έλ¨ λͺ©λ‘ μ€λ₯ νμ
|
| 562 |
+
showProgramsError: function(errorMessage) {
|
| 563 |
+
this.elements.programsList.innerHTML = `
|
| 564 |
+
<div class="error-message">
|
| 565 |
+
<i class="fas fa-exclamation-circle"></i> ${errorMessage}
|
| 566 |
+
<button class="retry-button" id="retryLoadProgramsBtn">
|
| 567 |
+
<i class="fas fa-sync"></i> λ€μ μλ
|
| 568 |
+
</button>
|
| 569 |
+
</div>
|
| 570 |
+
`;
|
| 571 |
+
|
| 572 |
+
// μ¬μλ λ²νΌ μ΄λ²€νΈ 리μ€λ
|
| 573 |
+
document.getElementById('retryLoadProgramsBtn').addEventListener('click', () => {
|
| 574 |
+
console.log('νλ‘κ·Έλ¨ λͺ©λ‘ μ¬μλ λ²νΌ ν΄λ¦');
|
| 575 |
+
this.loadProgramsList();
|
| 576 |
+
});
|
| 577 |
}
|
| 578 |
};
|
| 579 |
|
requirements.txt
CHANGED
|
@@ -9,3 +9,4 @@ nltk>=3.6.5
|
|
| 9 |
sentence-transformers>=2.2.2
|
| 10 |
gradio>=3.50.0,<4.0.0
|
| 11 |
openai>=1.0.0
|
|
|
|
|
|
| 9 |
sentence-transformers>=2.2.2
|
| 10 |
gradio>=3.50.0,<4.0.0
|
| 11 |
openai>=1.0.0
|
| 12 |
+
flask-cors>=3.0.10
|