shukdevdatta123 commited on
Commit
16b0159
·
verified ·
1 Parent(s): 4924aa2

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +6 -1
app.py CHANGED
@@ -95,8 +95,13 @@ def translate_to_english(api_key, text, lang_code):
95
  {"role": "user", "content": prompt}]
96
  )
97
 
98
- # Extract translated text from response
99
  translated_text = response['choices'][0]['message']['content'].strip()
 
 
 
 
 
100
  return translated_text
101
  except Exception as e:
102
  st.error(f"Error occurred during translation: {e}")
 
95
  {"role": "user", "content": prompt}]
96
  )
97
 
98
+ # Extract translated text from response, removing any additional context or prefixes
99
  translated_text = response['choices'][0]['message']['content'].strip()
100
+
101
+ # Clean up any unwanted prefixes or context
102
+ if translated_text.lower().startswith("the translated text"):
103
+ translated_text = translated_text.split(":", 1)[1].strip()
104
+
105
  return translated_text
106
  except Exception as e:
107
  st.error(f"Error occurred during translation: {e}")