Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
|
@@ -39,6 +39,14 @@ def transliterate_to_hindi(text):
|
|
| 39 |
return text
|
| 40 |
|
| 41 |
def save_to_sheet(original, translation, correction, direction):
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 42 |
try:
|
| 43 |
json_creds = os.getenv("GOOGLE_CREDENTIALS")
|
| 44 |
if not json_creds:
|
|
@@ -54,6 +62,7 @@ def save_to_sheet(original, translation, correction, direction):
|
|
| 54 |
|
| 55 |
sheet = client.open(SHEET_NAME).sheet1
|
| 56 |
|
|
|
|
| 57 |
if not sheet.get_all_values():
|
| 58 |
sheet.append_row(
|
| 59 |
[
|
|
@@ -245,5 +254,11 @@ with gr.Blocks(title="Kurukh AI Translator") as demo:
|
|
| 245 |
gr.HTML(
|
| 246 |
"<center style='color:#777;'>Built with ❤️ for the Kurukh Community</center>"
|
| 247 |
)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 248 |
|
| 249 |
demo.launch()
|
|
|
|
| 39 |
return text
|
| 40 |
|
| 41 |
def save_to_sheet(original, translation, correction, direction):
|
| 42 |
+
# --- VALIDATION CHECK ---
|
| 43 |
+
|
| 44 |
+
if not original or not original.strip():
|
| 45 |
+
return "⚠️ Error: Original text is missing."
|
| 46 |
+
|
| 47 |
+
if not correction or not correction.strip():
|
| 48 |
+
return "⚠️ Error: Please enter your correction before submitting."
|
| 49 |
+
|
| 50 |
try:
|
| 51 |
json_creds = os.getenv("GOOGLE_CREDENTIALS")
|
| 52 |
if not json_creds:
|
|
|
|
| 62 |
|
| 63 |
sheet = client.open(SHEET_NAME).sheet1
|
| 64 |
|
| 65 |
+
# Check if header exists, if not add it
|
| 66 |
if not sheet.get_all_values():
|
| 67 |
sheet.append_row(
|
| 68 |
[
|
|
|
|
| 254 |
gr.HTML(
|
| 255 |
"<center style='color:#777;'>Built with ❤️ for the Kurukh Community</center>"
|
| 256 |
)
|
| 257 |
+
|
| 258 |
+
translate_btn.click(
|
| 259 |
+
fn=lambda orig, trans, direc: (orig, trans, direc),
|
| 260 |
+
inputs=[input_text, output_text, direction],
|
| 261 |
+
outputs=[fb_original, fb_ai_output, fb_direction]
|
| 262 |
+
)
|
| 263 |
|
| 264 |
demo.launch()
|