amine_dubs commited on
Commit
7db04ce
·
1 Parent(s): 5d570c5
Files changed (2) hide show
  1. backend/main.py +1 -1
  2. static/script.js +12 -1
backend/main.py CHANGED
@@ -500,7 +500,7 @@ async def translate_text_endpoint(request: TranslationRequest):
500
  print(f"Error with fallback translation: {str(e)}")
501
  translation_result = f"[Translation failed during fallback] {text}"
502
 
503
- return {"success": True, "translation": translation_result}
504
 
505
  except Exception as e:
506
  print(f"Critical error in translate_text_endpoint: {str(e)}")
 
500
  print(f"Error with fallback translation: {str(e)}")
501
  translation_result = f"[Translation failed during fallback] {text}"
502
 
503
+ return {"success": True, "translated_text": translation_result}
504
 
505
  except Exception as e:
506
  print(f"Critical error in translate_text_endpoint: {str(e)}")
static/script.js CHANGED
@@ -67,9 +67,20 @@ document.addEventListener('DOMContentLoaded', () => {
67
 
68
  try {
69
  console.log('Sending translation request...');
 
 
 
 
 
 
 
 
70
  const response = await fetch('/translate/text', {
71
  method: 'POST',
72
- body: formData
 
 
 
73
  });
74
 
75
  console.log('Response received:', response.status, response.statusText);
 
67
 
68
  try {
69
  console.log('Sending translation request...');
70
+
71
+ // Create JSON payload from FormData instead of sending FormData directly
72
+ const payload = {
73
+ text: formData.get('text'),
74
+ source_lang: formData.get('source_lang'),
75
+ target_lang: formData.get('target_lang')
76
+ };
77
+
78
  const response = await fetch('/translate/text', {
79
  method: 'POST',
80
+ headers: {
81
+ 'Content-Type': 'application/json',
82
+ },
83
+ body: JSON.stringify(payload)
84
  });
85
 
86
  console.log('Response received:', response.status, response.statusText);