Update app.py
Browse files
app.py
CHANGED
|
@@ -181,15 +181,15 @@ def save_uploaded_file(file, filename,TEMP_DIR):
|
|
| 181 |
|
| 182 |
client = OpenAI(api_key="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")
|
| 183 |
|
| 184 |
-
def translate_text(
|
| 185 |
response = client.chat.completions.create(
|
| 186 |
model="gpt-4-0125-preview",
|
| 187 |
-
messages=[
|
| 188 |
-
{"role": "
|
| 189 |
-
{"role": "user", "content": f"Translate and give just the following text into {target_language} as response: {text}\n"},
|
| 190 |
],
|
| 191 |
-
max_tokens=len(text
|
| 192 |
-
temperature=0.3,
|
|
|
|
| 193 |
)
|
| 194 |
return response
|
| 195 |
|
|
|
|
| 181 |
|
| 182 |
client = OpenAI(api_key="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")
|
| 183 |
|
| 184 |
+
def translate_text(text_prompt, target_language):
|
| 185 |
response = client.chat.completions.create(
|
| 186 |
model="gpt-4-0125-preview",
|
| 187 |
+
messages=[{"role": "system", "content": "You are a helpful language translator assistant."},
|
| 188 |
+
{"role": "user", "content": f"Translate completely without hallucination, end to end, and give the following text to {target_language} language and the text is: {text_prompt}"},
|
|
|
|
| 189 |
],
|
| 190 |
+
max_tokens = len(text_prompt) + 200 # Use the length of the input text
|
| 191 |
+
# temperature=0.3,
|
| 192 |
+
# stop=["Translate:", "Text:"]
|
| 193 |
)
|
| 194 |
return response
|
| 195 |
|