GIRI45 commited on
Commit
09315e0
·
verified ·
1 Parent(s): c27f053

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +13 -2
app.py CHANGED
@@ -32,9 +32,20 @@ def translate_file():
32
  if not isinstance(encoding, str):
33
  encoding = "utf-8" # Default to UTF-8
34
 
35
- contents = file.read().decode(encoding, errors="replace") # Replace invalid characters
 
 
 
 
 
36
  translated = translator.translate(contents, dest=target_language)
37
- translated_text = translated.text
 
 
 
 
 
 
38
  except Exception as e:
39
  translated_text = f"Error during translation: {str(e)}"
40
 
 
32
  if not isinstance(encoding, str):
33
  encoding = "utf-8" # Default to UTF-8
34
 
35
+ contents = file.read().decode(encoding, errors="replace").strip()
36
+
37
+ # ✅ Check if file is empty
38
+ if not contents:
39
+ return "Error: The uploaded file is empty."
40
+
41
  translated = translator.translate(contents, dest=target_language)
42
+
43
+ # ✅ Check if translation result is valid
44
+ if translated and translated.text:
45
+ translated_text = translated.text
46
+ else:
47
+ return "Error: Translation failed. No output received."
48
+
49
  except Exception as e:
50
  translated_text = f"Error during translation: {str(e)}"
51