change confidence to %
This commit is contained in:
parent
2c9c4a22a6
commit
890408f018
@ -214,7 +214,7 @@ class LyricSearch(FastAPI):
|
|||||||
result['lyrics'] = " / ".join(lyric_lines[seeked_found_line:])
|
result['lyrics'] = " / ".join(lyric_lines[seeked_found_line:])
|
||||||
|
|
||||||
result['lyrics'] = regex.sub(r'(\s/\s|\n)', '<br>', result['lyrics']).strip()
|
result['lyrics'] = regex.sub(r'(\s/\s|\n)', '<br>', result['lyrics']).strip()
|
||||||
result['confidence'] = f'{float(result.get('confidence', 0)):.2f}'
|
result['confidence'] = int(result.get('confidence', 0))
|
||||||
result['time'] = f'{float(result['time']):.4f}'
|
result['time'] = f'{float(result['time']):.4f}'
|
||||||
if "cached" in result['src']:
|
if "cached" in result['src']:
|
||||||
result['from_cache'] = True
|
result['from_cache'] = True
|
||||||
|
@ -9,7 +9,7 @@ class LyricsResult:
|
|||||||
song: str
|
song: str
|
||||||
src: str
|
src: str
|
||||||
lyrics: str
|
lyrics: str
|
||||||
confidence: float
|
confidence: int
|
||||||
time: float = 0.00
|
time: float = 0.00
|
||||||
|
|
||||||
def dict(self):
|
def dict(self):
|
||||||
|
@ -29,7 +29,7 @@ class Cache:
|
|||||||
self.sqlite_exts: list[str] = ['/usr/local/lib/python3.11/dist-packages/spellfix1.cpython-311-x86_64-linux-gnu.so']
|
self.sqlite_exts: list[str] = ['/usr/local/lib/python3.11/dist-packages/spellfix1.cpython-311-x86_64-linux-gnu.so']
|
||||||
self.label: str = "Cache"
|
self.label: str = "Cache"
|
||||||
|
|
||||||
def get_matched(self, sqlite_rows: list[sqlite3.Row], matched_candidate: tuple, confidence: float) -> Optional[LyricsResult]:
|
def get_matched(self, sqlite_rows: list[sqlite3.Row], matched_candidate: tuple, confidence: int) -> Optional[LyricsResult]:
|
||||||
"""Get Matched Result"""
|
"""Get Matched Result"""
|
||||||
matched_id: int = matched_candidate[0]
|
matched_id: int = matched_candidate[0]
|
||||||
for row in sqlite_rows:
|
for row in sqlite_rows:
|
||||||
@ -148,7 +148,7 @@ class Cache:
|
|||||||
best_match: tuple|None = matcher.find_best_match(input_track=input_track,
|
best_match: tuple|None = matcher.find_best_match(input_track=input_track,
|
||||||
candidate_tracks=result_tracks)
|
candidate_tracks=result_tracks)
|
||||||
else:
|
else:
|
||||||
best_match = (result_tracks[0], float(1))
|
best_match = (result_tracks[0], 100)
|
||||||
if not best_match:
|
if not best_match:
|
||||||
return None
|
return None
|
||||||
(candidate, confidence) = best_match
|
(candidate, confidence) = best_match
|
||||||
|
@ -2,6 +2,7 @@
|
|||||||
|
|
||||||
from difflib import SequenceMatcher
|
from difflib import SequenceMatcher
|
||||||
from typing import List, Optional, Tuple
|
from typing import List, Optional, Tuple
|
||||||
|
import logging
|
||||||
import regex
|
import regex
|
||||||
|
|
||||||
class TrackMatcher:
|
class TrackMatcher:
|
||||||
@ -28,6 +29,8 @@ class TrackMatcher:
|
|||||||
Optional[Tuple[int, str, float]]: Tuple of (best matching track, similarity score)
|
Optional[Tuple[int, str, float]]: Tuple of (best matching track, similarity score)
|
||||||
or None if no good match found
|
or None if no good match found
|
||||||
"""
|
"""
|
||||||
|
|
||||||
|
|
||||||
if not input_track or not candidate_tracks:
|
if not input_track or not candidate_tracks:
|
||||||
return None
|
return None
|
||||||
|
|
||||||
@ -53,7 +56,7 @@ class TrackMatcher:
|
|||||||
best_match = candidate
|
best_match = candidate
|
||||||
|
|
||||||
# Return the match only if it meets the threshold
|
# Return the match only if it meets the threshold
|
||||||
return (best_match, round(best_score, 2)) if best_score >= self.threshold else None
|
return (best_match, round(best_score *100)) if best_score >= self.threshold else None
|
||||||
|
|
||||||
def _normalize_string(self, text: str) -> str:
|
def _normalize_string(self, text: str) -> str:
|
||||||
"""
|
"""
|
||||||
|
Loading…
x
Reference in New Issue
Block a user