Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -32,11 +32,13 @@ def hf_translate(text, src_lang, tgt_lang):
|
|
32 |
url = f"https://api-inference.huggingface.co/models/{HF_MODEL}"
|
33 |
try:
|
34 |
response = requests.post(url, headers=headers, json=payload)
|
|
|
|
|
|
|
35 |
result = response.json()
|
36 |
-
if isinstance(result, list):
|
37 |
-
return
|
38 |
-
|
39 |
-
return "Translation failed: Invalid response format"
|
40 |
except Exception as e:
|
41 |
return f"Error: {e}"
|
42 |
|
|
|
32 |
url = f"https://api-inference.huggingface.co/models/{HF_MODEL}"
|
33 |
try:
|
34 |
response = requests.post(url, headers=headers, json=payload)
|
35 |
+
# Check if the response is empty or invalid
|
36 |
+
if response.status_code != 200:
|
37 |
+
return f"Error: Received status code {response.status_code}"
|
38 |
result = response.json()
|
39 |
+
if not result or not isinstance(result, list):
|
40 |
+
return f"Error: Invalid response format. {response.text}"
|
41 |
+
return result[0]["translation_text"]
|
|
|
42 |
except Exception as e:
|
43 |
return f"Error: {e}"
|
44 |
|