CrazyEric commited on
Commit
b3459ea
1 Parent(s): e5daf26

翻译prompt

Browse files
Files changed (1) hide show
  1. app.py +18 -4
app.py CHANGED
@@ -62,6 +62,20 @@ def randomize_seed_fn(seed: int, randomize_seed: bool) -> int:
62
  seed = random.randint(0, MAX_SEED)
63
  return seed
64
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
65
 
66
  @spaces.GPU
67
  def generate(
@@ -284,10 +298,10 @@ with gr.Blocks(css="style.css") as demo:
284
  ).then(
285
  fn=generate,
286
  inputs=[
287
- prompt,
288
- negative_prompt,
289
- prompt_2,
290
- negative_prompt_2,
291
  use_negative_prompt,
292
  use_prompt_2,
293
  use_negative_prompt_2,
 
62
  seed = random.randint(0, MAX_SEED)
63
  return seed
64
 
65
+ def translateEN(zh):
66
+ result = requests.post(
67
+ "https://api-free.deepl.com/v2/translate",
68
+ params={
69
+ "auth_key": "e8b4d428-ada5-3f8d-f965-bad01e8a06c1:fx",
70
+ "target_lang": "EN-US",
71
+ "text": zh})
72
+ return result.json()["translations"][0]["text"]
73
+
74
+ def process_text(prompt):
75
+ print("中文提示词: \n", prompt)
76
+ prompt_trans = translateEN(prompt)
77
+ print("prompt: \n", prompt_trans)
78
+ return prompt_trans
79
 
80
  @spaces.GPU
81
  def generate(
 
298
  ).then(
299
  fn=generate,
300
  inputs=[
301
+ process_text(prompt),
302
+ process_text(negative_prompt),
303
+ process_text(prompt_2),
304
+ process_text(negative_prompt_2),
305
  use_negative_prompt,
306
  use_prompt_2,
307
  use_negative_prompt_2,