Staticaliza commited on
Commit
74d93be
1 Parent(s): e56cbf6

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +8 -18
app.py CHANGED
@@ -5,8 +5,6 @@ import os
5
 
6
  API_TOKEN = os.environ.get("API_TOKEN")
7
 
8
- KEY = os.environ.get("KEY")
9
-
10
  DEFAULT_NEGATIVE_INPUT = "nsfw, nude, nudity, naked, pantsless, boob, boobs, extra fingers, fewer fingers, (worst quality:1.4), (low quality:1.4), (monochrome:1.1), (bad_prompt_version2:0.8), text, jpeg, watermark, artist sign, blurry, out of frame, multiple breasts, (mutated hands and fingers:1.5 ), (long body :1.3), (mutation, poorly drawn :1.2) , black-white, bad anatomy, liquid body, liquid tongue, disfigured, malformed, mutated, anatomical nonsense, text font ui, error, malformed hands, long neck, blurred, lowers, lowres, bad anatomy, bad proportions, bad shadow, uncoordinated body, unnatural body, fused breasts, bad breasts, huge breasts, poorly drawn breasts, extra breasts, liquid breasts, heavy breasts, missing breasts, huge haunch, huge thighs, huge calf, bad hands, fused hand, missing hand, disappearing arms, disappearing thigh, disappearing calf, disappearing legs, fused ears, bad ears, poorly drawn ears, extra ears, liquid ears, heavy ears, missing ears, fused animal ears, bad animal ears, poorly drawn animal ears, extra animal ears, liquid animal ears, heavy animal ears, missing animal ears, text, ui, error, missing fingers, fused feet, bad feet, poorly drawn feet, extra feet, melting feet, fused feet, liquid feet, missing toes, bad toes, fused toes, poorly drawn toes, extra toes, fused eyes, missing eyes, liquid eyes, blurry eyes, fused lips, missing mouth, liquid mouth, expressionless, no expression, null face, liquid face, swirly face, no error correction,"
11
 
