pngwn commited on
Commit
f82013f
1 Parent(s): 90ec86f
Files changed (1) hide show
  1. app.py +43 -1
app.py CHANGED
@@ -1,6 +1,46 @@
1
  import gradio as gr
2
  from share_btn import community_icon_html, loading_icon_html, share_js
 
 
3
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
4
 
5
 
6
  block = gr.Blocks(css="./css.css")
@@ -11,7 +51,7 @@ with block:
11
  with gr.Row(elem_id="prompt-container").style(mobile_collapse=False, equal_height=True):
12
  text = gr.Dropdown(
13
  label="Star Sign",
14
- choices=["leo", "scorpio", "gemini"],
15
  show_label=True,
16
  max_lines=1,
17
  placeholder="Enter your prompt",
@@ -45,6 +85,7 @@ with block:
45
  interactive=False,
46
  label="Generated images", show_label=False, elem_id="gallery"
47
  ).style(grid=[2], height="auto")
 
48
 
49
  with gr.Group(elem_id="container-advanced-btns"):
50
  with gr.Group(elem_id="share-btn-container"):
@@ -52,6 +93,7 @@ with block:
52
  loading_icon = gr.HTML(loading_icon_html)
53
  share_button = gr.Button("Share to community", elem_id="share-btn")
54
 
 
55
  share_button.click(
56
  None,
57
  [],
 
1
  import gradio as gr
2
  from share_btn import community_icon_html, loading_icon_html, share_js
3
+ import random
4
+ import re
5
 
6
+ import torch
7
+ from transformers import AutoModelWithLMHead, AutoTokenizer, pipeline, set_seed
8
+
9
+ import gradio as grad
10
+ from diffusers import StableDiffusionPipeline
11
+ def fn(sign, cat):
12
+ category = "career"
13
+ sign = "scorpio"
14
+
15
+ prompt = f"<|category|> {cat} <|horoscope|> {sign}"
16
+
17
+ tokenizer = AutoTokenizer.from_pretrained("shahp7575/gpt2-horoscopes")
18
+ model = AutoModelWithLMHead.from_pretrained("shahp7575/gpt2-horoscopes")
19
+
20
+ prompt_encoded = torch.tensor(tokenizer.encode(prompt)).unsqueeze(0)
21
+
22
+ sample_outputs = model.generate(
23
+ prompt_encoded,
24
+ do_sample=True,
25
+ top_k=40,
26
+ max_length=300,
27
+ top_p=0.95,
28
+ temperature=0.95,
29
+ num_beams=4,
30
+ num_return_sequences=4,
31
+ )
32
+
33
+ final_out = tokenizer.decode(sample_outputs[0], skip_special_tokens=True)
34
+ starting_text = " ".join(final_out.split(" ")[4:])
35
+ pipe = pipeline("text-generation", model="Gustavosta/MagicPrompt-Stable-Diffusion", tokenizer="gpt2")
36
+
37
+ seed = random.randint(100, 1000000)
38
+ set_seed(seed)
39
+
40
+ response = pipe(starting_text, max_length=(len(starting_text) + random.randint(60, 90)), num_return_sequences=1)
41
+ pipe = StableDiffusionPipeline.from_pretrained("CompVis/stable-diffusion-v1-4")
42
+ image = pipe(response[0]["generated_text"], num_inference_steps=5).images[0]
43
+ return [image, starting_text]
44
 
45
 
46
  block = gr.Blocks(css="./css.css")
 
51
  with gr.Row(elem_id="prompt-container").style(mobile_collapse=False, equal_height=True):
52
  text = gr.Dropdown(
53
  label="Star Sign",
54
+ choices=["aries", "taurus","gemini", "cancer", "leo", "virgo", "libra", "scorpio", "sagittarius", "capricorn", "aquarius", "Pisces"],
55
  show_label=True,
56
  max_lines=1,
57
  placeholder="Enter your prompt",
 
85
  interactive=False,
86
  label="Generated images", show_label=False, elem_id="gallery"
87
  ).style(grid=[2], height="auto")
88
+ text = gr.Textbox("Text")
89
 
90
  with gr.Group(elem_id="container-advanced-btns"):
91
  with gr.Group(elem_id="share-btn-container"):
 
93
  loading_icon = gr.HTML(loading_icon_html)
94
  share_button = gr.Button("Share to community", elem_id="share-btn")
95
 
96
+ btn.click(fn=fn, inputs=[text, text2], outputs=[gallery, text])
97
  share_button.click(
98
  None,
99
  [],