Ashrafb commited on
Commit
91cb6a2
·
1 Parent(s): b6d5336

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +6 -87
app.py CHANGED
@@ -7,7 +7,6 @@ import time
7
  from queue import Queue
8
  from threading import Thread
9
 
10
- text_gen = gr.Interface.load("models/Gustavosta/MagicPrompt-Stable-Diffusion")
11
  proc1 = gr.Interface.load("models/playgroundai/playground-v2-1024px-aesthetic")
12
 
13
  def restart_script_periodically():
@@ -22,20 +21,6 @@ restart_thread.start()
22
  queue = Queue()
23
  queue_threshold = 100
24
 
25
- def add_random_noise(prompt, noise_level=0.00):
26
- if noise_level == 0:
27
- noise_level = 0.00
28
- percentage_noise = noise_level * 5
29
- num_noise_chars = int(len(prompt) * (percentage_noise / 100))
30
- noise_indices = random.sample(range(len(prompt)), num_noise_chars)
31
- prompt_list = list(prompt)
32
- noise_chars = list(string.ascii_letters + string.punctuation + ' ' + string.digits)
33
- noise_chars.extend(['😍', '💩', '😂', '🤔', '😊', '🤗', '😭', '🙄', '😷', '🤯', '🤫', '🥴', '😴', '🤩', '🥳', '😔', '😩', '🤪', '😇', '🤢', '😈', '👹', '👻', '🤖', '👽', '💀', '🎃', '🎅', '🎄', '🎁', '🎂', '🎉', '🎈', '🎊', '🎮', '❤️', '💔', '💕', '💖', '💗', '🐶', '🐱', '🐭', '🐹', '🦊', '🐻', '🐨', '🐯', '🦁', '🐘', '🔥', '🌧️', '🌞', '🌈', '💥', '🌴', '🌊', '🌺', '🌻', '🌸', '🎨', '🌅', '🌌', '☁️', '⛈️', '❄️', '☀️', '🌤️', '⛅️', '🌥️', '🌦️', '🌧️', '🌩️', '🌨️', '🌫️', '☔️', '🌬️', '💨', '🌪️', '🌈'])
34
- for index in noise_indices:
35
- prompt_list[index] = random.choice(noise_chars)
36
- return "".join(prompt_list)
37
-
38
- # Existing code...
39
 
40
  import uuid # Import the UUID library
41
 
@@ -45,103 +30,37 @@ import uuid # Import the UUID library
45
 
46
  request_counter = 0 # Global counter to track requests
47
 
48
- def send_it1(inputs, noise_level, proc=proc1):
49
  global request_counter
50
  request_counter += 1
51
  timestamp = f"{time.time()}_{request_counter}"
52
- prompt_with_noise = add_random_noise(inputs, noise_level) + f" - {timestamp}"
53
- while queue.qsize() >= queue_threshold:
54
- time.sleep(2)
55
- queue.put(prompt_with_noise)
56
- output = proc(prompt_with_noise)
57
  return output
58
- import random
59
-
60
- import random
61
- import time
62
-
63
- # ... (existing code)
64
-
65
- import random
66
- import time
67
-
68
- # ... (existing code)
69
-
70
- def get_prompts(prompt_text):
71
- global request_counter
72
- request_counter += 1
73
- timestamp = f"{time.time()}_{request_counter}"
74
-
75
- options = [
76
- "Cyberpunk android",
77
- "2060",
78
- "newyork",
79
- ", style of laurie greasley" , "studio ghibli" , "akira toriyama" , "james gilleard" , "genshin impact" , "trending pixiv fanbox" , "acrylic palette knife, 4k, vibrant colors, devinart, trending on artstation, low details"
80
- ", Editorial Photography, Shot on 70mm lens, Depth of Field, Bokeh, DOF, Tilt Blur, Shutter Speed 1/1000, F/22, 32k, Super-Resolution, award winning,",
81
- ", high detail, warm lighting, godrays, vivid, beautiful, trending on artstation, by jordan grimmer, huge scene, grass, art greg rutkowski ",
82
- ", highly detailed, digital painting, artstation, illustration, art by artgerm and greg rutkowski and alphonse mucha.",
83
- ", Charlie Bowater, stanley artgerm lau, a character portrait, sots art, sharp focus, smooth, aesthetic, extremely detailed, octane render,solo, dark industrial background, rtx, rock clothes, cinematic light, intricate detail, highly detailed, high res, detailed facial features",
84
- ", portrait photograph" , "realistic" , "concept art" , "elegant, highly detailed" , "intricate, sharp focus, depth of field, f/1. 8, 85mm, medium shot, mid shot, (((professionally color graded)))" ," sharp focus, bright soft diffused light" , "(volumetric fog),",
85
- ",Cinematic film still" ," (dark city street:1.2)" , "(cold colors), damp, moist, intricate details" ,"shallow depth of field, [volumetric fog]" , "cinematic lighting, reflections, photographed on a Canon EOS R5, 50mm lens, F/2.8, HDR, 8k resolution" , "cinematic film still from cyberpunk movie" , "volumetric fog, (RAW, analog, masterpiece, best quality, soft particles, 8k, flawless perfect face, intricate details" , "trending on artstation, trending on cgsociety, dlsr, ultra sharp, hdr, rtx, antialiasing, canon 5d foto))" , "((skin details, high detailed skin texture))" , "(((perfect face))), (perfect eyes)))",
86
-
87
- # Add other prompt options here...
88
- ]
89
-
90
- if prompt_text:
91
- chosen_option = random.choice(options)
92
- return text_gen(f"{prompt_text}, {chosen_option} - {timestamp}")
93
- else:
94
- return text_gen("", timestamp)
95
 
