Spaces:
Running
Running
Commit
Β·
7b7724d
1
Parent(s):
9a0f9e8
...
Browse files
app.py
CHANGED
@@ -45,10 +45,10 @@ def save_to_supabase(input_text, output_text, direction):
|
|
45 |
|
46 |
try:
|
47 |
response = requests.post(f"{SUPABASE_URL}/rest/v1/{table}", json=payload, headers=headers)
|
48 |
-
return "
|
49 |
except Exception as e:
|
50 |
logging.error("Save error: %s", e)
|
51 |
-
return "
|
52 |
|
53 |
# --- Save verified translation ---
|
54 |
def save_verified_translation(original_text, verified_text):
|
@@ -68,10 +68,10 @@ def save_verified_translation(original_text, verified_text):
|
|
68 |
|
69 |
try:
|
70 |
response = requests.post(f"{SUPABASE_URL}/rest/v1/verified_translations", json=payload, headers=headers)
|
71 |
-
return "
|
72 |
except Exception as e:
|
73 |
logging.error("Verified Save error: %s", e)
|
74 |
-
return "
|
75 |
|
76 |
|
77 |
def get_translation_history(direction):
|
@@ -90,12 +90,12 @@ def get_translation_history(direction):
|
|
90 |
verified_data = vres.json() if vres.status_code == 200 else []
|
91 |
|
92 |
normal_history = "\n".join([
|
93 |
-
f"
|
94 |
for r in normal_data
|
95 |
]) or "No regular translations yet."
|
96 |
|
97 |
verified_history = "\n".join([
|
98 |
-
f"
|
99 |
for r in verified_data
|
100 |
]) or "No verified translations yet."
|
101 |
|
@@ -134,7 +134,7 @@ def translate(text, direction, generate_tts=False):
|
|
134 |
return final, audio_path
|
135 |
except Exception as e:
|
136 |
logging.error("Translation error: %s", e)
|
137 |
-
return "
|
138 |
|
139 |
# --- TTS for English output ---
|
140 |
def synthesize_tts(text):
|
@@ -163,7 +163,7 @@ def transcribe_audio(audio_path):
|
|
163 |
return transcription, None
|
164 |
except Exception as e:
|
165 |
logging.error("STT error: %s", e)
|
166 |
-
return None, f"
|
167 |
|
168 |
# --- Store audio file path ---
|
169 |
def store_audio(audio_path):
|
@@ -173,7 +173,7 @@ def store_audio(audio_path):
|
|
173 |
# --- Handle audio translation ---
|
174 |
def handle_audio_translation(audio_path, direction):
|
175 |
if direction != "en_to_ks":
|
176 |
-
return "
|
177 |
|
178 |
transcription, error = transcribe_audio(audio_path)
|
179 |
if error:
|
|
|
45 |
|
46 |
try:
|
47 |
response = requests.post(f"{SUPABASE_URL}/rest/v1/{table}", json=payload, headers=headers)
|
48 |
+
return "Saved successfully!" if response.status_code == 201 else "β Failed to save."
|
49 |
except Exception as e:
|
50 |
logging.error("Save error: %s", e)
|
51 |
+
return "Save error."
|
52 |
|
53 |
# --- Save verified translation ---
|
54 |
def save_verified_translation(original_text, verified_text):
|
|
|
68 |
|
69 |
try:
|
70 |
response = requests.post(f"{SUPABASE_URL}/rest/v1/verified_translations", json=payload, headers=headers)
|
71 |
+
return "Verified translation saved!" if response.status_code == 201 else "β Failed to save verified translation."
|
72 |
except Exception as e:
|
73 |
logging.error("Verified Save error: %s", e)
|
74 |
+
return "Verified save error."
|
75 |
|
76 |
|
77 |
def get_translation_history(direction):
|
|
|
90 |
verified_data = vres.json() if vres.status_code == 200 else []
|
91 |
|
92 |
normal_history = "\n".join([
|
93 |
+
f"Input: {r['input_text']} β Output: {r['output_text']}"
|
94 |
for r in normal_data
|
95 |
]) or "No regular translations yet."
|
96 |
|
97 |
verified_history = "\n".join([
|
98 |
+
f"Verified: {r['original_translation']} β {r['verified_translation']}"
|
99 |
for r in verified_data
|
100 |
]) or "No verified translations yet."
|
101 |
|
|
|
134 |
return final, audio_path
|
135 |
except Exception as e:
|
136 |
logging.error("Translation error: %s", e)
|
137 |
+
return "Translation failed.", None
|
138 |
|
139 |
# --- TTS for English output ---
|
140 |
def synthesize_tts(text):
|
|
|
163 |
return transcription, None
|
164 |
except Exception as e:
|
165 |
logging.error("STT error: %s", e)
|
166 |
+
return None, f"Transcription failed: {str(e)}"
|
167 |
|
168 |
# --- Store audio file path ---
|
169 |
def store_audio(audio_path):
|
|
|
173 |
# --- Handle audio translation ---
|
174 |
def handle_audio_translation(audio_path, direction):
|
175 |
if direction != "en_to_ks":
|
176 |
+
return "Audio input is only supported for English to Kashmiri.", "", "", audio_path
|
177 |
|
178 |
transcription, error = transcribe_audio(audio_path)
|
179 |
if error:
|