TIL updates
Browse files- app.py +20 -9
- templates/index.html +26 -12
app.py
CHANGED
|
@@ -26,6 +26,9 @@ wmodel = WhisperModel("guillaumekln/faster-whisper-small", device="cpu", compute
|
|
| 26 |
qdrant_api_key = os.environ.get("qdrant_api_key")
|
| 27 |
qdrant_url = os.environ.get("qdrant_url")
|
| 28 |
|
|
|
|
|
|
|
|
|
|
| 29 |
client = QdrantClient(url=qdrant_url, port=443, api_key=qdrant_api_key, prefer_grpc=False)
|
| 30 |
|
| 31 |
device = torch.device("cuda" if torch.cuda.is_available() else "cpu")
|
|
@@ -54,6 +57,7 @@ def index():
|
|
| 54 |
@app.route("/search", methods=["POST"])
|
| 55 |
def search():
|
| 56 |
query = request.form["query"]
|
|
|
|
| 57 |
topN = 200 # Define your topN value
|
| 58 |
|
| 59 |
|
|
@@ -77,18 +81,25 @@ def search():
|
|
| 77 |
else: results = client.search(collection_name=collection_name, query_vector=(qvector, sq), with_payload=True, limit=100)
|
| 78 |
print('SEARCH TIME: ', time.time() - timh)
|
| 79 |
|
| 80 |
-
|
| 81 |
-
try:
|
| 82 |
-
|
| 83 |
-
|
| 84 |
-
|
| 85 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 86 |
|
| 87 |
@app.route("/delete_joke", methods=["POST"])
|
| 88 |
def delete_joke():
|
| 89 |
joke_id = request.form["id"]
|
| 90 |
-
|
| 91 |
-
|
|
|
|
| 92 |
return jsonify({"deleted": True})
|
| 93 |
|
| 94 |
@app.route("/whisper_transcribe", methods=["POST"])
|
|
@@ -96,7 +107,7 @@ def whisper_transcribe():
|
|
| 96 |
if 'audio' not in request.files: return jsonify({'error': 'No file provided'}), 400
|
| 97 |
|
| 98 |
audio_file = request.files['audio']
|
| 99 |
-
allowed_extensions = {'mp3', 'wav', 'ogg', '
|
| 100 |
if not (audio_file and audio_file.filename.lower().split('.')[-1] in allowed_extensions): return jsonify({'error': 'Invalid file format'}), 400
|
| 101 |
|
| 102 |
print('Transcribing audio')
|
|
|
|
| 26 |
qdrant_api_key = os.environ.get("qdrant_api_key")
|
| 27 |
qdrant_url = os.environ.get("qdrant_url")
|
| 28 |
|
| 29 |
+
qdrant_api_key = "WaGH94-bo_CzlxTNHFjBAGPvWRhbsWEKUKbMz6YQtYt4oTD1ZXTvwg"
|
| 30 |
+
qdrant_url = "https://c9bee7c7-2bf3-4e1b-8838-2f6f23372ab5.us-east-1-0.aws.cloud.qdrant.io"
|
| 31 |
+
|
| 32 |
client = QdrantClient(url=qdrant_url, port=443, api_key=qdrant_api_key, prefer_grpc=False)
|
| 33 |
|
| 34 |
device = torch.device("cuda" if torch.cuda.is_available() else "cpu")
|
|
|
|
| 57 |
@app.route("/search", methods=["POST"])
|
| 58 |
def search():
|
| 59 |
query = request.form["query"]
|
| 60 |
+
collection_name = request.form["collection"]
|
| 61 |
topN = 200 # Define your topN value
|
| 62 |
|
| 63 |
|
|
|
|
| 81 |
else: results = client.search(collection_name=collection_name, query_vector=(qvector, sq), with_payload=True, limit=100)
|
| 82 |
print('SEARCH TIME: ', time.time() - timh)
|
| 83 |
|
| 84 |
+
print(results[0])
|
| 85 |
+
# try:
|
| 86 |
+
if collection_name == 'jks': results = [{"text": x.payload['text'], "date": str(int(x.payload['date'])), "id": x.id} for x in results] # Implement your Qdrant search here
|
| 87 |
+
else:
|
| 88 |
+
new_results = []
|
| 89 |
+
for r in results:
|
| 90 |
+
if 'context' in r.payload and r.payload['context'] != '': new_results.append({"text": r.payload['title'] + '\nContext: ' + r.payload['context'], "url": r.payload['url'], "date": r.payload['date'], "id": r.id})
|
| 91 |
+
else: new_results.append({"text": r.payload['title'], "url": r.payload['url'], "date": r.payload['date'], "id": r.id})
|
| 92 |
+
results = new_results
|
| 93 |
+
return jsonify(results)
|
| 94 |
+
# except:
|
| 95 |
+
# return jsonify([])
|
| 96 |
|
| 97 |
@app.route("/delete_joke", methods=["POST"])
|
| 98 |
def delete_joke():
|
| 99 |
joke_id = request.form["id"]
|
| 100 |
+
collection_name = request.form["collection"]
|
| 101 |
+
print('Deleting no.', joke_id, 'from collection', collection_name)
|
| 102 |
+
client.delete(collection_name=collection_name, points_selector=models.PointIdsList(points=[int(joke_id)],),)
|
| 103 |
return jsonify({"deleted": True})
|
| 104 |
|
| 105 |
@app.route("/whisper_transcribe", methods=["POST"])
|
|
|
|
| 107 |
if 'audio' not in request.files: return jsonify({'error': 'No file provided'}), 400
|
| 108 |
|
| 109 |
audio_file = request.files['audio']
|
| 110 |
+
allowed_extensions = {'mp3', 'wav', 'ogg', 'm4a'}
|
| 111 |
if not (audio_file and audio_file.filename.lower().split('.')[-1] in allowed_extensions): return jsonify({'error': 'Invalid file format'}), 400
|
| 112 |
|
| 113 |
print('Transcribing audio')
|
templates/index.html
CHANGED
|
@@ -2,14 +2,14 @@
|
|
| 2 |
<html lang="en">
|
| 3 |
<head>
|
| 4 |
<meta charset="UTF-8">
|
| 5 |
-
<title>
|
| 6 |
<script src="https://code.jquery.com/jquery-3.6.0.min.js"></script>
|
| 7 |
<style>
|
| 8 |
body {
|
| 9 |
font-family: Arial, sans-serif;
|
| 10 |
}
|
| 11 |
|
| 12 |
-
|
| 13 |
text-align: center;
|
| 14 |
}
|
| 15 |
|
|
@@ -65,7 +65,7 @@
|
|
| 65 |
</style>
|
| 66 |
</head>
|
| 67 |
<body>
|
| 68 |
-
<
|
| 69 |
<div id="search-container">
|
| 70 |
<input type="text" id="query" placeholder="Search...">
|
| 71 |
<button id="search">Search</button>
|
|
@@ -79,28 +79,42 @@
|
|
| 79 |
|
| 80 |
<script>
|
| 81 |
$(document).ready(function () {
|
|
|
|
| 82 |
function performSearch() {
|
| 83 |
var query = $("#query").val();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 84 |
|
| 85 |
-
$.post("/search", { query: query }, function (data) {
|
| 86 |
// Handle search results
|
| 87 |
var results = $("#results");
|
| 88 |
results.empty();
|
| 89 |
|
| 90 |
data.forEach(function (result) {
|
| 91 |
-
|
| 92 |
-
|
| 93 |
-
|
| 94 |
-
|
| 95 |
-
"</div>");
|
| 96 |
-
|
|
|
|
|
|
|
|
|
|
| 97 |
results.append(resultElement);
|
| 98 |
|
| 99 |
resultElement.find(".delete").on("click", function () {
|
| 100 |
var id = $(this).data("id");
|
| 101 |
var resultButton = $(this);
|
| 102 |
|
| 103 |
-
$.post("/delete_joke", { id: id }, function (data) {
|
| 104 |
// Handle the delete response if needed
|
| 105 |
|
| 106 |
if (data.deleted) {
|
|
@@ -119,7 +133,7 @@
|
|
| 119 |
results.empty();
|
| 120 |
results.append("<div class='result'>" + "<p>" + transcription + "</p>" + "</div>");
|
| 121 |
// Hide the "Transcribing..." message
|
| 122 |
-
$("#drag-drop-container").text("Drag & Drop Audio File (mp3, wav, ogg,
|
| 123 |
$("#drag-drop-container").css("border-color", "#4c72af");
|
| 124 |
}
|
| 125 |
|
|
|
|
| 2 |
<html lang="en">
|
| 3 |
<head>
|
| 4 |
<meta charset="UTF-8">
|
| 5 |
+
<title>Utilities</title>
|
| 6 |
<script src="https://code.jquery.com/jquery-3.6.0.min.js"></script>
|
| 7 |
<style>
|
| 8 |
body {
|
| 9 |
font-family: Arial, sans-serif;
|
| 10 |
}
|
| 11 |
|
| 12 |
+
h2 {
|
| 13 |
text-align: center;
|
| 14 |
}
|
| 15 |
|
|
|
|
| 65 |
</style>
|
| 66 |
</head>
|
| 67 |
<body>
|
| 68 |
+
<h2>Utilities</h2>
|
| 69 |
<div id="search-container">
|
| 70 |
<input type="text" id="query" placeholder="Search...">
|
| 71 |
<button id="search">Search</button>
|
|
|
|
| 79 |
|
| 80 |
<script>
|
| 81 |
$(document).ready(function () {
|
| 82 |
+
var collection = "jks";
|
| 83 |
function performSearch() {
|
| 84 |
var query = $("#query").val();
|
| 85 |
+
// if query starts with til: or tilc:, set collection to tils, else set to jks
|
| 86 |
+
if (query.startsWith("til:")) {
|
| 87 |
+
collection = "tils";
|
| 88 |
+
// query = query.substring(4);
|
| 89 |
+
} else if (query.startsWith("tilc:")) {
|
| 90 |
+
collection = "tils";
|
| 91 |
+
// query = query.substring(5);
|
| 92 |
+
} else {
|
| 93 |
+
collection = "jks";
|
| 94 |
+
}
|
| 95 |
|
| 96 |
+
$.post("/search", { query: query, collection:collection }, function (data) {
|
| 97 |
// Handle search results
|
| 98 |
var results = $("#results");
|
| 99 |
results.empty();
|
| 100 |
|
| 101 |
data.forEach(function (result) {
|
| 102 |
+
// if collection is tils, set resultElement to the result.text, hyperlinked by result.url after prepending with https://. The date should have an underscore after the first 8 characters
|
| 103 |
+
// else, set resultElement to the result.text
|
| 104 |
+
|
| 105 |
+
if (collection == "tils") {
|
| 106 |
+
var resultElement = $("<div class='result'>" + "<p>" + "<a href='https://" + result.url + "' target='_blank'>" + result.text + "</a>" + "</p>" + "<small>" + result.date + "</small>" + "<button class='delete' data-id='" + result.id + "'>Delete</button>" + "</div>");
|
| 107 |
+
} else {
|
| 108 |
+
var resultElement = $("<div class='result'>" + "<p>" + result.text + "</p>" + "<small>Date: " + result.date + "</small>" + "<button class='delete' data-id='" + result.id + "'>Delete</button>" + "</div>");
|
| 109 |
+
}
|
| 110 |
+
|
| 111 |
results.append(resultElement);
|
| 112 |
|
| 113 |
resultElement.find(".delete").on("click", function () {
|
| 114 |
var id = $(this).data("id");
|
| 115 |
var resultButton = $(this);
|
| 116 |
|
| 117 |
+
$.post("/delete_joke", { id: id, collection:collection }, function (data) {
|
| 118 |
// Handle the delete response if needed
|
| 119 |
|
| 120 |
if (data.deleted) {
|
|
|
|
| 133 |
results.empty();
|
| 134 |
results.append("<div class='result'>" + "<p>" + transcription + "</p>" + "</div>");
|
| 135 |
// Hide the "Transcribing..." message
|
| 136 |
+
$("#drag-drop-container").text("Drag & Drop Audio File (mp3, wav, ogg, m4a) Here");
|
| 137 |
$("#drag-drop-container").css("border-color", "#4c72af");
|
| 138 |
}
|
| 139 |
|