96
 
97
 
98
- # Existing code...
99
 
100
- # Existing code...
101
 
102
  with gr.Blocks(css=".gradio-container {background-color: #fdf7e6;} footer{display:none !important;}",) as demo:
103
-
104
-
105
  with gr.Column(elem_id="col-container"):
106
  with gr.Row(variant="compact"):
107
  input_text = gr.Textbox(
108
- lines=8,
109
- label="Short Prompt",
110
- show_label=False,
111
- max_lines=10,
112
- placeholder="Enter a basic idea and click 'Magic Prompt'. Got no ideas? No problem, Simply just hit the magic button!",
113
- ).style(
114
- container=False,
115
- textarea={'height': '400px'}
116
- )
117
- see_prompts = gr.Button("✨ Magic Prompt ✨").style(full_width=False)
118
-
119
- with gr.Row(variant="compact"):
120
- prompt = gr.Textbox(
121
  lines=8,
122
  label="Enter your prompt",
123
  show_label=False,
124
  max_lines=10,
125
- placeholder="Full Prompt",
126
  ).style(
127
  container=False,
128
  textarea={'height': '400px'}
129
  )
130
- run = gr.Button("Generate Images").style(full_width=False)
131
-
132
- with gr.Row():
133
- with gr.Row():
134
- noise_level = gr.Slider(minimum=0.0, maximum=3, step=0.1, label="Noise Level")
135
 
136
  with gr.Row():
137
  with gr.Row():
138
  output1 = gr.Image(label="", show_label=False, show_share_button=False)
139
 
 
140
 
141
- see_prompts.click(get_prompts, inputs=[input_text], outputs=[prompt], queue=False)
142
- run.click(send_it1, inputs=[prompt, noise_level], outputs=[output1])
143
-
144
-
145
-
146
-
147
  demo.launch(enable_queue=True, inline=True)
 
7
  from queue import Queue
8
  from threading import Thread
9
 
 
10
  proc1 = gr.Interface.load("models/playgroundai/playground-v2-1024px-aesthetic")
11
 
12
  def restart_script_periodically():
 
21
  queue = Queue()
22
  queue_threshold = 100
23
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
24
 
25
  import uuid # Import the UUID library
26
 
 
30
 
31
  request_counter = 0 # Global counter to track requests
32
 
33
+ def send_it1(prompt, proc=proc1):
34
  global request_counter
35
  request_counter += 1
36
  timestamp = f"{time.time()}_{request_counter}"
37
+ output = proc(prompt)
 
 
 
 
38
  return output
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
39
 
40
 
41
 
 
42
 
43
+ .
44
 
45
  with gr.Blocks(css=".gradio-container {background-color: #fdf7e6;} footer{display:none !important;}",) as demo:
 
 
46
  with gr.Column(elem_id="col-container"):
47
  with gr.Row(variant="compact"):
48
  input_text = gr.Textbox(
 
 
 
 
 
 
 
 
 
 
 
 
 
49
  lines=8,
50
  label="Enter your prompt",
51
  show_label=False,
52
  max_lines=10,
53
+ placeholder="Enter your text prompt here",
54
  ).style(
55
  container=False,
56
  textarea={'height': '400px'}
57
  )
58
+ run = gr.Button("Generate Image").style(full_width=False)
 
 
 
 
59
 
60
  with gr.Row():
61
  with gr.Row():
62
  output1 = gr.Image(label="", show_label=False, show_share_button=False)
63
 
64
+ run.click(send_it1, inputs=[input_text], outputs=[output1])
65
 
 
 
 
 
 
 
66
  demo.launch(enable_queue=True, inline=True)