IamVicky111 commited on
Commit
4b231ef
·
verified ·
1 Parent(s): d029c31

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +122 -0
app.py ADDED
@@ -0,0 +1,122 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+
2
+ import gradio as gr
3
+ from gradio.themes.base import Base
4
+ from typing import Iterable
5
+ import random
6
+ from gradio.themes.utils import colors, fonts, sizes
7
+ import requests
8
+ import io
9
+ from PIL import Image
10
+ import os
11
+
12
+
13
+ API_URL = os.environ.get("MODEL_API_URL")
14
+
15
+
16
+ def query(payload):
17
+ auth_hf_api_token = os.environ.get("AUTH_HF_API_TOKEN")
18
+ authorization = "Bearer " + auth_hf_api_token
19
+ headers = {"Authorization": authorization}
20
+ response = requests.post(API_URL, headers=headers, json=payload)
21
+ return response.content
22
+
23
+
24
+ def genImage(prompt, negative_prompt, steps, cfg_scale, width, height, seed):
25
+ image_bytes = query(
26
+ {
27
+ "inputs": prompt,
28
+ "negative_prompt": negative_prompt,
29
+ "steps": steps,
30
+ "cfg_scale": cfg_scale,
31
+ "sampler": "DPM++ 2M Karras",
32
+ "width": width,
33
+ "height": height,
34
+ "seed": seed
35
+ }
36
+ )
37
+ image = Image.open(io.BytesIO(image_bytes))
38
+ return image
39
+
40
+
41
+ class Seafoam(Base):
42
+ def __init__(
43
+ self,
44
+ *,
45
+ primary_hue: colors.Color | str = colors.blue,
46
+ secondary_hue: colors.Color | str = colors.blue,
47
+ neutral_hue: colors.Color | str = colors.gray,
48
+ spacing_size: sizes.Size | str = sizes.spacing_md,
49
+ radius_size: sizes.Size | str = sizes.radius_md,
50
+ text_size: sizes.Size | str = sizes.text_md,
51
+ font: fonts.Font
52
+ | str
53
+ | Iterable[fonts.Font | str] = (
54
+ fonts.GoogleFont("Quicksand"),
55
+ "ui-sans-serif",
56
+ "sans-serif",
57
+ ),
58
+ font_mono: fonts.Font
59
+ | str
60
+ | Iterable[fonts.Font | str] = (
61
+ fonts.GoogleFont("IBM Plex Mono"),
62
+ "ui-monospace",
63
+ "monospace",
64
+ ),
65
+ ):
66
+ super().__init__(
67
+ primary_hue=primary_hue,
68
+ secondary_hue=secondary_hue,
69
+ neutral_hue=neutral_hue,
70
+ spacing_size=spacing_size,
71
+ radius_size=radius_size,
72
+ text_size=text_size,
73
+ font=font,
74
+ font_mono=font_mono,
75
+ )
76
+
77
+ theme = Seafoam(radius_size=gr.themes.sizes.radius_sm).set(body_background_fill="white")
78
+
79
+
80
+ with gr.Blocks(theme=theme) as demo:
81
+ gr.HTML(
82
+ """
83
+ <div style="text-align: center; margin: 0 auto;">
84
+ <div style="display: inline-flex; align-items: center;gap: 0.8rem;font-size: 1.75rem;">
85
+ <h1 style="font-weight: 900; margin-bottom: 7px;margin-top:5px">
86
+ AI Cartoon Generator
87
+ </h1>
88
+ </div>
89
+ <p>AI Character Generator creator by <a href="https://aicartoongenerator.net/" title="AI Cartoon Generator">https://aicartoongenerator.net/</a><p>
90
+ </div>
91
+ """
92
+ )
93
+ with gr.Row():
94
+ with gr.Column():
95
+ prompt = gr.Textbox(label="Prompt", placeholder="a cute cat, 8k",value="a cute cat, 8k", show_label=True, lines=5)
96
+ with gr.Row():
97
+ with gr.Accordion("Additionals inputs", open=False):
98
+ with gr.Column(scale=1):
99
+ negative_prompt = gr.Textbox(label="Negative Prompt", value="text, blurry", placeholder="What you don't want to see in the image", show_label=True, lines=1)
100
+ with gr.Column(scale=1):
101
+ steps = gr.Slider(label="Sampling Steps", minimum=1, maximum=30, value=25, step=1)
102
+ cfg_scale = gr.Slider(label="CFG Scale", minimum=1, maximum=20, value=7, step=1)
103
+ seed = gr.Number(label="Seed", value=-1)
104
+ with gr.Column(scale=1):
105
+ width = gr.Slider(label="↔️ Width", minimum=1024, maximum=1024, value=1024, step=8)
106
+ height = gr.Slider(label="↕️ Height", minimum=1024, maximum=1024, value=1024, step=8)
107
+ text_button = gr.Button("Generate", variant='primary')
108
+ with gr.Column():
109
+ image_output = gr.Image(type="pil", label="Output Image",height="auto",show_share_button=False)
110
+
111
+ text_button.click(genImage, inputs=[prompt, negative_prompt, steps, cfg_scale, width, height, seed], concurrency_limit=100,outputs=image_output)
112
+ with gr.Row():
113
+ gr.Examples(
114
+ examples=[
115
+ "It’s spring, a super cute little girl IP sitting on a huge flower as if dreaming, sunny day, chibi, 3D,natural lighting, full body portralt, 8k best quality, super detail, super detail, Ultra HD",
116
+ "A high-detail Pixar-style, especially Wreck-It Ralph style woman cartoon character with long brown hair and black eyes with big smile in a peaceful and happy scene, set in an environment with natural and clear weather, enhanced with bright sunshine.",
117
+ "A high-detail Pixar-style, especially Wreck-It Ralph style woman cartoon character with long brown hair and black eyes with big smile In a joyful Christmas scene, set in a snowy environment during the night, where the twinkling lights create an atmosphere full of hope and festive cheer."
118
+ ],
119
+ inputs=prompt
120
+
121
+ )
122
+