ysharma HF staff commited on
Commit
59506cd
1 Parent(s): bdfcd29
Files changed (1) hide show
  1. app.py +7 -6
app.py CHANGED
@@ -19,11 +19,12 @@ nllb_model_name = 'facebook/nllb-200-distilled-600M'
19
  nllb_model = AutoModelForSeq2SeqLM.from_pretrained(nllb_model_name)
20
  nllb_tokenizer = AutoTokenizer.from_pretrained(nllb_model_name)
21
 
22
- def get_chinese_translation(in_language_first, in_language_second, text):
23
  print("********Inside get_chinese_translation ********")
24
  print(f"text is :{text}, source language is : {in_language_first}, target language is : {in_language_second} ")
25
-
26
- translator = pipeline('translation', model=nllb_model, tokenizer=nllb_tokenizer, src_lang=in_language_first, tgt_lang=in_language_second)
 
27
  output = translator(text, max_length=400)
28
  print(f"initial output is:{output}")
29
  output = output[0]['translation_text']
@@ -63,14 +64,14 @@ with demo:
63
 
64
  out_ernie = gr.Image(type="pil", label="Ernie output for the given prompt")
65
  #out_gallery = gr.Gallery(label="Generated images", show_label=False, elem_id="gallery") #.style(grid=[2, 3], height="auto")
66
- in_language_first = gr.Textbox(visible=False, value= 'eng_Latn') #'English'
67
- in_language_second = gr.Textbox(visible=False, value= 'zho_Hans') #'Chinese (Simplified)'
68
 
69
 
70
  #out_sd = gr.Image(type="pil", label="SD output for the given prompt")
71
  #b3 = gr.Button("Generate Images from SD")
72
 
73
- b1.click(get_chinese_translation, [in_language_first, in_language_second, in_text_prompt], out_text_chinese )
74
  b2.click(get_ernie_vilg, [out_text_chinese, in_styles], out_ernie)
75
 
76
  #b3.click(get_sd, [in_text_prompt,s1,s2,s3,s4], out_sd) #out_gallery )
 
19
  nllb_model = AutoModelForSeq2SeqLM.from_pretrained(nllb_model_name)
20
  nllb_tokenizer = AutoTokenizer.from_pretrained(nllb_model_name)
21
 
22
+ def get_chinese_translation(text): #in_language_first, in_language_second,
23
  print("********Inside get_chinese_translation ********")
24
  print(f"text is :{text}, source language is : {in_language_first}, target language is : {in_language_second} ")
25
+ src = 'eng_Latn'
26
+ tgt= 'zho_Hans'
27
+ translator = pipeline('translation', model=nllb_model, tokenizer=nllb_tokenizer, src_lang=src, tgt_lang=tgt)
28
  output = translator(text, max_length=400)
29
  print(f"initial output is:{output}")
30
  output = output[0]['translation_text']
 
64
 
65
  out_ernie = gr.Image(type="pil", label="Ernie output for the given prompt")
66
  #out_gallery = gr.Gallery(label="Generated images", show_label=False, elem_id="gallery") #.style(grid=[2, 3], height="auto")
67
+ #in_language_first = gr.Textbox(visible=False, value= 'eng_Latn') #'English'
68
+ #in_language_second = gr.Textbox(visible=False, value= 'zho_Hans') #'Chinese (Simplified)'
69
 
70
 
71
  #out_sd = gr.Image(type="pil", label="SD output for the given prompt")
72
  #b3 = gr.Button("Generate Images from SD")
73
 
74
+ b1.click(get_chinese_translation, in_text_prompt, out_text_chinese ) #[in_language_first, in_language_second,
75
  b2.click(get_ernie_vilg, [out_text_chinese, in_styles], out_ernie)
76
 
77
  #b3.click(get_sd, [in_text_prompt,s1,s2,s3,s4], out_sd) #out_gallery )