pakooo commited on
Commit
242ab76
1 Parent(s): fbded8a

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +1 -29
app.py CHANGED
@@ -43,30 +43,6 @@ extend_prompt_1 = True
43
  extend_prompt_2 = True
44
  extend_prompt_3 = True
45
 
46
- thanks_info = "Thanks: "
47
- if extend_prompt_1:
48
- extend_prompt_pipe = pipeline('text-generation', model='yizhangliu/prompt-extend', max_length=77, pad_token_id=0)
49
- thanks_info += "[<a style='display:inline-block' href='https://huggingface.co/spaces/daspartho/prompt-extend' _blank><font style='color:blue;weight:bold;'>prompt-extend(1)</font></a>]"
50
- if extend_prompt_2:
51
- def load_prompter():
52
- prompter_model = AutoModelForCausalLM.from_pretrained("microsoft/Promptist")
53
- tokenizer = AutoTokenizer.from_pretrained("gpt2")
54
- tokenizer.pad_token = tokenizer.eos_token
55
- tokenizer.padding_side = "left"
56
- return prompter_model, tokenizer
57
- prompter_model, prompter_tokenizer = load_prompter()
58
- def extend_prompt_microsoft(in_text):
59
- input_ids = prompter_tokenizer(in_text.strip()+" Rephrase:", return_tensors="pt").input_ids
60
- eos_id = prompter_tokenizer.eos_token_id
61
- outputs = prompter_model.generate(input_ids, do_sample=False, max_new_tokens=75, num_beams=8, num_return_sequences=8, eos_token_id=eos_id, pad_token_id=eos_id, length_penalty=-1.0)
62
- output_texts = prompter_tokenizer.batch_decode(outputs, skip_special_tokens=True)
63
- res = output_texts[0].replace(in_text+" Rephrase:", "").strip()
64
- return res
65
- thanks_info += "[<a style='display:inline-block' href='https://huggingface.co/spaces/microsoft/Promptist' _blank><font style='color:blue;weight:bold;'>Promptist(2)</font></a>]"
66
- if extend_prompt_3:
67
- MagicPrompt = gr.Interface.load("spaces/Gustavosta/MagicPrompt-Stable-Diffusion")
68
- thanks_info += "[<a style='display:inline-block' href='https://huggingface.co/spaces/Gustavosta/MagicPrompt-Stable-Diffusion' _blank><font style='color:blue;weight:bold;'>MagicPrompt(3)</font></a>]"
69
-
70
  do_dreamlike_photoreal = False
71
  if do_dreamlike_photoreal:
72
  def add_random_noise(prompt, noise_level=0.1):
@@ -88,7 +64,6 @@ if do_dreamlike_photoreal:
88
 
89
  tab_actions.append(dreamlike_image)
90
  tab_titles.append("Dreamlike_2.0")
91
- thanks_info += "[<a style='display:inline-block' href='https://huggingface.co/dreamlike-art/dreamlike-photoreal-2.0' _blank><font style='color:blue;weight:bold;'>dreamlike-photoreal-2.0</font></a>]"
92
 
93
  for space_id in space_ids.keys():
94
  print(space_id, space_ids[space_id])
@@ -101,7 +76,6 @@ for space_id in space_ids.keys():
101
  else:
102
  tab_content = gr.Interface.load(space_id)
103
  tab_actions.append(tab_content)
104
- thanks_info += f"[<a style='display:inline-block' href='https://huggingface.co/{space_id}' _blank><font style='color:blue;weight:bold;'>{tab_title}</font></a>]"
105
  except Exception as e:
106
  logger.info(f"load_fail__{space_id}_{e}")
107
 
@@ -333,7 +307,7 @@ def prompt_draw_2(prompt):
333
  prompt_zh = getTextTrans(prompt, source='en', target='zh')
334
  return prompt_en, prompt_zh
335
 
336
- with gr.Blocks(title='Text-to-Image') as demo:
337
  with gr.Group(elem_id="page_1", visible=True) as page_1:
338
  with gr.Box():
339
  with gr.Row():
@@ -374,8 +348,6 @@ with gr.Blocks(title='Text-to-Image') as demo:
374
  with gr.Row():
375
  switch_tab_advanced_btn = gr.Button(value = "Switch_tab_advanced", elem_id="switch_tab_advanced_btn")
376
  switch_tab_advanced_btn.click(fn=None, inputs=[], outputs=[], _js=switch_tab_advanced)
377
- with gr.Row():
378
- gr.HTML(f"<p>{thanks_info}</p>")
379
 
380
  if extend_prompt_1:
381
  extend_btn_1.click(fn=prompt_extend_1, inputs=[prompt_input0], outputs=[prompt_input1])
 
43
  extend_prompt_2 = True
44
  extend_prompt_3 = True
45
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
46
  do_dreamlike_photoreal = False
47
  if do_dreamlike_photoreal:
48
  def add_random_noise(prompt, noise_level=0.1):
 
64
 
65
  tab_actions.append(dreamlike_image)
66
  tab_titles.append("Dreamlike_2.0")
 
67
 
68
  for space_id in space_ids.keys():
69
  print(space_id, space_ids[space_id])
 
76
  else:
77
  tab_content = gr.Interface.load(space_id)
78
  tab_actions.append(tab_content)
 
79
  except Exception as e:
80
  logger.info(f"load_fail__{space_id}_{e}")
81
 
 
307
  prompt_zh = getTextTrans(prompt, source='en', target='zh')
308
  return prompt_en, prompt_zh
309
 
310
+ with gr.Blocks(title='VM8 Text2Image') as demo:
311
  with gr.Group(elem_id="page_1", visible=True) as page_1:
312
  with gr.Box():
313
  with gr.Row():
 
348
  with gr.Row():
349
  switch_tab_advanced_btn = gr.Button(value = "Switch_tab_advanced", elem_id="switch_tab_advanced_btn")
350
  switch_tab_advanced_btn.click(fn=None, inputs=[], outputs=[], _js=switch_tab_advanced)
 
 
351
 
352
  if extend_prompt_1:
353
  extend_btn_1.click(fn=prompt_extend_1, inputs=[prompt_input0], outputs=[prompt_input1])