|
@@ -2,27 +2,26 @@ from openai import OpenAI
|
|
|
from config import SYSTEM_PROMPT, OPEN_API_KEY, SUPABASE_KEY, SUPABASE_URL
|
|
|
from supabase import create_client, Client
|
|
|
from text_processing import fuzzy_correct_chinese
|
|
|
+import csv
|
|
|
|
|
|
client = OpenAI(api_key=OPEN_API_KEY)
|
|
|
supabase: Client = create_client(SUPABASE_URL, SUPABASE_KEY)
|
|
|
|
|
|
+def load_custom_vocab_from_csv(file_path):
|
|
|
+ custom_vocab = []
|
|
|
+ try:
|
|
|
+ with open(file_path, 'r', encoding='utf-8') as csvfile:
|
|
|
+ reader = csv.DictReader(csvfile)
|
|
|
+ custom_vocab = [row['brand'] for row in reader if 'brand' in row]
|
|
|
+ except Exception as e:
|
|
|
+ print(f"Error reading CSV file: {str(e)}")
|
|
|
+ print("Using empty vocabulary.")
|
|
|
+ return custom_vocab
|
|
|
+
|
|
|
def transcribe(audio_file):
|
|
|
try:
|
|
|
- table_name = "brand_database"
|
|
|
- response = supabase.table(table_name).select("brand", "category").execute()
|
|
|
- custom_vocab = []
|
|
|
- if response.data:
|
|
|
- for item in response.data:
|
|
|
- custom_vocab.append({item['brand']})
|
|
|
- else:
|
|
|
- print(f"No data found or an error occurred: {response.error}")
|
|
|
- print("Using default dictionary as Supabase data couldn't be fetched.")
|
|
|
- custom_vocab = ["FENDI", "BOSS", "BALENCIAGA", "BURBERRY", "CELINE", "COS",
|
|
|
- "COACH", "Dior", "FENDI", "GUCCI", "KENZO", "Louis Vuitton",
|
|
|
- "LV", "MONTBLANC", "POLO", "TORY BURCH", "VERSACE", "BV",
|
|
|
- "BAO BAO ISSEY MIYAKE", "BERLUTI", "BOTTEGA VENETA", "ZEGNA",
|
|
|
- "FERRAGAMO", "LONGCHAMP", "Loro Piana", "maje", "MICHAEL KORS",
|
|
|
- "MONCLER", "PLEATS PLEASE", "SAINT LAURENT"]
|
|
|
+ custom_vocab = load_custom_vocab_from_csv('brand_database_rows.csv')
|
|
|
+
|
|
|
transcript = client.audio.transcriptions.create(
|
|
|
file=audio_file,
|
|
|
model="whisper-1",
|
|
@@ -56,4 +55,4 @@ def process_audio(audio_data):
|
|
|
if raw_transcript is None:
|
|
|
return None, None
|
|
|
corrected_transcript = post_process_transcript(raw_transcript)
|
|
|
- return raw_transcript, corrected_transcript
|
|
|
+ return raw_transcript, corrected_transcript
|