DamarJati commited on
Commit
6f9d065
1 Parent(s): 278956c

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +17 -5
app.py CHANGED
@@ -5,11 +5,16 @@ import random
5
  import os
6
  from PIL import Image
7
 
8
- API_URL = "https://api-inference.huggingface.co/models/cagliostrolab/animagine-xl-3.1"
 
 
 
 
9
  API_TOKEN = os.getenv("HF_READ_TOKEN") # it is free
10
  headers = {"Authorization": f"Bearer {API_TOKEN}"}
11
 
12
- def query(prompt, is_negative=False, steps=1, cfg_scale=6, seed=None):
 
13
  payload = {
14
  "inputs": prompt,
15
  "is_negative": is_negative,
@@ -21,6 +26,7 @@ def query(prompt, is_negative=False, steps=1, cfg_scale=6, seed=None):
21
  image_bytes = requests.post(API_URL, headers=headers, json=payload).content
22
  image = Image.open(io.BytesIO(image_bytes))
23
  return image
 
24
  css = """
25
  body {
26
  background-color: #fafafa !important;
@@ -52,7 +58,7 @@ css = """
52
 
53
  """
54
 
55
- with gr.Blocks(css=css, theme="gstaff/sketch") as Animagine:
56
  gr.HTML(
57
  """
58
  <div style="text-align: center; margin: 0 auto;">
@@ -65,10 +71,16 @@ with gr.Blocks(css=css, theme="gstaff/sketch") as Animagine:
65
  """
66
  )
67
  with gr.Row():
 
 
 
 
 
 
68
  with gr.Column(elem_id="prompt-container"):
69
  text_prompt = gr.Textbox(label="Prompt", value="1girl, c.c., code geass, white shirt, long sleeves, turtleneck, sitting, looking at viewer, eating, pizza, plate, fork, knife, table, chair, table, restaurant, cinematic angle, cinematic lighting, masterpiece, best quality", placeholder="a cute cat", lines=1, elem_id="prompt-text-input")
70
  negative_prompt = gr.Textbox(label="Negative Prompt", value="nsfw, lowres, bad anatomy, bad hands, text, error, missing fingers, extra digit, fewer digits, cropped, worst quality, low quality, normal quality, jpeg artifacts, signature, watermark, username, blurry, artist name, ", lines=1, elem_id="negative-prompt-text-input")
71
  text_button = gr.Button("Generate", variant='primary', elem_id="gen-button")
72
  image_output = gr.Image(type="pil", label="Output Image", elem_id="gallery")
73
- text_button.click(query, inputs=[text_prompt, negative_prompt], outputs=image_output)
74
- Animagine.launch(show_api=False)
 
5
  import os
6
  from PIL import Image
7
 
8
+ API_URLS = {
9
+ "Animagine XL 3.1": "https://api-inference.huggingface.co/models/cagliostrolab/animagine-xl-3.1",
10
+ "Animagine XL 3.0": "https://api-inference.huggingface.co/models/cagliostrolab/animagine-xl-3.0"
11
+ }
12
+ DEFAULT_MODEL = "Animagine XL 3.1"
13
  API_TOKEN = os.getenv("HF_READ_TOKEN") # it is free
14
  headers = {"Authorization": f"Bearer {API_TOKEN}"}
15
 
16
+ def query(prompt, is_negative=False, steps=1, cfg_scale=6, seed=None, model_version=DEFAULT_MODEL):
17
+ API_URL = API_URLS[model_version]
18
  payload = {
19
  "inputs": prompt,
20
  "is_negative": is_negative,
 
26
  image_bytes = requests.post(API_URL, headers=headers, json=payload).content
27
  image = Image.open(io.BytesIO(image_bytes))
28
  return image
29
+
30
  css = """
31
  body {
32
  background-color: #fafafa !important;
 
58
 
59
  """
60
 
61
+ with gr.Blocks(css=css) as Animagine:
62
  gr.HTML(
63
  """
64
  <div style="text-align: center; margin: 0 auto;">
 
71
  """
72
  )
73
  with gr.Row():
74
+ gr.Dropdown(
75
+ label="Model Version",
76
+ choices=list(API_URLS.keys()),
77
+ default=DEFAULT_MODEL,
78
+ elem_id="model-dropdown"
79
+ )
80
  with gr.Column(elem_id="prompt-container"):
81
  text_prompt = gr.Textbox(label="Prompt", value="1girl, c.c., code geass, white shirt, long sleeves, turtleneck, sitting, looking at viewer, eating, pizza, plate, fork, knife, table, chair, table, restaurant, cinematic angle, cinematic lighting, masterpiece, best quality", placeholder="a cute cat", lines=1, elem_id="prompt-text-input")
82
  negative_prompt = gr.Textbox(label="Negative Prompt", value="nsfw, lowres, bad anatomy, bad hands, text, error, missing fingers, extra digit, fewer digits, cropped, worst quality, low quality, normal quality, jpeg artifacts, signature, watermark, username, blurry, artist name, ", lines=1, elem_id="negative-prompt-text-input")
83
  text_button = gr.Button("Generate", variant='primary', elem_id="gen-button")
84
  image_output = gr.Image(type="pil", label="Output Image", elem_id="gallery")
85
+ text_button.click(query, inputs=[text_prompt, negative_prompt, "model-dropdown"], outputs=image_output)
86
+ Animagine.launch(show_api=False)