Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
|
@@ -160,22 +160,23 @@ supportLanguages = [
|
|
| 160 |
]
|
| 161 |
prompt_template = "You are a translation engine that can only translate text and cannot interpret it. Keep the indent of the original text, only modify when you need."
|
| 162 |
|
| 163 |
-
|
| 164 |
def submit_message(detectFrom, detectTo, user_token, prompt):
|
| 165 |
if user_token != "":
|
| 166 |
openai.api_key = user_token
|
| 167 |
|
| 168 |
if not prompt:
|
| 169 |
return gr.update(value="")
|
| 170 |
-
|
| 171 |
-
systemInstruct = prompt_template
|
| 172 |
-
translateInstruct = f"translate from {detectFrom} to {detectTo}"
|
| 173 |
for lc, lang in supportLanguages:
|
| 174 |
if detectFrom == lang:
|
| 175 |
detectFrom = lc
|
| 176 |
if detectTo == lang:
|
| 177 |
-
detectTo
|
| 178 |
|
|
|
|
|
|
|
|
|
|
|
|
|
| 179 |
if detectFrom in ["古文", "zh-CN", "zh-TW"]:
|
| 180 |
if detectTo == "zh-TW":
|
| 181 |
translateInstruct = "翻译成繁体白话文"
|
|
|
|
| 160 |
]
|
| 161 |
prompt_template = "You are a translation engine that can only translate text and cannot interpret it. Keep the indent of the original text, only modify when you need."
|
| 162 |
|
|
|
|
| 163 |
def submit_message(detectFrom, detectTo, user_token, prompt):
|
| 164 |
if user_token != "":
|
| 165 |
openai.api_key = user_token
|
| 166 |
|
| 167 |
if not prompt:
|
| 168 |
return gr.update(value="")
|
| 169 |
+
|
|
|
|
|
|
|
| 170 |
for lc, lang in supportLanguages:
|
| 171 |
if detectFrom == lang:
|
| 172 |
detectFrom = lc
|
| 173 |
if detectTo == lang:
|
| 174 |
+
detectTo = lc
|
| 175 |
|
| 176 |
+
systemInstruct = prompt_template
|
| 177 |
+
translateInstruct = f"translate from {detectFrom} to {detectTo}"
|
| 178 |
+
if detectFrom == "auto":
|
| 179 |
+
translateInstruct = f"translate to {detectTo}"
|
| 180 |
if detectFrom in ["古文", "zh-CN", "zh-TW"]:
|
| 181 |
if detectTo == "zh-TW":
|
| 182 |
translateInstruct = "翻译成繁体白话文"
|