ysharma HF staff commited on
Commit
4700be2
·
1 Parent(s): 7bb9dbf

update for ernie

Browse files
Files changed (1) hide show
  1. app.py +12 -9
app.py CHANGED
@@ -8,8 +8,9 @@ import paddlehub as hub
8
  HF_TOKEN = os.environ["HF_TOKEN"]
9
  model = hub.Module(name='ernie_vilg')
10
 
11
- def get_ernie_vilg(text_prompts):
12
- results = model.generate_image(text_prompts=text_prompts, style="油画", visualization=False)
 
13
  return results[0]
14
 
15
  sd_inf = gr.Blocks.load(name="spaces/stabilityai/stable-diffusion", use_auth_token=HF_TOKEN)
@@ -30,7 +31,7 @@ def get_chinese_translation(in_language_first, in_language_second, text):
30
 
31
  return output
32
 
33
-
34
  def get_sd(translated_txt, samples, steps, scale, seed):
35
  print("******** Inside get_SD ********")
36
  print(f"translated_txt is : {translated_txt}")
@@ -45,27 +46,29 @@ with demo:
45
 
46
  with gr.Row():
47
  in_text_prompt = gr.Textbox(label="Enter English text here")
48
- out_text_chinese = gr.Textbox(label="Your Chinese language output")
49
- b1 = gr.Button("English to Chinese")
50
 
51
  s1 = gr.Slider(label='samples', value=4, visible=False)
52
  s2 = gr.Slider(label='steps', value=45, visible=False)
53
  s3 = gr.Slider(label='scale', value=7.5, visible=False)
54
  s4 = gr.Slider(label='seed', value=1024, visible=False)
55
 
 
56
  in_language_first = gr.Dropdown(visible=False, value= 'eng_Latn') #'English')
57
  in_language_second = gr.Dropdown(visible=False, value= 'zho_Hans') #'Chinese (Simplified)')
58
 
59
  with gr.Row():
 
60
  out_ernie = gr.Image(type="pil", label="Ernie output for the given prompt")
61
  #out_gallery = gr.Gallery(label="Generated images", show_label=False, elem_id="gallery") #.style(grid=[2, 3], height="auto")
62
  b2 = gr.Button("Generate Images from Ernie")
63
 
64
- out_sd = gr.Image(type="pil", label="SD output for the given prompt")
65
- b3 = gr.Button("Generate Images from SD")
66
 
67
  b1.click(get_chinese_translation, [in_language_first, in_language_second, in_text_prompt], out_text_chinese )
68
- b2.click(get_ernie_vilg, out_text_chinese, out_ernie) #out_gallery )
69
- b3.click(get_sd, [in_text_prompt,s1,s2,s3,s4], out_sd) #out_gallery )
70
 
71
  demo.launch(enable_queue=True, debug=True)
 
8
  HF_TOKEN = os.environ["HF_TOKEN"]
9
  model = hub.Module(name='ernie_vilg')
10
 
11
+ def get_ernie_vilg(text_prompts, style):
12
+ style = style.split('-')[0]
13
+ results = model.generate_image(text_prompts=text_prompts, style=style, visualization=False)
14
  return results[0]
15
 
16
  sd_inf = gr.Blocks.load(name="spaces/stabilityai/stable-diffusion", use_auth_token=HF_TOKEN)
 
31
 
32
  return output
33
 
34
+ #Block inference not working for stable diffusion
35
  def get_sd(translated_txt, samples, steps, scale, seed):
36
  print("******** Inside get_SD ********")
37
  print(f"translated_txt is : {translated_txt}")
 
46
 
47
  with gr.Row():
48
  in_text_prompt = gr.Textbox(label="Enter English text here")
49
+ out_text_chinese = gr.Textbox(label="Text in Simplified Chinese")
50
+ b1 = gr.Button("English to Simplified Chinese")
51
 
52
  s1 = gr.Slider(label='samples', value=4, visible=False)
53
  s2 = gr.Slider(label='steps', value=45, visible=False)
54
  s3 = gr.Slider(label='scale', value=7.5, visible=False)
55
  s4 = gr.Slider(label='seed', value=1024, visible=False)
56
 
57
+
58
  in_language_first = gr.Dropdown(visible=False, value= 'eng_Latn') #'English')
59
  in_language_second = gr.Dropdown(visible=False, value= 'zho_Hans') #'Chinese (Simplified)')
60
 
61
  with gr.Row():
62
+ in_styles = gr.Dropdown(['水彩-WaterColor', '油画-OilPainting', '粉笔画-Painting', '卡通-Cartoon', '蜡笔画-Pencils', '儿童画-ChildrensPaintings', '探索无限-ExploringTheInfinite']),
63
  out_ernie = gr.Image(type="pil", label="Ernie output for the given prompt")
64
  #out_gallery = gr.Gallery(label="Generated images", show_label=False, elem_id="gallery") #.style(grid=[2, 3], height="auto")
65
  b2 = gr.Button("Generate Images from Ernie")
66
 
67
+ #out_sd = gr.Image(type="pil", label="SD output for the given prompt")
68
+ #b3 = gr.Button("Generate Images from SD")
69
 
70
  b1.click(get_chinese_translation, [in_language_first, in_language_second, in_text_prompt], out_text_chinese )
71
+ b2.click(get_ernie_vilg, [out_text_chinese, in_styles], out_ernie) #out_gallery )
72
+ #b3.click(get_sd, [in_text_prompt,s1,s2,s3,s4], out_sd) #out_gallery )
73
 
74
  demo.launch(enable_queue=True, debug=True)