change confidence to %
This commit is contained in:
parent
2c9c4a22a6
commit
890408f018
@ -206,7 +206,7 @@ class LyricSearch(FastAPI):
|
||||
logging.debug("Found %s at %s, match for %s!",
|
||||
line, seeked_found_line, data.sub) # REMOVEME: DEBUG
|
||||
break
|
||||
|
||||
|
||||
if not seeked_found_line:
|
||||
return {
|
||||
'failed_seek': True,
|
||||
@ -214,7 +214,7 @@ class LyricSearch(FastAPI):
|
||||
result['lyrics'] = " / ".join(lyric_lines[seeked_found_line:])
|
||||
|
||||
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}'
|
||||
if "cached" in result['src']:
|
||||
result['from_cache'] = True
|
||||
|
@ -9,7 +9,7 @@ class LyricsResult:
|
||||
song: str
|
||||
src: str
|
||||
lyrics: str
|
||||
confidence: float
|
||||
confidence: int
|
||||
time: float = 0.00
|
||||
|
||||
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.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"""
|
||||
matched_id: int = matched_candidate[0]
|
||||
for row in sqlite_rows:
|
||||
@ -148,7 +148,7 @@ class Cache:
|
||||
best_match: tuple|None = matcher.find_best_match(input_track=input_track,
|
||||
candidate_tracks=result_tracks)
|
||||
else:
|
||||
best_match = (result_tracks[0], float(1))
|
||||
best_match = (result_tracks[0], 100)
|
||||
if not best_match:
|
||||
return None
|
||||
(candidate, confidence) = best_match
|
||||
|
@ -2,6 +2,7 @@
|
||||
|
||||
from difflib import SequenceMatcher
|
||||
from typing import List, Optional, Tuple
|
||||
import logging
|
||||
import regex
|
||||
|
||||
class TrackMatcher:
|
||||
@ -28,6 +29,8 @@ class TrackMatcher:
|
||||
Optional[Tuple[int, str, float]]: Tuple of (best matching track, similarity score)
|
||||
or None if no good match found
|
||||
"""
|
||||
|
||||
|
||||
if not input_track or not candidate_tracks:
|
||||
return None
|
||||
|
||||
@ -53,7 +56,7 @@ class TrackMatcher:
|
||||
best_match = candidate
|
||||
|
||||
# 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:
|
||||
"""
|
||||
|
Loading…
x
Reference in New Issue
Block a user