12
  API_ENDPOINTS = {
@@ -28,14 +26,10 @@ for model_name, model_endpoint in API_ENDPOINTS.items():
28
  CHOICES.append(model_name)
29
  CLIENTS[model_name] = InferenceClient(model_endpoint, headers = { "Authorization": f"Bearer {API_TOKEN}" })
30
 
31
- def generate(access_key, inputs, model, anti_inputs = DEFAULT_NEGATIVE_INPUT, ht = 512, wt = 512, nis = 50, gs = 7.5, seed = 42):
32
 
33
  print("MODEL CALLED: Input: " + inputs + ", Model: " + str(model))
34
 
35
- if (access_key != KEY):
36
- print("MODEL FAILED: Attempted Key: " + access_key)
37
- return;
38
-
39
  output = CLIENTS[model].text_to_image(
40
  inputs,
41
  negative_prompt = anti_inputs,
@@ -48,10 +42,8 @@ def generate(access_key, inputs, model, anti_inputs = DEFAULT_NEGATIVE_INPUT, ht
48
 
49
  return (output)
50
 
51
- def reload_models():
52
-
53
- print("RELOAD CALLED: Reloading all existing models ...")
54
-
55
  for model_name, model_client in CLIENTS.items():
56
  try:
57
  threading.Thread(target=CLIENTS[model_name].text_to_image, args=("Preload",), kwargs={
@@ -64,9 +56,8 @@ def reload_models():
64
  }).start()
65
  except Exception as e:
66
  print(f"[PRELOAD ERROR] An error occurred: {e}")
67
-
68
- return ("[RELOAD SUCCESSFUL]");
69
-
70
  with gr.Blocks() as demo:
71
  with gr.Row(variant = "panel"):
72
  gr.Markdown("✨ A IDM space owned within Statical.")
@@ -78,9 +69,8 @@ with gr.Blocks() as demo:
78
  with gr.Column():
79
  prompt_text = gr.Textbox(label = "Your Prompt", lines = 4)
80
  negative_prompt_text = gr.Textbox(label = "Your Negative Prompt", lines = 4, value = DEFAULT_NEGATIVE_INPUT)
81
- access_key = gr.Textbox(label = "Access Key", lines = 1)
82
  run = gr.Button("Generate Image")
83
- reload = gr.Button("Reload Models")
84
  height = gr.Slider( minimum = 144, maximum = 2160, value = 1024, step = 1, interactive = True, label = "Height" )
85
  width = gr.Slider( minimum = 144, maximum = 2160, value = 1024, step = 1, interactive = True, label = "Width" )
86
  nis = gr.Slider( minimum = 0, maximum = 100, value = 50, step = 1, interactive = True, label = "Steps" )
@@ -90,7 +80,7 @@ with gr.Blocks() as demo:
90
  with gr.Column():
91
  output = gr.Image(label = "Output")
92
 
93
- run.click(generate, inputs = [access_key, prompt_text, model, negative_prompt_text, height, width, nis, gs, seed], outputs = [output], queue = False)
94
- reload.click(reload_models, inputs = [], outputs = [prompt_text], queue = False)
95
 
96
  demo.launch(show_api = True)
 
5
 
6
  API_TOKEN = os.environ.get("API_TOKEN")
7
 
 
 
8
  DEFAULT_NEGATIVE_INPUT = "nsfw, nude, nudity, naked, pantsless, boob, boobs, extra fingers, fewer fingers, (worst quality:1.4), (low quality:1.4), (monochrome:1.1), (bad_prompt_version2:0.8), text, jpeg, watermark, artist sign, blurry, out of frame, multiple breasts, (mutated hands and fingers:1.5 ), (long body :1.3), (mutation, poorly drawn :1.2) , black-white, bad anatomy, liquid body, liquid tongue, disfigured, malformed, mutated, anatomical nonsense, text font ui, error, malformed hands, long neck, blurred, lowers, lowres, bad anatomy, bad proportions, bad shadow, uncoordinated body, unnatural body, fused breasts, bad breasts, huge breasts, poorly drawn breasts, extra breasts, liquid breasts, heavy breasts, missing breasts, huge haunch, huge thighs, huge calf, bad hands, fused hand, missing hand, disappearing arms, disappearing thigh, disappearing calf, disappearing legs, fused ears, bad ears, poorly drawn ears, extra ears, liquid ears, heavy ears, missing ears, fused animal ears, bad animal ears, poorly drawn animal ears, extra animal ears, liquid animal ears, heavy animal ears, missing animal ears, text, ui, error, missing fingers, fused feet, bad feet, poorly drawn feet, extra feet, melting feet, fused feet, liquid feet, missing toes, bad toes, fused toes, poorly drawn toes, extra toes, fused eyes, missing eyes, liquid eyes, blurry eyes, fused lips, missing mouth, liquid mouth, expressionless, no expression, null face, liquid face, swirly face, no error correction,"
9
 
10
  API_ENDPOINTS = {
 
26
  CHOICES.append(model_name)
27
  CLIENTS[model_name] = InferenceClient(model_endpoint, headers = { "Authorization": f"Bearer {API_TOKEN}" })
28
 
29
+ def generate(inputs, model, anti_inputs = DEFAULT_NEGATIVE_INPUT, ht = 512, wt = 512, nis = 50, gs = 7.5, seed = 42):
30
 
31
  print("MODEL CALLED: Input: " + inputs + ", Model: " + str(model))
32
 
 
 
 
 
33
  output = CLIENTS[model].text_to_image(
34
  inputs,
35
  negative_prompt = anti_inputs,
 
42
 
43
  return (output)
44
 
45
+ def cloud():
46
+ print("[CLOUD] | Reloading all existing models...")
 
 
47
  for model_name, model_client in CLIENTS.items():
48
  try:
49
  threading.Thread(target=CLIENTS[model_name].text_to_image, args=("Preload",), kwargs={
 
56
  }).start()
57
  except Exception as e:
58
  print(f"[PRELOAD ERROR] An error occurred: {e}")
59
+ print("[CLOUD] | Reload successful.")
60
+
 
61
  with gr.Blocks() as demo:
62
  with gr.Row(variant = "panel"):
63
  gr.Markdown("✨ A IDM space owned within Statical.")
 
69
  with gr.Column():
70
  prompt_text = gr.Textbox(label = "Your Prompt", lines = 4)
71
  negative_prompt_text = gr.Textbox(label = "Your Negative Prompt", lines = 4, value = DEFAULT_NEGATIVE_INPUT)
 
72
  run = gr.Button("Generate Image")
73
+ maintain = gr.Button("☁☁️")
74
  height = gr.Slider( minimum = 144, maximum = 2160, value = 1024, step = 1, interactive = True, label = "Height" )
75
  width = gr.Slider( minimum = 144, maximum = 2160, value = 1024, step = 1, interactive = True, label = "Width" )
76
  nis = gr.Slider( minimum = 0, maximum = 100, value = 50, step = 1, interactive = True, label = "Steps" )
 
80
  with gr.Column():
81
  output = gr.Image(label = "Output")
82
 
83
+ run.click(generate, inputs = [prompt_text, model, negative_prompt_text, height, width, nis, gs, seed], outputs = [output], queue = False)
84
+ maintain.click(cloud, inputs = [], outputs = [], queue = False)
85
 
86
  demo.launch(show_api = True)