Update app.py
Browse files
app.py
CHANGED
@@ -63,9 +63,10 @@ def translate_text(input_text, input_lang, output_langs, model_name):
|
|
63 |
system_prompt = """You are a translation assistant that provides direct, accurate translations.
|
64 |
Do NOT include any thinking, reasoning, or explanations in your response.
|
65 |
Do NOT use phrases like 'In [language]:', 'Translation:' or similar prefixes.
|
|
|
66 |
Always respond with ONLY the exact translation text itself."""
|
67 |
|
68 |
-
user_prompt = f"Translate this {input_lang} text: '{input_text}' into the following languages: {', '.join(output_langs)}. Provide each translation on a separate line with the language name as a prefix."
|
69 |
|
70 |
response = groq_client.chat.completions.create(
|
71 |
model=model_id,
|
@@ -81,6 +82,9 @@ def translate_text(input_text, input_lang, output_langs, model_name):
|
|
81 |
# Remove text between <think> tags if they exist
|
82 |
translation_text = re.sub(r'<think>.*?</think>', '', translation_text, flags=re.DOTALL)
|
83 |
|
|
|
|
|
|
|
84 |
# Remove any line starting with common thinking patterns
|
85 |
thinking_patterns = [
|
86 |
r'^\s*Let me think.*$',
|
@@ -135,6 +139,10 @@ def clean_translation_output(text):
|
|
135 |
# Remove any meta-content or thinking
|
136 |
text = re.sub(r'<think>.*?</think>', '', text, flags=re.DOTALL)
|
137 |
|
|
|
|
|
|
|
|
|
138 |
# Remove lines that appear to be thinking/reasoning
|
139 |
lines = text.split('\n')
|
140 |
cleaned_lines = []
|
|
|
63 |
system_prompt = """You are a translation assistant that provides direct, accurate translations.
|
64 |
Do NOT include any thinking, reasoning, or explanations in your response.
|
65 |
Do NOT use phrases like 'In [language]:', 'Translation:' or similar prefixes.
|
66 |
+
Do NOT use any special formatting like asterisks (**) or other markdown.
|
67 |
Always respond with ONLY the exact translation text itself."""
|
68 |
|
69 |
+
user_prompt = f"Translate this {input_lang} text: '{input_text}' into the following languages: {', '.join(output_langs)}. Provide each translation on a separate line with the language name as a prefix. Do not use any special formatting or markdown."
|
70 |
|
71 |
response = groq_client.chat.completions.create(
|
72 |
model=model_id,
|
|
|
82 |
# Remove text between <think> tags if they exist
|
83 |
translation_text = re.sub(r'<think>.*?</think>', '', translation_text, flags=re.DOTALL)
|
84 |
|
85 |
+
# Remove any asterisks
|
86 |
+
translation_text = translation_text.replace('**', '')
|
87 |
+
|
88 |
# Remove any line starting with common thinking patterns
|
89 |
thinking_patterns = [
|
90 |
r'^\s*Let me think.*$',
|
|
|
139 |
# Remove any meta-content or thinking
|
140 |
text = re.sub(r'<think>.*?</think>', '', text, flags=re.DOTALL)
|
141 |
|
142 |
+
# Remove asterisks from the text
|
143 |
+
text = text.replace('**', '')
|
144 |
+
text = text.replace('*', '')
|
145 |
+
|
146 |
# Remove lines that appear to be thinking/reasoning
|
147 |
lines = text.split('\n')
|
148 |
cleaned_lines = []
|